|
[Sponsors] |
How to get the current time within the controlDict? |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
November 4, 2014, 14:53 |
How to get the current time within the controlDict?
|
#1 |
New Member
duan
Join Date: Apr 2014
Posts: 6
Rep Power: 12 |
Hi,
I am trying to set different writeTimeInterval rather than a constant one during the runTime. for example: if (currentRunTime<t0) writeTimeInterval=value0; else writeTimeInterval=value1; Now I have problems on how to get current time within the controlDict. Here is my code: Code:
writeInterval #codeStream { code #{ /*// the sample works scalar start = readScalar(dict.lookup("startTime")); scalar end = readScalar(dict.lookup("endTime")); label nDumps = 5; os << ((end - start)/nDumps);*/ //================================================== //how to get the current time within controlDic??? //Tried but Not work //scalar t=this->db().time().value(); //error: invalid use of ‘this’ in non-member function //scalar t = runTime().value() ; //error: ‘runTime’ was not declared in this scope //scalar t = timeDirs.last().value(); //error: ‘timeDirs’ was not declared in this scope //scalar t = time().value(); //error: too few arguments to function ‘time_t time(time_t*) label t0 = 0.4; if (t <= t0) { os << 0.05; } else { os << 0.02; } #}; }; http://www.cfd-online.com/Forums/ope...ntroldict.html http://www.openfoam.org/version2.0.0...me-control.php http://www.cfd-online.com/Forums/ope...me-scalar.html Thanks in advance. |
|
November 4, 2014, 15:36 |
|
#2 |
Senior Member
|
Hi,
you'd like just to update writeInterval, depending on current time, you can create controlDict_1 with writeInterval_1, controlDict_2 with writeInterval_2 and use timeActivatedFileUpdate like below: Code:
functions { fileUpdate1 { type timeActivatedFileUpdate; functionObjectLibs ("libutilityFunctionObjects.so"); outputControl timeStep; outputInterval 1; fileToUpdate "$FOAM_CASE/system/controlDict"; timeVsFile ( (-1 "$FOAM_CASE/system/controlDict_1") (10 "$FOAM_CASE/system/controlDict_2") ); } } |
|
November 6, 2014, 08:12 |
|
#4 |
New Member
duan
Join Date: Apr 2014
Posts: 6
Rep Power: 12 |
For alternative,
I also wrote a script, to run the case in 3 steps: 0=>t1 ,with write time interval WI1 t1=>t2 ,with write time interval WI2 t2=>t3 ,with write time interval WI3 It's not a very good solution, but works. If someone is interested, see the attached file. |
|
July 25, 2015, 04:47 |
scalar t = runTime().value()
|
#5 |
Member
SM
Join Date: Dec 2010
Posts: 97
Rep Power: 15 |
Does any one know how to get
Code:
scalar t = runTime().value Code:
writeInterval #codeStream I am getting the same error as reported here Code:
system/controlDict.#codeStream:40:13: error: ‘runTime’ was not declared in this scope |
|
July 25, 2015, 12:43 |
|
#6 |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52 |
It's more like:
Code:
scalar t = U.runTime().value();
__________________
Keep foaming, Tobias Holzmann |
|
March 22, 2016, 10:25 |
|
#7 |
New Member
Carles
Join Date: Aug 2015
Posts: 4
Rep Power: 11 |
Hi Tobi,
I tried Code:
scalar t = U.runTime().value(); Code:
error: ‘U’ was not declared in this scope Can you elaborate a little more about that and the namespace option? Thanks! |
|
March 21, 2021, 13:51 |
|
#8 | |
Member
Join Date: Mar 2009
Posts: 90
Rep Power: 17 |
Quote:
|
||
March 22, 2021, 06:53 |
|
#9 |
Member
Andrea Di Ronco
Join Date: Nov 2016
Location: Milano, Italy
Posts: 57
Rep Power: 10 |
I didn't try myself, but you should be able to access the mesh database, and then the simulation time with something like
Code:
db().time().value() In the codeStream documentation (https://cpp.openfoam.org/v6/classFoa...m.html#details) there should be an example on how to access the database from within a codeStream instance: Code:
someEntry #codeStream { code #{ const IOdictionary& d = static_cast<const IOdictionary&>(dict); const fvMesh& mesh = refCast<const fvMesh>(d.db()); ... #}; }; Andrea |
|
March 23, 2021, 05:09 |
|
#10 |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52 |
If you call db() you need an object. It is the same as with U.time().value(). U is an object of e.g., volVectorField.
It is not possible to just call db().time().value(). Probably this works: Code:
this->db().time().value(); Depending if »this« is a pointer or a reference you have to choose the point ».« operator or the other one »->«.
__________________
Keep foaming, Tobias Holzmann |
|
March 23, 2021, 05:29 |
|
#11 | |
Member
Andrea Di Ronco
Join Date: Nov 2016
Location: Milano, Italy
Posts: 57
Rep Power: 10 |
Quote:
If you already have some object U like a volScalarField, then it is much easier to just call U.db(). If not, this->db() may do the job in general but since I wasn't sure about what is returned by this in a codeStream context, my suggestion was to look at the documentation and see how to retrieve the simulation database from the current dictionary. Andrea |
||
March 23, 2021, 05:31 |
|
#12 |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52 |
Does not fit 100 % but here is something similar.
https://www.youtube.com/watch?v=cvWaXBnEz1U&t=1095s
__________________
Keep foaming, Tobias Holzmann |
|
March 27, 2024, 06:29 |
|
#13 |
New Member
Join Date: Mar 2024
Posts: 1
Rep Power: 0 |
Hi,
I meet the same issue here. Does anyone know how to get the current time in the controlDict via codeStream? |
|
Yesterday, 09:53 |
|
#14 |
New Member
bou
Join Date: May 2014
Posts: 11
Rep Power: 12 |
Code:
mesh().time().value(); |
|
Yesterday, 11:06 |
How to replace InterCondensatingEvaporatingFoam in OpenFOAM 11 for condensation model
|
#15 |
New Member
Sélectionnez une option
Join Date: Dec 2024
Posts: 1
Rep Power: 0 |
Hello everyone,
I am currently working with OpenFOAM 11 and previously used the solver InterCondensatingEvaporatingFoam in an older version for simulating condensation and evaporation processes. I am wondering if anyone knows the equivalent solver or method to handle condensation processes in OpenFOAM 11, as InterCondensatingEvaporatingFoam appears to no longer be available or updated. Could anyone guide me on how to replace InterCondensatingEvaporatingFoam or suggest an alternative solver in OpenFOAM 11 that can handle both condensation and evaporation effectively? Thank you in advance for your help! Best regards, |
|
Tags |
controldict, current run time, write control |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Current density visualisation (PEM fuel cell add-on module) | pchoopanya | FLUENT | 10 | August 21, 2023 15:33 |
Multiple floating objects | CKH | OpenFOAM Running, Solving & CFD | 14 | February 20, 2019 10:08 |
Superlinear speedup in OpenFOAM 13 | msrinath80 | OpenFOAM Running, Solving & CFD | 18 | March 3, 2015 06:36 |
pisoFoam with k-epsilon turb blows up - Some questions | Heroic | OpenFOAM Running, Solving & CFD | 26 | December 17, 2012 04:34 |
Could anybody help me see this error and give help | liugx212 | OpenFOAM Running, Solving & CFD | 3 | January 4, 2006 19:07 |