CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > General Forums > Main CFD Forum

Dual Time Stepping

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By t.teschner

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 2, 2017, 12:05
Default Dual Time Stepping
  #1
Senior Member
 
Tom-Robin Teschner
Join Date: Dec 2011
Location: Cranfield, UK
Posts: 211
Rep Power: 17
t.teschner is on a distinguished road
I have some issues implementing the dual time stepping procedure and was hoping some experienced eyes can help me out. Suppose I want to solve the advection equation using a dual time stepping procedure, then I have

\frac{\partial u}{\partial \tau}+\frac{\partial u}{\partial t}+a\frac{\partial u}{\partial x},

where \tau and t are the pseudo and real time, respectively. Using first order (for simplicity) for all the derivatives, I get

\frac{u_i^{n+1,m+1}-u_i^{n+1,m}}{\Delta \tau} + \frac{u_i^{n+1,m}-u_i^{n}}{\Delta t} + a\frac{u_i^n - u_{i-1}^n}{\Delta x} = 0.

I define the right-hand side (RHS) as

RHS=-\frac{u_i^{n+1,m}-u_i^{n}}{\Delta t} - a\frac{u_i^n - u_{i-1}^n}{\Delta x}

and then can rewrite the equation in explicit time integration form as

u_i^{n+1,m+1}=u_i^{n+1,m}+\Delta\tau RHS.

Once u_i^{n+1,m+1}-u_i^{n+1,m}<\epsilon, where \epsilon is some small (convergence number), the pseudo time derivative vanishes and i obtain the solution at the next time step. The pseudo code for my example follows below

Code:
t_r=0

while(t_r < t_{end})
   while(\epsilon<residual and iteration<iteration_{max})
   
      Do i=2 to n
         RHS=-\frac{u_i^{n+1,m}-u_i^{n}}{\Delta t} - a\frac{u_i^n - u_{i-1}^n}{\Delta x}
      End

      Do i=2 to n
         u_i^{n+1,m+1}=u_i^{n+1,m}+\Delta\tau RHS
      End

      calculate residual
      set iteration=iteration+1
      u^{n+1,m}=u^{n+1,m+1}

   End

   u^n=u^{n+1,m+1}
   t_r=t_r+\Delta t

End
As long as I have \Delta \tau=\Delta t the above code works fine, but as soon as I use different time steps, say 2\Delta \tau=\Delta t, then my solution is off (by a factor of 2, in terms of propagated distance). It is probably an easy fix, but at the moment I am not quite sure what I am doing wrong.

Last edited by t.teschner; August 3, 2017 at 15:13.
t.teschner is offline   Reply With Quote

Old   August 2, 2017, 17:41
Default
  #2
Senior Member
 
Filippo Maria Denaro
Join Date: Jul 2010
Posts: 6,897
Rep Power: 73
FMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura about
I never worked with such a procedure, thus I have no experience about the advantage in doing that. However, I see that for dt=dtau you get the increment without
u^{n+1,m}

so I wonder what about the iteration over m...
FMDenaro is offline   Reply With Quote

Old   August 3, 2017, 05:40
Default
  #3
Senior Member
 
Tom-Robin Teschner
Join Date: Dec 2011
Location: Cranfield, UK
Posts: 211
Rep Power: 17
t.teschner is on a distinguished road
well, as far as i understand, the method was introduced to allow usage of fast time marching algorithms (implicit schemes, multigrid etc.) which need not to be accurate but give a steady state solution fast. the time accurate solution is recovered with the second timestep which can follow its on stability criterion.
well, so far the theory, but all method derived from the artificial compressibility method in incompressible flows (which i am working on) suffer from the inherent pseudo time marching so the only way, really, to get an unsteady simulation, is to use the dual time stepping procedure.
so i though i start with a simple advection equation but yeah, if \Delta \tau=\Delta t than u^{n+1,m} vanishes. I suspect the problem to be somewhere in the update of the variables, though.
t.teschner is offline   Reply With Quote

Old   August 3, 2017, 10:44
Default
  #4
Senior Member
 
sbaffini's Avatar
 
Paolo Lampitella
Join Date: Mar 2009
Location: Italy
Posts: 2,195
Blog Entries: 29
Rep Power: 39
sbaffini will become famous soon enoughsbaffini will become famous soon enough
Send a message via Skype™ to sbaffini
The DTS formulation refers to the fact that you have 2 time derivative terms, one of which is in pseudo-time, the other in actual time so, formally, by construction, it is used for unsteady computations. By extension, it is also possible for steady states, where the true time derivative term is assumed to be 0.

Now, what the problem is for such unsteady computations? That the explicit stability limit to advance them might require much lower time steps than accuracy would, possibly only because of few problematic cells.

The idea of the DTS is thus to introduce a pseudo-time derivative, discretized with a local time step (on a per cell basis) based on the local stability limit, and use such pseudo-time to advance explicilty the solution until it doesn't change anymore in pseudo-time, which means that the pseudo-time derivative has disappeared and the remaining terms (i.e., the original equation) are fully balanced.

Now, what should be clear is that, really, it only makes sense for implicit discretizations in time or implicit steady states. Otherwise, your physical time step, by construction, has to be, for each cell, equal to the lowest allowed pseudo-time step in the grid.

So, to start with, as your discretization is explicit, both in time and pseudo-time, both time steps have to respect the stability limits. For your simple case it means:

\frac{a \Delta t} {\Delta x} \le 1

\frac{a \Delta \tau} {\Delta x} \le 1

Do the both of them respect these constraints?

Second question, how do you determine convergence within pseudo-time? Are you sure you are not simply using all the allowed iterations without actually converging? (Also note that, typically, the condition used in the check is an AND, not an OR)
sbaffini is offline   Reply With Quote

Old   August 3, 2017, 15:37
Default
  #5
Senior Member
 
Tom-Robin Teschner
Join Date: Dec 2011
Location: Cranfield, UK
Posts: 211
Rep Power: 17
t.teschner is on a distinguished road
thanks for spotting that, in my code i have indeed a "and" statement, not or. and yes, i specify the timestep according to the stability criterion stated in your post. as i was saying before, when dealing with the artificial compressibility method, dual time stepping is the only way to achieve unsteady simulations, so we don't use it for the larger timestep reason as in compressible flow and hence an explicit method will work just fine for me.
i set my maximum iterations to 100 and found convergence for eps=1e-8 to be around 30 iterations, i played around with the maximum iteration number and eps but usually the solution converged in pseudo time before the maximum iteration count was achieved. the residual is calculated based on the L0 norm and i just take the maximum difference of u between m+1 and m (and normalise that difference so that the residual is 1 at the first iteration). if it helps, i put the matlab code below (i use k here instead of m to indicate the pseudo time level)

Code:
%% the program solves the advection equation with dual-time stepping
clc;
clear;
close all;

%% initial parameters

% problem specific parameters
a     = 1.0;   % wave speed
n     = 1001;  % number of elements in x
CFL_r = 0.8;   % CFL, real time
CFL_p = 0.4;   % CFL, pseudo time
t_end = 5.0;   % compute until

% convergence criterion in pseudo time
eps   = 1e-8;  % convergence parameter in pseudo time
imax  = 100;   % maximum iterations in pseudo time

% calculated parameters
dx    = 20/(n-1);   % spacing
dt_p  = CFL_p*dx/a; % delta t(au), pseudo time
dt_r  = CFL_r*dx/a; % delta t, real time

% solution arrays
un1k1 = zeros(n,1); % u^{n+1,k+1}
un1k  = zeros(n,1); % u^{n+1,k}
un    = zeros(n,1); % u^{n}
unm1  = zeros(n,1); % u^{n-1}
uana  = zeros(n,1); % u analytic
RHS   = zeros(n,1); % right-hand side vector

% space vector
x = linspace(-10,10,n); % x vector

% initialise solution
for i=1:n
    un1k1(i) = 0.5*exp(-x(i)^2);
    un1k(i)  = 0.5*exp(-x(i)^2);
    un(i)    = 0.5*exp(-x(i)^2);
    unm1(i)  = 0.5*exp(-x(i)^2);
end

% compute analytic solution for comparison
for i=1:n
    uana(i) = 0.5*exp(-(x(i)-t_end)^2);
end

%% time loop

% loop in real time (outer loop)
t_r = 0.0;
while(t_r<t_end)
    
    % copy values
    unm1 = un;
    un   = un1k;
   
    % loop in pseudo time (inner loop)
    res  = 1.0;
    iter = 1; 
    while(eps<res && iter<imax)
        
        % copy values
        un1k = un1k1;
        
        % loop over space
        for i=2:n            
            % assemble right-hand side
            temp = getRHS(un1k, un, unm1, dt_r, dx, a, i);
            RHS(i) = temp;            
        end
        
         % time integration in pseudo time
        for i=2:n            
            un1k1(i) = un1k(i)+dt_p*RHS(i);
        end
        
        % calculate residual
        res = abs(max(un1k1-un1k));
        
        if (iter == 1)
            if (res ~= 0.0)
                resnorm = res;
            else
                resnorm = 1.0;
            end
        end
        
        % normalise residuals
        res = res/resnorm;
        
        % print to screen
        if(mod(iter,100) == 0)
            fprintf('   iter: %d   residual: %12.5e\n', iter, res)
        end
        
        % increase iteration counter
        iter = iter + 1;
        
    end
    
    fprintf('time: %12.2e   iterations in pseudo time: %d\n',t_r,iter);
    t_r = t_r + dt_r;
end

%% plot solution
plot (x,un1k1,x,uana)
legend('numerical','analytical','location','northwest')
ylim([0 0.5])
and the function call

Code:
function [temp] = getRHS(un1k, un, unm1, dt_r, dx, a, i)
    
    temp = (-1.0)*(3*un1k(i)-4*un(i)+unm1(i))/dt_r - a*(un(i)-un(i-1))/dx;
    
end
with the code above you'll get the following output
Attached Images
File Type: png 01.png (4.2 KB, 18 views)
t.teschner is offline   Reply With Quote

Old   August 4, 2017, 01:57
Default
  #6
Senior Member
 
sbaffini's Avatar
 
Paolo Lampitella
Join Date: Mar 2009
Location: Italy
Posts: 2,195
Blog Entries: 29
Rep Power: 39
sbaffini will become famous soon enoughsbaffini will become famous soon enough
Send a message via Skype™ to sbaffini
I can'try your code now. But I suspect that the following 3 points are creating troubles:

1) res = abs(max(..., where it should be max(abs(...

2) you are not using the 1st order explicit euler in real time as claimed, but a 2nd order backward discretization. Still, you have it wrong, because you need to divide that by 2dt

3) as per point 2 above, your discretized physical unsteady term is actually defined at n+1, which means you would need to go implicit. I don't know if staying explicit here just means reverting to 1st order
sbaffini is offline   Reply With Quote

Old   August 4, 2017, 03:35
Default
  #7
Senior Member
 
sbaffini's Avatar
 
Paolo Lampitella
Join Date: Mar 2009
Location: Italy
Posts: 2,195
Blog Entries: 29
Rep Power: 39
sbaffini will become famous soon enoughsbaffini will become famous soon enough
Send a message via Skype™ to sbaffini
Did the check in 2. It seems to solve your problem. Check in 1 does not seem to be relevant for this case.
sbaffini is offline   Reply With Quote

Old   August 4, 2017, 03:37
Default
  #8
Senior Member
 
Tom-Robin Teschner
Join Date: Dec 2011
Location: Cranfield, UK
Posts: 211
Rep Power: 17
t.teschner is on a distinguished road
it was about point 2 ... thanks, problem is solved now (forgot to devide by 2dt). i just used first order in the opening post for simplicity but 2nd order in the code. and there does not seem to be a problem with having a double explicit scheme, as stated before, for artificial compressibility based methods its the only way to introduce real unsteady behaviour so both pseudo and real time can be explicit. in this case i just use the advection equation to simplify the problem. but thanks again for spotting the bug
sbaffini likes this.
t.teschner is offline   Reply With Quote

Reply

Tags
dual time stepping


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Elastic or Plastic Deformations in OpenFOAM NickolasPl OpenFOAM Pre-Processing 36 September 23, 2023 09:22
pimpleDyMFoam computation randomly stops babapeti OpenFOAM Running, Solving & CFD 5 January 24, 2018 06:28
same geometry,structured and unstructured mesh,different behaviour. sharonyue OpenFOAM Running, Solving & CFD 13 January 2, 2013 23:40
plot over time fferroni OpenFOAM Post-Processing 7 June 8, 2012 08:56
IcoFoam parallel woes msrinath80 OpenFOAM Running, Solving & CFD 9 July 22, 2007 03:58


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