CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Pre-Processing (https://www.cfd-online.com/Forums/openfoam-pre-processing/)
-   -   time step ramp (https://www.cfd-online.com/Forums/openfoam-pre-processing/151561-time-step-ramp.html)

Knigge46 April 13, 2015 06:50

time step ramp
 
Hey guys,

I'm trying to implement a ramped time step for a pimpleDYMfoam simulation, because I have a feeling that my solution is very time step sensitive.

I successfully built some if-statements in the controlDict file via runtime code-compilation (marking a coded part with #{ #} brackets), but that results in huge jumps in the force output even if the time step is only reduced by its half.

My desired way of doing this would be to keep using the runtime code compilation and not building some wild libraries...

My code part in the controlDict file looks like this:

Code:

      #{
          const Time& runTime = mesh().time();
          // scalar deltaT_start = 0.005;
          scalar deltaT_end = 0.001;
          scalar t_end = 1.0;
          // const_cast<Time&>(runTime).setDeltaT(deltaT_start+(deltaT_end-deltaT_start)*(pow(sin(min(runTime*pi/(2*t_end),pi/2))),2));
          const_cast<Time&>(runTime).setDeltaT(deltaT_end*(min(1, 0.1*runTime)));


        /*  if (runTime.value()>=2)
          {
              const_cast<Time&>(runTime).setDeltaT(deltaT_end);
          }
          if (runTime.value()>=3)
          {
              const_cast<Time&>(runTime).setDeltaT(deltaT_end/2);
          } */
      #};

I would like to use the commented squared sine function but also fail with the simple minimum function, because my variables seam to have different types.

Error output for a pisoFOAM trial case lokk like this:
Code:

/home.local/janwi/OpenFOAM/janwi-2.3.x/run/incompressible/pisoFoam/ras/cavity/system/controlDict.functions.changeTimeStep:59:79: note: candidates are:
/home.local/janwi/OpenFOAM/OpenFOAM-2.3.x/src/OpenFOAM/lnInclude/label.H:295:1: note: char Foam::min(char, char)
/home.local/janwi/OpenFOAM/OpenFOAM-2.3.x/src/OpenFOAM/lnInclude/label.H:295:1: note:  no known conversion for argument 2 from ‘Foam::dimensioned<double>’ to ‘char’
/home.local/janwi/OpenFOAM/OpenFOAM-2.3.x/src/OpenFOAM/lnInclude/label.H:296:1: note: short int Foam::min(short int, short int)

...and so on for various types...

I think the multiplication of 0.1*runTime is causing this. How can I best solve this issue?

Knigge46 April 13, 2015 08:53

solution:
 
okay, I found the solution myself: :cool:

I didn't set the variable for the time step in a proper way. It's working now, even if the results for the time step look a bit weird. Maybe someone has another (better) function to work as a kind of smoothed ramp.

I use a squared sine function:

Code:

delta_t_start + (delta_t_end - delta_t_start) * (sin^2(min(t*PI/(2* t_end) , PI/2) )
(Is there a way to use LaTeX formatting here on the forum? Then the formula would be presented a much better readable way! )

My working code is:

Code:

#{         
          const Time& runTime = mesh().time();
          double  t = runTime.value();
          scalar deltaT_start = 0.005;
          scalar deltaT_end = 0.001;
          scalar t_end = 1.0;
          double pi = M_PI;
          const_cast<Time&>(runTime).setDeltaT(deltaT_start+(deltaT_end-deltaT_start)*(pow(sin(min(t*pi/(2*t_end),pi/2)),2)));
#};

Feel free to test and feedback!


All times are GMT -4. The time now is 08:23.