CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Write Control at Specified Times (https://www.cfd-online.com/Forums/openfoam-programming-development/223805-write-control-specified-times.html)

Brandani January 27, 2020 10:56

Write Control at Specified Times
 
I am running a combustion simulation model in OpenFoam and would like to write out my solution only at specified times.

So, my model runs for 8000 timeSteps and I would like to only write down solutions at 5500, 5782, 6245 and other times.

I can create a separate case and change its end-time to those specified times as follows:

foamDictionary -entry "writeInterval" -set "1" system/controlDict
foamDictionary -entry "purgeWrite" -set "1" system/controlDict
foamDictionary -entry "endTime" -set "5782" system/controlDict

However, with the above method, I need to clone the case and change my endTime for every desired time-based solution. I would like to sample about 30 different solution times quite far from each other meaning I cannot write out all 8000 time-steps due to storage issues.

Is there any way to do that? Thank you!

clapointe January 27, 2020 14:48

Couldn't you, with a single simulation, run until 5500 and (write and) stop. Then restart and run until your next cutoff (and stop), etc... ? You would just need to edit the controlDict accordingly before each restart (and make sure to make startTime latestTime). No programming necessary.

Caelan

Brandani February 11, 2020 08:14

Thank you for this suggestion!
I did just that and wrote a small python script that generates text that can be directly copied into your Allrun script:

from itertools import tee, islice, chain

def previous_and_next(some_iterable):
prevs, items, nexts = tee(some_iterable, 3)
prevs = chain([None], prevs)
nexts = chain(islice(nexts, 1, None), [None])
return zip(prevs, items, nexts)


list_of_times = [2425, 2733, 2735, 2737, 2738, 2984, 3001, 3307, 3309, 3311, 3312]

for previous, item, nxt in previous_and_next(list_of_times):
print('foamDictionary -entry "startTime" -set "%d" system/controlDict' %item)
print('foamDictionary -entry "writeInterval" -set "1" system/controlDict')
print('foamDictionary -entry "purgeWrite" -set "1" system/controlDict')
print('foamDictionary -entry "endTime" -set "%d" system/controlDict' %nxt)
print('runParallel -o $application')

HPE February 11, 2020 08:42

might help a bit?
https://www.openfoam.com/documentati...e-control.html

Brandani March 11, 2020 12:26

Hi! Thanks for your response but I cannot seem to find (in the link you shared) a tool that would help me? I see conditioning like stop simulation if x occurs but not how to write out custom time steps? Thanks!


All times are GMT -4. The time now is 04:27.