change U and controlDict from shell
Hi everyone
A boundary condition in the /U directory looks like this: Code:
outlet I thought the easiest way to implement this is a shell script, something like this: Code:
#!/bin/sh 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! |
Hi Josh,
You could just run one simulation with a time varying boundary condition. See: Code:
outlet |
Quote:
|
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. |
Quote:
Code:
outlet Quote:
Code:
#!/bin/sh 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! |
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 :) |
Quote:
|
Hey Flowkersma
One last question. Would you execute these changes from a shell script or in python? More importantly, why? |
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']) |
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! |
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 |
Quote:
I do have a question for you: when running through the table manually, so using the approach below rather than table: Code:
outlet Do you know what I'm missing? Either way, the table works, so thank you! |
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.
|
All times are GMT -4. The time now is 16:34. |