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

Correct way to write two nested solvers

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 5, 2022, 16:27
Default Correct way to write two nested solvers
  #1
Senior Member
 
Join Date: Jul 2013
Posts: 124
Rep Power: 12
wildfire230 is on a distinguished road
Hi All,


I am basically trying to write a nested solver that alternately solves the steady-state flow profile using simpleFoam, and then updates a scalar field using scalarTransportFoam. This must be done iteratively, because the viscosity of the fluid depends on the scalar quantity, so after updating the scalar quantity I need to re-solve the (steady) fluid velocity. I was able to make this work by taking out the guts of simpleFoam and placing them in an inner loop in my scalarTransportFoam modified solver, but I couldn't figure out the proper way to access the residuals for terminating the solver. Finally I figured out I could do it like this:


// SOLVE THE FLOW FIELD
int myCounter = 0;
while (true)
{
// --- Pressure-velocity SIMPLE corrector
#include "UEqn.H"
p.storePrevIter();
#include "pEqn.H"
laminarTransport.correct();
turbulence->correct();

if (eqnResidualU[0] < UResidual.value() && eqnResidualU[1] < UResidual.value() && eqnResidualU[2] < UResidual.value() && eqnResidualP < pResidual.value())
{
break;
}

myCounter = myCounter + 1;
Info<< "counter = " << myCounter << endl;
}

// Update the concentration numSteps times
for (int n = 0; n < numSteps.value(); ++n) {
runTime++;
Info<< "Time = " << runTime.timeName() << nl << endl;

#include "CEqn.H"

Info << "max(C) = " << max(C) << endl;
Info << "min(C) = " << min(C) << endl;

runTime.write();

Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s"
<< " ClockTime = " << runTime.elapsedClockTime() << " s"
<< nl << endl;
}
}


Where the residuals are calculated here in the UEqn file:


if (simple.momentumPredictor())
{
eqnResidualU = solve(UEqn == -fvc::grad(p)).initialResidual();
fvOptions.correct(U);
}



and similar for the pressure residual. I seriously doubt this is the best way to do this, but I don't really know. The thing that really bothers me is that this fluid solver part of the code is 5x slower than just running simpleFoam, although it is essentially the same UEqn and same pEqn, and it is running the same number of total iterations. Something else is slowing it down significantly, but I don't know what.


The other weird thing to me is that I had to add the middle line here:


#include "UEqn.H"
p.storePrevIter();
#include "pEqn.H"


which is not present in simpleFoam, and I don't really understand why. Does anyone have any advice for understanding these issues?


Thanks
wildfire230 is offline   Reply With Quote

Reply

Tags
scalartransportfoam, simplefoam, speed


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
Should I focus on explicit or implicit solvers for transient simulations? aerosayan Main CFD Forum 1 April 11, 2021 07:31
MULES in Eulerian solvers MMNCH OpenFOAM Programming & Development 2 July 7, 2020 13:58
Correct way to write intermediate values of field calculations joeeweaver OpenFOAM Programming & Development 2 February 5, 2020 12:30
OpenFOAM solvers for two-phase boiling flows Coris CFD Freelancers 1 May 22, 2019 03:54
Types of solvers CFD-Junior Main CFD Forum 6 April 14, 2019 17:25


All times are GMT -4. The time now is 07:50.