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

Restarting simulations in openfoam with updated boundary conditions

Register Blogs Community New Posts Updated Threads Search

Like Tree12Likes
  • 3 Post By maheshraj
  • 3 Post By julien.decharentenay
  • 1 Post By arvindpj
  • 2 Post By wc34071209
  • 3 Post By miotto

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 11, 2013, 07:24
Default Restarting simulations in openfoam with updated boundary conditions
  #1
New Member
 
Mahesh
Join Date: Dec 2010
Posts: 9
Rep Power: 15
maheshraj is on a distinguished road
Hi All,

Suppose I have run a simulation to 2000 iterations with a set of BC's and want to run another 2000 iterations with changed BC's or a new mass flow rate.
The iteration should start from 2001 and should use the flow field already developed.
Could you let me know how to do this?

Thanks,
Mahesh
Arthas, Tom123 and AmandaB like this.
maheshraj is offline   Reply With Quote

Old   March 11, 2013, 10:48
Default
  #2
Senior Member
 
sail's Avatar
 
Vieri Abolaffio
Join Date: Jul 2010
Location: Always on the move.
Posts: 308
Rep Power: 17
sail is on a distinguished road
any reason why you can't simply edit the approriate file (U, p, etc...) in the 2000 directory?
__________________
http://www.leadingedge.it/
Naval architecture and CFD consultancy
sail is offline   Reply With Quote

Old   March 12, 2013, 12:18
Default
  #3
New Member
 
Mahesh
Join Date: Dec 2010
Posts: 9
Rep Power: 15
maheshraj is on a distinguished road
U or any file at 2000th iteration is a binary file and will contain the values at each node. So it is not possble to edit these files.

Last edited by maheshraj; March 13, 2013 at 09:08.
maheshraj is offline   Reply With Quote

Old   March 13, 2013, 19:39
Default
  #4
Senior Member
 
Julien de Charentenay
Join Date: Jun 2009
Location: Australia
Posts: 231
Rep Power: 18
julien.decharentenay is on a distinguished road
Send a message via Skype™ to julien.decharentenay
I think you can do it using the changeDictionary utility.
__________________
---
Julien de Charentenay
julien.decharentenay is offline   Reply With Quote

Old   March 14, 2013, 03:45
Default
  #5
Senior Member
 
Pablo Higuera
Join Date: Jan 2011
Location: Auckland
Posts: 627
Rep Power: 19
Phicau is on a distinguished road
Quote:
Originally Posted by maheshraj View Post
U or any file at 2000th iteration is a binary file and will contain the values at each node. So it is not possible to edit these files.
Yes you can, not directly, but it takes 3 steps.

Clone your constant and system folders, along with your 2000 folder.
Then change writeFormat on controlDict from binary to ascii.
Finally run foamFormatConvert.

Then you can change whatever you want. If you proceed in the inverse way you will end up with your new case in binary format again.
Phicau is offline   Reply With Quote

Old   March 14, 2013, 13:05
Default
  #6
Senior Member
 
sail's Avatar
 
Vieri Abolaffio
Join Date: Jul 2010
Location: Always on the move.
Posts: 308
Rep Power: 17
sail is on a distinguished road
Quote:
Originally Posted by maheshraj View Post
U or any file at 2000th iteration is a binary file and will contain the values at each node. So it is not possble to edit these files.
sorry, i usually keep my writeFormat in ascii, mor ease of modification and readability.
__________________
http://www.leadingedge.it/
Naval architecture and CFD consultancy
sail is offline   Reply With Quote

Old   March 14, 2013, 14:36
Default
  #7
Senior Member
 
mturcios777's Avatar
 
Marco A. Turcios
Join Date: Mar 2009
Location: Vancouver, BC, Canada
Posts: 740
Rep Power: 28
mturcios777 will become famous soon enough
I would use mapFields have the target mesh equipped with new boundary conditions (and specified at cutting patches)
mturcios777 is offline   Reply With Quote

Old   January 24, 2014, 10:04
Default
  #8
Member
 
Tobias Adam
Join Date: Oct 2013
Location: Siegen
Posts: 55
Rep Power: 13
Tobias Adam is on a distinguished road
can anyone show me an example for the Mapfieldsdict?
I don know how to create this properly.
When I map the fields, I always get the old boundary conditions of the source case.

best regards Tobi
Tobias Adam is offline   Reply With Quote

Old   January 25, 2014, 01:44
Default
  #9
Senior Member
 
Julien de Charentenay
Join Date: Jun 2009
Location: Australia
Posts: 231
Rep Power: 18
julien.decharentenay is on a distinguished road
Send a message via Skype™ to julien.decharentenay
Hi Tobi,

You may want to use the -sourceRegion/-targetRegion options of mapFields, which may be able to limit itself to the internalField (untested, and I would love to hear if it works).

But, as mentioned previously you may as well just modify the boundary conditions in the file 2000. My understanding from reading the file is that parts of it are binary but not all and you are likely to be able to edit the boundary condition definition. Below is an extract of one of my file:

Code:
ÁÀìLÍèýÁÀÑT¾» w‘@M%Þ“/ÁÀŸ0Ì|E-ÁÀ¿¯•Ì¡@K'ç2Œ¹ÀÀ“Un¥~;ÁÀv©NL¾ÀŸrgk	ã–@^)
3ÇáÀÀŽÏrÐùIÁÀûN§êwÈ”@(<VÎ^MÁÀä&•#ÂBÁÀŒ|Î-³—@yÃÅÀÀðûÁ{ÓÀÀüJj\
X”@N<ÿ9üëÀÀ&¶mðÀÀ);

boundaryField
{
    minX
    {
        type            zeroGradient;
    }
    maxX
    {
        type            zeroGradient;
    }
There is some binary for the fields values, but the boundary conditions are in plain text...
Simjoh, Tobias Adam and RjwV like this.
__________________
---
Julien de Charentenay
julien.decharentenay is offline   Reply With Quote

Old   January 26, 2014, 14:50
Default
  #10
Member
 
Ripudaman Manchanda
Join Date: May 2013
Posts: 55
Rep Power: 13
ripudaman is on a distinguished road
Does anyone have any idea how to automatize this?

Say I have to run 5 such instances successively where I change the boundary conditions 5 times.

Adding to the complexity, the number of time steps the solution will require to converge will be different for each case (I have modified my solver file to incorporate that). Is there anyway I could access the latestTime from outside Openfoam?
ripudaman is offline   Reply With Quote

Old   January 28, 2014, 07:38
Default
  #11
Senior Member
 
Julien de Charentenay
Join Date: Jun 2009
Location: Australia
Posts: 231
Rep Power: 18
julien.decharentenay is on a distinguished road
Send a message via Skype™ to julien.decharentenay
It depends on your preferred environment, script and/or programming language.

Do recover the latest time, you can just loop through the directories that are numerical values and select the highest one. It should be the latest one. This is a way to do it in ruby (Note: it assumes that time directories are integer, not float. In other words, it works for steady-state simulations):

Code:
times = []
Dir.foreach(".") { |f|
 times.push(f.to_f) if ((File.directory?(f)) and (f =~ /\d+/))
}
latestTime = times.max()
__________________
---
Julien de Charentenay

Last edited by julien.decharentenay; January 28, 2014 at 07:38. Reason: Add ")" to code expression
julien.decharentenay is offline   Reply With Quote

Old   May 1, 2017, 16:56
Default Editing the phi field to restart a simulation
  #12
New Member
 
Jorge Rivas Ordenes
Join Date: Dec 2016
Location: Chile
Posts: 12
Rep Power: 9
Coke Rivas Ordenes is on a distinguished road
Hi everyone! Hope i am not boring anyone posting in this "old" thread, but i have a question related to some topics that have been spoken here:

Quote:
any reason why you can't simply edit the approriate file (U, p, etc...) in the 2000 directory?
I am running a 10000 physical-seconds Large-Eddy-Simulation of the ABL with a PISO solver. At 5000 seconds of the simulation i must remove a .stl objects existing in the domain, which provokes an obvious changes it the initial mesh.

To restart the simulation from the 5000 seconds i have already edit the U, p, k and nut files but i am still struggling with the edition of the phi and phi_0 files. Related to this last issue, my questions are:
  1. Do i need to restart the simulation from the 5000 seconds the phi field? Or does OF calculates it with the p and U files?
  2. If the phi field is indeed required, how those OF runs through the faces of the domain?
  3. Can the changeDict utility handle a change in the mesh?
Thanks to all for the time you might take reading my question.
Coke Rivas Ordenes is offline   Reply With Quote

Old   May 1, 2017, 17:19
Default
  #13
Member
 
Arvind Jay
Join Date: Sep 2012
Posts: 97
Rep Power: 15
arvindpj is on a distinguished road
If the mesh is different, you can use the mapFields option to "map" the fields and restart your runs.
Cheers,
-J
Coke Rivas Ordenes likes this.
arvindpj is offline   Reply With Quote

Old   May 1, 2017, 17:28
Default
  #14
Senior Member
 
Yuehan
Join Date: Nov 2012
Posts: 142
Rep Power: 14
wc34071209 is on a distinguished road
If the mesh is the same, use changeDictionary utility.
wc34071209 is offline   Reply With Quote

Old   May 1, 2017, 17:35
Default
  #15
New Member
 
Jorge Rivas Ordenes
Join Date: Dec 2016
Location: Chile
Posts: 12
Rep Power: 9
Coke Rivas Ordenes is on a distinguished road
Quote:
Originally Posted by arvindpj View Post
If the mesh is different, you can use the mapFields option to "map" the fields and restart your runs.
Cheers,
-J
Thanks J! I will check it out right away.
Coke Rivas Ordenes is offline   Reply With Quote

Old   May 1, 2017, 17:36
Default
  #16
New Member
 
Jorge Rivas Ordenes
Join Date: Dec 2016
Location: Chile
Posts: 12
Rep Power: 9
Coke Rivas Ordenes is on a distinguished road
Quote:
Originally Posted by wc34071209 View Post
If the mesh is the same, use changeDictionary utility.
Unfortunately the mesh does change. Thank you Yuehan!
Coke Rivas Ordenes is offline   Reply With Quote

Old   April 7, 2020, 16:03
Default
  #17
New Member
 
Join Date: Mar 2020
Location: Paris
Posts: 5
Rep Power: 6
georgiak is on a distinguished road
Hi all,


I know that this conversation is quite old, but my issue is relative to this topic.


I have already run a simulation and I have a serious issue of wave reflection to the outlet boundary, so I would like to take the last path before the wave reflexion and try to change the outlet.



For this, initially I tried to use the changeDictionaryDict where I take always the same error:


--> FOAM FATAL IO ERROR:
keyword sampleMode is undefined in dictionary ".inlet"

file: .inlet from line 23 to line 25.

From function const Foam::entry& Foam::dictionary::lookupEntry(const Foam::word&, bool, bool) const
in file db/dictionary/dictionary.C at line 551.

FOAM exiting



After, I tried with the MapFields utility by changing the boudary condition in the target and by taking the latestTime information of the source. I take exactly the same error in the execution of mapFields too.


Does someone have met a relative error in the past and could explain to me?


Thank you in advance


Georgia
georgiak is offline   Reply With Quote

Old   April 14, 2020, 13:33
Default
  #18
Member
 
Gui Miotto
Join Date: Feb 2020
Posts: 30
Rep Power: 6
miotto is on a distinguished road
Hi everyone,


I recently had to go through this problem and I'll share here the solution I've adopted.
First of all:
  • I'm running interFoam from OpenFOAM 7
  • My geometry doesn't change. I just wanted to convert an outlet into a wall at specific times
My starting point was the suggestions by Vieri Abolaffio and Pablo Higuera. (Thank you guys). But with some remarks:
  1. I wouldn't edit field dictionaries by hand, even if ASCII. This can easily become a mess.
  2. It is safer to use a tool. Some suggested changeDictionary, however it is 2020 and this tool is now deprecated. Use foamDictionary instead.
I implemented everything at the Allrun script, most important here are the functions open_valve and close_valve:


Code:
#!/bin/bash

### BEGIN FUNCTION DEFINITIONS                                                         

delete_old_files()
{
    echo "Removing old files."
    rm -r -v dynamicCode
    rm -r -v postProcessing
    ls -1 | grep -E "processors?[0-9]*" | xargs -d"\n" rm -r -v
    foamListTimes -rm  # Deletes all time directories except t=0
    local ZERODIR=$(foamListTimes -withZero | head -n 1)
    rm ${ZERODIR}/alpha.water
    rm ${ZERODIR}/p_rgh
}

close_valve()
{
    local LATEST_TIME=$(foamListTimes -withZero -latestTime | tail -n 1)
    echo "Closing valve at" $LATEST_TIME

    # Patch type (not sure if this is really necessary)
    foamDictionary constant/polyMesh/boundary \
        -entry entry0.pres_inlet.type -set "wall" || exit 1
    # pressure
    foamDictionary ${LATEST_TIME}/p_rgh -entry boundaryField.pres_inlet \
        -set "{type fixedFluxPressure; value uniform 0;}" || exit 1
    # velocity
    foamDictionary ${LATEST_TIME}/U -entry boundaryField.pres_inlet \
        -set "{type noSlip;}" || exit 1
    # alpha
    foamDictionary ${LATEST_TIME}/alpha.water -entry boundaryField.pres_inlet \
        -set "{type zeroGradient;}" || exit 1
}

open_valve()  # Expects one argument: The inlet pressure in Pascal
{
    local LATEST_TIME=$(foamListTimes -withZero -latestTime | tail -n 1)
    echo "Opening valve at" $LATEST_TIME

    # Patch type (not sure if this is really necessary)
    foamDictionary constant/polyMesh/boundary \
        -entry entry0.pres_inlet.type -set "patch" || exit 1
    # pressure
    foamDictionary ${LATEST_TIME}/p_rgh -entry boundaryField.pres_inlet \
        -set "{type totalPressure; p0 uniform ${1};}" || exit 1
    # velocity
    foamDictionary ${LATEST_TIME}/U -entry boundaryField.pres_inlet \
        -set "{type pressureInletOutletVelocity; value uniform (0 0 0);}" || exit 1
    # alpha
    foamDictionary ${LATEST_TIME}/alpha.water -entry boundaryField.pres_inlet \
        -set "{type inletOutlet; inletValue uniform 1; value uniform 0;}" || exit 1
}

simulate_until()  # Expects one argument: endTime in seconds
{
    foamDictionary system/controlDict -entry endTime -set ${1} || exit 1

    if [[ $(foamListTimes) = "" ]]; then
        echo "Simulating for the first time."
        echo "setFields and decomposePar including geometry will be executed"
        setFields || exit 1
        decomposePar || exit 1
    else
        echo "Simulation already in progress."
        echo "Decomposing fields only."
        decomposePar -latestTime -fields || exit 1
    fi

    mpirun -np 12 interFoam -parallel || exit 1
    reconstructPar -newTimes || exit 1
}

### END FUNCTION DEFINITIONS                                                           


### USAGE EXAMPLE

delete_old_files

open_valve "4000"
simulate_until "2E-6"

close_valve
simulate_until "4E-6"

open_valve "8000"
simulate_until "6E-6"

close_valve
simulate_until "8E-6"
Two final observations:
  1. My boundary is called pres_inlet. You have to adapt this of course.
  2. This logic just works if your controlDict is set to start simulations from the latest time
Code:
startFrom       latestTime;
This solution works. I've tested it. But let me know if there is a more efficient/elegant way to do this.


Cheers
namsivag, krikre and Yann Scott like this.
miotto is offline   Reply With Quote

Old   October 9, 2020, 06:48
Default
  #19
Member
 
Kristjan
Join Date: Apr 2017
Location: Slovenia
Posts: 36
Rep Power: 9
krikre is on a distinguished road
This is a nice solution!


Any ideas on how to set the 'value' entry when switching from 'zeroGradient' to something else? externalWallHeatFluxTemperature in my case.



Zero gradient doesn't have a value entry because it uses neighboring cell values. I'd like to use those rather than a uniform field. Temperature in my case.


PS. It just occurred to me that externalWallHeatFluxTemperature is a mixed type BC so I can have it work like zeroGradient by using HTC=0. It's gonna look illogical but it'll work.
krikre is offline   Reply With Quote

Reply


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
mesh file for flow over a circular cylinder Ardalan Main CFD Forum 7 December 15, 2020 14:06
[Commercial meshers] exporting boundary conditions with pointwise -> openFoam ebah6 OpenFOAM Meshing & Mesh Conversion 2 September 16, 2012 17:57
CFX13 Post Periodic interface EtaEta CFX 7 December 8, 2011 18:15
OpenFOAM class to represent initial boundary conditions sanatan OpenFOAM Programming & Development 1 March 20, 2011 10:16
Please help with flow around car modelling! Tudor Miron CFX 17 March 19, 2004 20:23


All times are GMT -4. The time now is 13:36.