CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Running, Solving & CFD (https://www.cfd-online.com/Forums/openfoam-solving/)
-   -   Restarting simulations in openfoam with updated boundary conditions (https://www.cfd-online.com/Forums/openfoam-solving/114435-restarting-simulations-openfoam-updated-boundary-conditions.html)

maheshraj March 11, 2013 06:24

Restarting simulations in openfoam with updated boundary conditions
 
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

sail March 11, 2013 09:48

any reason why you can't simply edit the approriate file (U, p, etc...) in the 2000 directory?

maheshraj March 12, 2013 11:18

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.

julien.decharentenay March 13, 2013 18:39

I think you can do it using the changeDictionary utility.

Phicau March 14, 2013 02:45

Quote:

Originally Posted by maheshraj (Post 413486)
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.

sail March 14, 2013 12:05

Quote:

Originally Posted by maheshraj (Post 413486)
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.

mturcios777 March 14, 2013 13:36

I would use mapFields have the target mesh equipped with new boundary conditions (and specified at cutting patches)

Tobias Adam January 24, 2014 09:04

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

julien.decharentenay January 25, 2014 00:44

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:

LT w@M%ޓ/0|E-̡@K'2Un~;vNLrgk        @^)
3rINwȔ@(<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...

ripudaman January 26, 2014 13:50

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?

julien.decharentenay January 28, 2014 06:38

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()


Coke Rivas Ordenes May 1, 2017 15:56

Editing the phi field to restart a simulation
 
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.

arvindpj May 1, 2017 16:19

If the mesh is different, you can use the mapFields option to "map" the fields and restart your runs.
Cheers,
-J

wc34071209 May 1, 2017 16:28

If the mesh is the same, use changeDictionary utility.

Coke Rivas Ordenes May 1, 2017 16:35

Quote:

Originally Posted by arvindpj (Post 647262)
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 May 1, 2017 16:36

Quote:

Originally Posted by wc34071209 (Post 647264)
If the mesh is the same, use changeDictionary utility.

Unfortunately the mesh does change. Thank you Yuehan!

georgiak April 7, 2020 15:03

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

miotto April 14, 2020 12:33

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

krikre October 9, 2020 05:48

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.


All times are GMT -4. The time now is 21:10.