poliflows:miscellaneous
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| poliflows:miscellaneous [2015/09/14 14:42] – [Launch a battery of tests] cerquaglia | poliflows:miscellaneous [2019/05/07 13:24] (current) – removed boman | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | In this section the use of some more advanced, not indispensable, | ||
| - | |||
| - | ====== Using functions ====== | ||
| - | |||
| - | The first concept that should be discussed is the use of functions in the POL(I)FLOWS [[poliflows: | ||
| - | |||
| - | The main purpose of functions for the moment is to give the user the possibility to define his/her own loading cases (see [[poliflows: | ||
| - | |||
| - | **PieceWiseLinearFunction** | ||
| - | |||
| - | A first possibility is to define a function using the POL(I)FLOWS built-in class '' | ||
| - | As the name suggests this represents a piece-wise linear function: in order to define it then, all that is needed are the pairs of abscisses and ordinates representing the interpolation points. | ||
| - | |||
| - | A '' | ||
| - | |||
| - | fct = w.PieceWiseLinearFunction() | ||
| - | |||
| - | Then, interpolation points can be either added one by one by the user: | ||
| - | |||
| - | fct.setData(abs1, | ||
| - | fct.setData(abs2, | ||
| - | ... | ||
| - | |||
| - | or imported from an existing file: | ||
| - | |||
| - | fct.fillData(' | ||
| - | |||
| - | **Python function** | ||
| - | |||
| - | Otherwise, Python functions can be used as well.\\ | ||
| - | If you do not need to define a function based on some data file (e.g. experimental measurements), | ||
| - | |||
| - | In general, a Python function declaration reads as follows: | ||
| - | |||
| - | def fct(x): | ||
| - | val = ... #function definition | ||
| - | return val | ||
| - | | ||
| - | and the function evaluation is performed by simply calling the function and passing the abscisse '' | ||
| - | |||
| - | y = fct(x) | ||
| - | |||
| - | Here is, for example, the definition of a piece-wise linear function in Python: | ||
| - | |||
| - | def f(x): | ||
| - | val = 0. | ||
| - | if(x <= 0.1): | ||
| - | val = 1.0*x | ||
| - | elif (0.1 < x < 1.0): | ||
| - | val = 0.1 | ||
| - | else: | ||
| - | val = 0. | ||
| - | return val | ||
| - | |||
| - | ... and the one of a much more complicated function, for basically the same effort: | ||
| - | |||
| - | import math | ||
| - | | ||
| - | a = 0.005 | ||
| - | f1 = 0.5 | ||
| - | f2 = 0.3 | ||
| - | | ||
| - | def f(x): | ||
| - | val = 0. | ||
| - | if(x < 3.0): | ||
| - | val = a*(2*math.pi*f1*math.cos(2*math.pi*f1*x) - 2*math.pi*f2*math.cos(2*math.pi*f2*x)) | ||
| - | else: | ||
| - | val = 0. | ||
| - | | ||
| - | |||
| - | ====== Creating your own loading case ====== | ||
| - | |||
| - | If you have read the section on how to [[poliflows: | ||
| - | | ||
| - | Nevertheless, | ||
| - | |||
| - | In order to create your own loading case, you can customize some C++ classes, by rederiving them in Python. | ||
| - | |||
| - | To explain how it works let us consider the example of a custom loading that already exists. This is the case of a time-depend imposed translation, | ||
| - | |||
| - | In the '' | ||
| - | |||
| - | class PieceWiseTransLoad(w.TranslationLoading): | ||
| - | def __init__(self, | ||
| - | w.TranslationLoading.__init__(self, | ||
| - | self.fun = fct # reference to the user-defined piece wise linear function fct | ||
| - | def getAmplitude(self, | ||
| - | return self.fun.evaluate(t) | ||
| - | |||
| - | In the input file, we create the loading by calling the '' | ||
| - | |||
| - | f = w.PieceWiseLinearFunction() # definition of a piece wise linear function | ||
| - | f.setData(abs1, | ||
| - | f.setData(abs2, | ||
| - | ... | ||
| - | | ||
| - | loadingset = w.LoadingSet() | ||
| - | loadingset.add(1, | ||
| - | | ||
| - | ...and, lo and behold, that works straight away! No need to do anything else! | ||
| - | |||
| - | **What is the hidden machinery behind it? | ||
| - | |||
| - | Well, all the loadings C++ base classes possess a `getAmplitude()` function which is used to know the value of the loading at each time step.\\ | ||
| - | For the C++ base class, `getAmplitude()` simply returns a constant value, defined by the user at the beginning of the simulation. | ||
| - | |||
| - | What '' | ||
| - | |||
| - | Now, imagine that you wanted, for example, dispose of a " | ||
| - | |||
| - | **Some more advanced stuff...** | ||
| - | |||
| - | That is all, if you want to impose translations or rotations, which is actually all you need. | ||
| - | |||
| - | But, let's say you want to go even further and impose a completely different movement, which is not a translation nor a rotation, or, even, impose a force, instead of a displacement. | ||
| - | You could, then, derive the most pure " | ||
| - | |||
| - | Nonetheless, | ||
| - | |||
| - | ====== Launch a battery of tests ====== | ||
| - | |||
| - | A battery of tests can be launched using the '' | ||
| - | |||
| - | If you tape '' | ||
| - | |||
| - | usage: [run|rerun|verif|clean] files | ||
| - | | ||
| - | examples: | ||
| - | run: start/ | ||
| - | | ||
| - | | ||
| - | | ||
| - | |||
| - | For example, to run the battery on the '' | ||
| - | |||
| - | python battery.py run ..\tests | ||
| - | |||
| - | Once the battery has been run, one can check the results using | ||
| - | |||
| - | python battery.py verif ..\tests | ||
| - | | ||
| - | In order to verify if the results are good, the easiest way is to use a '' | ||
| - | For '' | ||
| - | |||
| - | git difftool pfem/ | ||
| - | | ||
poliflows/miscellaneous.1442234535.txt.gz · Last modified: (external edit)
