|
[Sponsors] |
April 8, 2020, 16:04 |
change U and controlDict from shell
|
#1 |
Senior Member
Josh McCraney
Join Date: Jun 2018
Posts: 220
Rep Power: 8 |
Hi everyone
A boundary condition in the /U directory looks like this: Code:
outlet { type fixedValue; value uniform (0 VALUE 0); //fixed inlet velocity } I thought the easiest way to implement this is a shell script, something like this: Code:
#!/bin/sh setFields decomposePar mpirun -np 16 interFoam -parallel 1) in controlDict the endtime needs to be 5 seconds larger than it previously was 2) VALUE in the /U directory needs to grab the next number from the .dat file. Any help is so appreciated! |
|
April 8, 2020, 16:58 |
|
#2 |
Senior Member
Mikko
Join Date: Jul 2014
Location: The Hague, The Netherlands
Posts: 243
Rep Power: 12 |
Hi Josh,
You could just run one simulation with a time varying boundary condition. See: Code:
outlet { type uniformFixedValue; uniformValue table ( (0 (0 1 0)) (5 (0 2 0)) (10 (0 3 0)) (15 (0 4 0)) (20 (0 5 0)) (25 (0 6 0)) ); } |
|
April 8, 2020, 18:25 |
|
#3 | |
Senior Member
Josh McCraney
Join Date: Jun 2018
Posts: 220
Rep Power: 8 |
Quote:
|
||
April 9, 2020, 03:16 |
|
#4 |
Senior Member
Mikko
Join Date: Jul 2014
Location: The Hague, The Netherlands
Posts: 243
Rep Power: 12 |
What do you mean by it takes more time? If you mean in terms of CPU time, it is insignificant. On the other hand if you use the other approach which you suggested, it that takes much more CPU time because of the re-initialization of each simulation.
But if you really want to go for it. It is also quite easy to implement. A bash script with a for loop which loops through the 6 different values and at each iterations does the following: 1. Sets the the boundary condition in 0/U file with sed tool 2. Sets the end time of the simulation in controlDict to 5 units further (sed) 3. Executes the solver 4. Waits for the solver to finish And as you already suggested, you should set in controlDict the simulation to start from the latest time. |
|
April 11, 2020, 15:02 |
|
#5 | ||
Senior Member
Josh McCraney
Join Date: Jun 2018
Posts: 220
Rep Power: 8 |
Quote:
Code:
outlet { type uniformFixedValue; uniformValue table ( (0 (0 1E-1 0)) (0.05 (0 -1E-1 0)) ); } Quote:
Code:
#!/bin/sh rm -r postProcessing rm -r processor* rm 0/alpha.water rm constant/dynamicMeshDict cp -r ../mesh/constant/polyMesh constant setFields decomposePar # LOOP THROUGH ALL OF VEL for (( i = 0; i < LENGTH($VEL); i++ )); do # SET LINE NUMBERS lineU = 33 lineContDict = 26 # REPLACE lineU (line 33) in 0/U WITH value uniform (0 $VEL(i) 0) sed -i "${lineU}s/.*/value uniform (0 $VEL(i) 0);/" ./0/U # UPDATE endTime (line 26) IN system/controlDict WITH VEL_T sed -i "${lineContDict}s/.*/endTime i*$VEL_t;/" ./system/controlDict # RUN SOLVER mpirun -np 16 interFoam -parallel # > log.interFoam & # COMMENT TO VIEW OUTPUT done 1) unsure how to grab the length of the VEL vector, so I wrote LENGTH($VEL) 2) how to grab the component values of the VEL vector, so I just wrote $VEL(i) 3) how to let the system know where VEL is even stored so it can grab values from there If you see anything else I'd really appreciate it! This was tough for me! |
|||
April 13, 2020, 04:28 |
|
#6 |
Senior Member
Mikko
Join Date: Jul 2014
Location: The Hague, The Netherlands
Posts: 243
Rep Power: 12 |
Surely the faster technique depends on many factors such as how long the initialization time is in comparison to the total simulation time. I'm still surprised that the time dependent boundary condition is so expensive.
I'm not the right person to ask about Bash programming. For more complicated things I use Python but what you want to should be still doable: 1. length of vector: ${#vector[@]} 2. component i of vector: ${vector[i]} 3. better do an online search |
|
April 13, 2020, 18:22 |
|
#7 | |
Senior Member
Josh McCraney
Join Date: Jun 2018
Posts: 220
Rep Power: 8 |
Quote:
|
||
April 14, 2020, 13:02 |
|
#8 |
Senior Member
Josh McCraney
Join Date: Jun 2018
Posts: 220
Rep Power: 8 |
Hey Flowkersma
One last question. Would you execute these changes from a shell script or in python? More importantly, why? |
|
April 14, 2020, 14:19 |
|
#9 |
Senior Member
Mikko
Join Date: Jul 2014
Location: The Hague, The Netherlands
Posts: 243
Rep Power: 12 |
I would still do this in a Bash script but for anything more complex I would use Python. I know Python much better and I think it's better general purpose language. Some commands (e.g. copy/remove file, change directory) are simpler in Bash because it is the command line language. Also, it has some very powerful commands such as sed.
In a Python script you can also execute Bash commands or the other way around so you can combine the best of both worlds. Here are a couple of examples with Python's subprocess module to call Bash: Code:
subprocess.call(['simpleFoam','-case','firstCase']) subprocess.call(['sed','-i', 's/endTime 1;/endTime 5;/','system/controlDict'] |
|
April 28, 2020, 18:37 |
|
#10 |
Senior Member
Josh McCraney
Join Date: Jun 2018
Posts: 220
Rep Power: 8 |
Hey Mikko
It appears the table you suggested gives drastically different results than running the simulation for a set amount of time, then switching the controlDict and U files to the next spot in the time step, and so on. Any idea what is happening? What makes maters even worse, when I use a python script I wrote that copies the values for U from a different file (same file I manually copy from) I get different results still! The odd thing is I can look at the U file and ensure it matches the manual copy. Please advise! |
|
April 29, 2020, 01:46 |
|
#11 |
Senior Member
Mikko
Join Date: Jul 2014
Location: The Hague, The Netherlands
Posts: 243
Rep Power: 12 |
Hi Josh,
Have you compared the boundary condition values at the same time steps between the different approaches? If you read the documentation of 5.2.3.4 Time-varying boundary conditions, the table boundary condition interpolates values linearly between times. I guess you can overcome this by defining the table as follows: Code:
outlet { type uniformFixedValue; uniformValue table ( (0 (0 1 0)) (4.9999 (0 1 0)) (5 (0 2 0)) (9.9999 (0 2 0)) (10 (0 3 0)) (14.9999 (0 3 0)) (15 (0 4 0)) (14.9999 (0 4 0)) ); } |
|
April 30, 2020, 21:12 |
|
#12 | |
Senior Member
Josh McCraney
Join Date: Jun 2018
Posts: 220
Rep Power: 8 |
Quote:
I do have a question for you: when running through the table manually, so using the approach below rather than table: Code:
outlet { type fixedValue; value uniform (0 -2.3074827e-04 0); } Do you know what I'm missing? Either way, the table works, so thank you! |
||
May 1, 2020, 03:03 |
|
#13 |
Senior Member
Mikko
Join Date: Jul 2014
Location: The Hague, The Netherlands
Posts: 243
Rep Power: 12 |
The boundary condition is read from the time-step that you specify in controlDict so you have to change it in that folder. So if you stop your first simulation at t=1 and start it again from latestTime, then you should modify the boundary condition in 1/U file.
|
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Change MotorBike Tutorial to Water | connoranderson | OpenFOAM Running, Solving & CFD | 0 | January 7, 2015 20:57 |
controlDict and sampleDict giving different results | Shenan | OpenFOAM Post-Processing | 2 | November 15, 2014 10:15 |
Forces not calculated when including a library in controlDict | fusij | OpenFOAM | 2 | May 13, 2011 07:25 |
writing controlDict as otherfields | ubaid | OpenFOAM | 5 | September 29, 2010 07:28 |
FoamXException by change in controlDict | vladimir | OpenFOAM Pre-Processing | 2 | March 14, 2007 14:32 |