Metafor

ULiege - Aerospace & Mechanical Engineering

User Tools

Site Tools


poliflows:miscellaneous

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
poliflows:miscellaneous [2016/03/30 15:23] – external edit 127.0.0.1poliflows:miscellaneous [2019/05/07 13:24] (current) – removed boman
Line 1: Line 1:
-In this section the use of some more advanced, not indispensable, yet very useful concepts is discussed. 
- 
-====== Using functions ====== 
- 
-The first concept that should be discussed is the use of functions in the POL(I)FLOWS [[poliflows:inputfile|input file]].   
- 
-The main purpose of functions for the moment is to give the user the possibility to define his/her own loading cases (see [[poliflows:miscellaneous#Creating your own loading case|Creating your own loading case]] section). 
- 
-**PieceWiseLinearFunction** 
- 
-A first possibility is to define a function using the POL(I)FLOWS built-in class ''PieceWiseLinearFunction''.   
-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 ''PieceWiseLinearFunction'' can be defined as follows: 
- 
-  fct = w.PieceWiseLinearFunction() 
- 
-Then, interpolation points can be either added one by one by the user: 
- 
-  fct.setData(abs1, ord1) 
-  fct.setData(abs2, ord2) 
-  ... 
- 
-or imported from an existing file: 
- 
-  fct.fillData('D:/path/to/the/data/file.txt') 
- 
-**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), Python functions have the great advantage that (almost) any mathematical function, from very simple to very complex, can be defined in a very simple way!  
- 
-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 ''x'' value as the argument: 
- 
-  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. 
-     return val 
- 
-====== Creating your own loading case ====== 
- 
-If you have read the section on how to [[poliflows:miscellaneous#Using functions|use functions]], you have already understood that you can basically use the loadings that already exist in order to create the loading case you need, just by defining the right evolution functions and possibly combining different loadings. 
-   
-Nevertheless, you can do even more, if you need to: you can create your whole brand new loading case! 
- 
-In order to create your own loading case, you can customize some C++ classes, by rederiving them in Python.   This is tipically done in the ''pfemtools.py'' file.   
- 
-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, whose evolution in time is defined through a ''PieceWiseLinearFunction''.   
- 
-In the ''pfemtools.py'' file we define the class: 
- 
-  class PieceWiseTransLoad(w.TranslationLoading): 
-      def __init__(self, msh, num_or_name , p1, p2, fct):                     # define the constructor: the user-defined function fct is passed as argument 
-          w.TranslationLoading.__init__(self, msh, num_or_name , p1, p2, 0.)  # call the base class constructor 
-          self.fun = fct                                                      # reference to the user-defined piece wise linear function fct 
-      def getAmplitude(self, t):                                              # derivation of the getAmplitude() function 
-          return self.fun.evaluate(t)                                         # getAmplitude() now returns the evaluation of the piece wise linear funtion at time t 
- 
-In the input file, we create the loading by calling the ''PieceWiseTransLoad'': 
- 
-  f = w.PieceWiseLinearFunction() # definition of a piece wise linear function 
-  f.setData(abs1, ord1) 
-  f.setData(abs2, ord2) 
-  ... 
-   
-  loadingset = w.LoadingSet() 
-  loadingset.add(1,wt.PieceWiseTransLoad(msh,"physicalEntity",p1,p2,f)) # call to the custom loading 
-   
-...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 ''PieceWiseTransLoad'' does is deriving the base class ''TranslationLoading'' and modifying the definition of the ''getAmplitude()'' function in order to make it return a different value at each time step; value which is obtained from the evaluation, at time ''t'', of the user-defined function ''f''. 
- 
-Now, imagine that you wanted, for example, dispose of a "cosine translation loading" and not of a "generic function loading", to avoid the need of defining a function every time: you could very well do it! All you have to do is derive, in the same fashion, a class ''CosTransLoad'' and put what you need inside it (this is already done for a "sinus", if you look in the ''pfemtools.py'' file). 
- 
-**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 "loadings" class, which is called ''Loading'' and define a completely different loading, by creating, for example, a ''RandomWalkMovement'' or ''imposedForce'' class, or whatever...  
- 
-Nonetheless, be aware that in this case you have to define the entire behavior of these classes! So you have to know what is contained in the source code and be sure of what you are doing! 
- 
-====== Launch a battery of tests ====== 
- 
-A battery of tests can be launched using the ''battery.py'' tool in the ''pfem/exe/'' directory. 
- 
-If you tape ''python battery.py'', a guide of the tool will be displayed: 
- 
-  usage: [run|rerun|verif|clean] files 
-   
-  examples: 
-     run: start/continue the battery 
-     rerun: restart the battery (clean before run) 
-     verif: create the summary file gathering the results 
-     clean: clean all results 
-      
-For example, to run the battery on the ''tests'' directory you should use: 
- 
-  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 ''diff'' tool (coming from svn, git, etc...). \\ 
-For ''Git'' it would be something like: 
- 
-  git difftool pfem/verif/results-Windows.txt 
-   
  
poliflows/miscellaneous.1459344184.txt.gz · Last modified: by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki