|
[Sponsors] |
Possibility to perform two simple.loop inside the same code |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
August 23, 2018, 17:05 |
Possibility to perform two simple.loop inside the same code
|
#1 |
Member
Pablo Alarcón
Join Date: Mar 2018
Location: Liège
Posts: 59
Rep Power: 8 |
Good morning everybody
I would like to know if it is possible to perform two simple.loop inside the same code. In simplified words, what I want to do is something like this algorithm Code:
int main(...) { while(it <= maxIter) { ... while (simple.loop()) // first loop { ... #include "UEqn.H" #include "pEqn.H" ... } ... while (simple.loop()) // second loop { ... #include "UEqn2.H" #include "pEqn2.H" ... } ... } ... } My guess is that happens because simple.loop already have an stop signal recorded, so when I try to enter the second loop by means of while (simple.loop()) for the second loop, simply doesn't enter because the while(simple.loop()) condition was already fulfilled in the first loop. Is there any way to restart or put to zero the simple.loop in order to be able to enter to the second loop? Any insight, references to documentation or examples, or threads in the forum I may have missed are welcome. |
|
August 25, 2018, 14:08 |
|
#2 |
Senior Member
Peter Baskovich
Join Date: Jul 2014
Posts: 127
Rep Power: 11 |
I'm not too strong on c++ and I don't have the source in front of me but I'd say that you are right and the second loop doesn't run because the simple.loop() function is returning 0. I think you should reconsider what exactly you are doing because solving the simple loop again is equivalent to just lowering the solver tolerances so it loops more in the first place. You won't be working on the results of the first simple loop until the timestep (iteration for steady state) is advanced.
|
|
August 26, 2018, 16:46 |
|
#3 |
Senior Member
Join Date: Aug 2015
Posts: 494
Rep Power: 14 |
If you aren't using the simple controls (ie just running for a fixed number of iterations) a simple fix is to use your own for or while loops instead of simple.loop().
Caelan |
|
August 27, 2018, 04:13 |
|
#4 |
Member
Pablo Alarcón
Join Date: Mar 2018
Location: Liège
Posts: 59
Rep Power: 8 |
Actually and in principle, I need the simple controls (or an equivalent one) because is necessary to converge the flow equations in loop 1 before entering loop 2, which, unfortunately solve equations that are really similar. That is the reason why I'm using simple.loop in both.
|
|
August 27, 2018, 04:43 |
|
#5 |
Senior Member
Pablo Higuera
Join Date: Jan 2011
Location: Auckland
Posts: 627
Rep Power: 19 |
Hi Pablo,
how about re-defining the variable simple? You can try adding this line after the first loop has finished: Code:
simpleControl simple(mesh); Best, Pablo |
|
August 27, 2018, 10:05 |
|
#6 |
Senior Member
Join Date: Aug 2015
Posts: 494
Rep Power: 14 |
Another option would be to manually set the time with eg. runTime.setTime() -- you'd set it to zero. I think this would reset the simple controls.
Caelan |
|
August 28, 2018, 01:11 |
|
#7 |
Senior Member
Peter Baskovich
Join Date: Jul 2014
Posts: 127
Rep Power: 11 |
You could have a look at how the chtMultiRegionFoam handles multiple meshes and solver loops. It appears to setup custom loops for the different regions neatly.
|
|
August 28, 2018, 03:10 |
|
#8 |
Member
Pablo Alarcón
Join Date: Mar 2018
Location: Liège
Posts: 59
Rep Power: 8 |
Hello
Everybody, I'm taking notes of all of your comments and I will try them today. |
|
August 28, 2018, 03:18 |
|
#9 |
Member
Pablo Alarcón
Join Date: Mar 2018
Location: Liège
Posts: 59
Rep Power: 8 |
Hello Phicau
Can you please explain me the effect of Code:
simpleControl simple(mesh); |
|
August 28, 2018, 03:21 |
|
#10 | |
Member
Pablo Alarcón
Join Date: Mar 2018
Location: Liège
Posts: 59
Rep Power: 8 |
Quote:
Code:
runTime.setTime(it - 1,it -1); That is the reason why the counter is reset to the value of the global iteration number, because there should be X number of complete solutions of the flow (because loop 2 changes the topology of the design domain). |
||
August 28, 2018, 03:29 |
|
#11 |
Senior Member
Pablo Higuera
Join Date: Jan 2011
Location: Auckland
Posts: 627
Rep Power: 19 |
It will make it have the same value it had when the simulation started. Basically it is the line called by the solver to initialize the object simple.
|
|
August 28, 2018, 09:45 |
|
#12 | |
Member
Pablo Alarcón
Join Date: Mar 2018
Location: Liège
Posts: 59
Rep Power: 8 |
Hi Pablo
Unfortunately that option doesn't work Code:
error: redeclaration of ‘Foam::simpleControl simple’ simpleControl simple(mesh); Quote:
|
||
August 28, 2018, 21:26 |
|
#13 |
Senior Member
Pablo Higuera
Join Date: Jan 2011
Location: Auckland
Posts: 627
Rep Power: 19 |
I see... what about using another variable name?
Code:
simpleControl simpleSecond(mesh); while (simpleSecond.loop()) // second loop { ... |
|
August 28, 2018, 22:00 |
|
#14 | |
Senior Member
Join Date: Aug 2015
Posts: 494
Rep Power: 14 |
Quote:
Caelan |
||
August 30, 2018, 05:14 |
|
#15 |
Member
Pablo Alarcón
Join Date: Mar 2018
Location: Liège
Posts: 59
Rep Power: 8 |
||
August 30, 2018, 05:15 |
|
#16 |
Member
Pablo Alarcón
Join Date: Mar 2018
Location: Liège
Posts: 59
Rep Power: 8 |
I can set the time to zero (or any number) but that doesn't change the convergence criteria.
If the first loop is already converged, then there is no way on entering into the second, that is the reason why I have to reset the convergence criteria and not only the time value. |
|
August 30, 2018, 11:02 |
|
#17 |
Senior Member
Join Date: Aug 2015
Posts: 494
Rep Power: 14 |
Good point -- I was hoping that writing in addition to changing the time would help. Should have looked at the code first.
What if you just wrote your own conversion criteria? Use two while loops, and when whatever you decide to calculate stops changing, you're converged. Caelan |
|
August 30, 2018, 21:13 |
|
#18 |
Senior Member
Pablo Higuera
Join Date: Jan 2011
Location: Auckland
Posts: 627
Rep Power: 19 |
Hi Pablo
the way to define the second variable is easy: Code:
simpleControl simpleSecond(mesh); Code:
startFrom startTime; startTime 0; |
|
June 29, 2020, 05:11 |
|
#19 |
New Member
Jesús Miguel Sánchez
Join Date: Jan 2019
Posts: 9
Rep Power: 7 |
Did the last solution work?
|
|
November 15, 2021, 02:22 |
|
#20 |
New Member
JHopman
Join Date: Oct 2021
Posts: 1
Rep Power: 0 |
Not sure if it has already been solved but this works for me.
Add an extra constructor for another pimpleControl object in your solver: Code:
pimpleControl pimple(mesh); //normal line pimpleControl pimple2(mesh, "PIMPLE2", true); //added line Code:
while (pimple2.loop()) { //do stuff in outer loop while (pimple2.correct()) { //do stufff in inner loop } } Code:
PIMPLE2 { nCorrectors x; nOuterCorrectors y; } |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[isoAdvector] Issues with modification of IsoAdvector Code | raunakbardia | OpenFOAM Community Contributions | 16 | September 4, 2020 05:36 |
possibility to perform two simple.loop inside the same code | palarcon | OpenFOAM Programming & Development | 5 | August 28, 2018 09:48 |
Type mismatch: Assigning a scalar to a Field<Type> inside templated BC code | karlli | OpenFOAM Programming & Development | 2 | August 28, 2017 01:25 |
public CFD Code development | Heinz Wilkening | Main CFD Forum | 38 | March 5, 1999 11:44 |
What kind of Cmmercial CFD code you feel well? | Lans | Main CFD Forum | 13 | October 27, 1998 10:20 |