CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Running, Solving & CFD

How to code Strang splitting ?

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree1Likes
  • 1 Post By celestial

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 11, 2020, 14:41
Default How to code Strang splitting ?
  #1
Member
 
Join Date: Mar 2019
Posts: 86
Rep Power: 7
celestial is on a distinguished road
Best wishes to all in this new year


I couldn't find how to do this in openFoam and all of its variants.

Strang splitting means

df/dt = T + S

becomes

df/dt = S
df/dt = T
df/dt = S

T stands for convective and diffusive terms whereas S stands for a source term. Also the original dt for the derivative numerical scheme is halved for both df/dt = S in the above



I think what should be done for two fields f1 and f2 is as follows. (S1 and S2 may depend non linearly on both f1 and f2)


....


delT = runTime.deltaT().value();


runTime.deltaT().value() = delT/2.;


solve
(
fvm::ddt(f1) == T1
) ;


solve
(
fvm::ddt(f2) == T2
) ;


runTime.deltaT().value() = delT;


solve
(
fvm::ddt(f1) == S1
) ;


solve
(
fvm::ddt(f2) == S2
) ;



runTime.deltaT().value() = delT/2;


solve
(
fvm::ddt(f1) == T1
) ;


solve
(
fvm::ddt(f2) == T2
) ;


runTime.deltaT().value() = delT;

....

Is anything wrong with my approach ? Any reply welcome
celestial is offline   Reply With Quote

Old   January 13, 2020, 15:28
Default
  #2
Member
 
Join Date: Mar 2019
Posts: 86
Rep Power: 7
celestial is on a distinguished road
Well, Im going to give you a first clue


you cannot set it this way

doubleScalar delT = runTime.deltaT().value();

runTime.deltaT().value() = delt/2;

I checked using Info that the original value isnt changed.

Instead, you have to write

runTime.setDeltaT
(
delT/2.
);


I will keep you posted after I study more about these time objects
superkelle likes this.
celestial is offline   Reply With Quote

Old   March 26, 2020, 13:48
Default
  #3
Member
 
alexander thierfelder
Join Date: Dec 2019
Posts: 71
Rep Power: 7
superkelle is on a distinguished road
Hey I found out that it should be possible with subCycle. But I don't know how to implement that the right way

"Strang splitting is an
alternative to this method, in which the sweeps are performed in a symmetric order. An odd
number of sweeps are required for this splitting, i.e. M = 3, 5, 7.., and the reaction terms are
always integrated explicitly at the middle iteration (M + 1)/2. The homogeneous terms are
integrated implicitly. The example is given for M = 3: The sub-cycling is implemented using the built-in subCycle utility. This functionality alters
the current time index of the corresponding volume field, assuring that sub-iterations are
stored as t+i/N and the final iteration corresponds to the current time step t+1, instead of
t+N which would be the case of the time indices are not corrected."

Source:
https://repository.tudelft.nl/island...m/OBJ/download
superkelle is offline   Reply With Quote

Old   May 24, 2020, 09:46
Default
  #4
Member
 
alexander thierfelder
Join Date: Dec 2019
Posts: 71
Rep Power: 7
superkelle is on a distinguished road
For the simplest case n =3 ,I think it should work somehow like this:
Code:
label nSubCycles = 3;
dimensionedScalar totalDeltaT = runTime.deltaT();
                
 for ( subCycle<volScalarField> YSubCycle(Y, nSubCycles); !(YSubCycle).end(); ++YSubCycle)
{

     if ( YsubCycle.index() != 2 )
     { 
        runTime.setDeltaT(totalDeltaT/2);
        #include "YEqnHom.H"
        YEqnHom.solve();
     }
     else 
     {
         runTime.setDeltaT(totalDeltaT);
         #include "YEqnHet.H"
         YEqnHet.solve();
     }
}
superkelle is offline   Reply With Quote

Old   June 6, 2020, 08:25
Default
  #5
Member
 
alexander thierfelder
Join Date: Dec 2019
Posts: 71
Rep Power: 7
superkelle is on a distinguished road
And for any number of sub cycles (odd).

Code:
label nSubCycles = 5; // odd

dimensionedScalar totalDeltaT = runTime.deltaT();
                
 for ( subCycle<volScalarField> YSubCycle(Y, nSubCycles); !(YSubCycle).end(); ++YSubCycle)
{

     if ( YsubCycle.index() != (floor(nSubcycle/2)+1) )
     { 
        runTime.setDeltaT(totalDeltaT/(nSubcycle-1));
        #include "YEqnHom.H"
        YEqnHom.solve();
     }
     else 
     {
         runTime.setDeltaT(totalDeltaT);
         #include "YEqnHet.H"
         YEqnHet.solve();
     }
}

Last edited by superkelle; June 6, 2020 at 16:23.
superkelle is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
CFD code layout plasmaCode Main CFD Forum 3 December 12, 2015 23:10
The FOAM Documentation Project - SHUT-DOWN holger_marschall OpenFOAM 242 March 7, 2013 13:30
How to make code run in parallel? cwang5 OpenFOAM Programming & Development 1 May 30, 2011 05:47
Open Source Vs Commercial Software MechE OpenFOAM 28 May 16, 2011 12:02
Small 3-D code Zdravko Stojanovic Main CFD Forum 2 July 19, 2010 11:11


All times are GMT -4. The time now is 17:03.