CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Post-Processing

Displaying OpenFOAM Results Automatically in ParaView through a Single Command

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 21, 2022, 20:28
Default Displaying OpenFOAM Results Automatically in ParaView through a Single Command
  #1
New Member
 
Erol Bicer
Join Date: Apr 2021
Location: Seoul
Posts: 2
Rep Power: 0
nucerl is on a distinguished road
I have been doing a parametric study and it was getting heavier on me to manually load a ParaView state file every time I change the working directory. Later I found out that I could change the folder path in the state file and then load it from the terminal. So, I semi-automated the process. However, this still requires going manually to a state file and changing the folder path to the current working directory. This also started to bother me so I found a way to fully automate the process but I am not sure whether this is the most efficient way to do it. So, I will explain below how I did it step by step which might be useful for those who are looking for something similar and I would appreciate it if anyone could tell me an easier way to do it. I also wanted to share the bash script that I am using to automatically run my simulations in parallel. So, the script does everything from pre-processing to post-process.

Task: Automatically run a simulation and display the results in ParaView using an existing state file.
  1. Save a state file (*.pvsm) after displaying all the results you want. (Make sure to give it a unique name)
  2. Go to the (*.pvsm) file and search for ".foam" ( or however you loaded the time directories, perhaps .OpenFOAM)
  3. Find the line that contains your folder path and change it to a unique string as shown in the box below.

    Code:
    <Element index="0" value="YOUR_FOLDER_PATH/YOUR_FILE_NAME.foam"/>
    <Element index="0" value="myUniqueString/myUniqueFileName.foam"/>
  4. Save the new state file with a unique name this will be your template.
  5. Use the 'sed' command to go into the saved state file replace the folder path and save it as a new file using the current directory name. (Notice that we are using '?' instead '/' and the reason is explained here)

    Code:
    sed 's?myUniqueString?'`pwd`'?' EARLIER_SAVED_STATE_FILE_NAME.pvsm > ${PWD##*/}.pvsm
  6. Finally, run the command below to display your results in ParaView

    Code:
    paraview --state=${PWD##*/}.pvsm

Now the explanation is out of the way, here is my bash script to run a case in parallel using multiphaseEulerFoam. It can be easily tweaked to adjust to your case. Please note that the script assumes you have saved the '0' time directory as '0.orig' which is a good practice in my opinion.

Save the code below as whatever name you want (e.g. cRun) and run it as '/cRun ' from the command line. It is also a good practice to separate the bash file into two files in case you want to only clean or only run sometimes.

Code:
# CLEANING PART

# clean the previous simulation data
. $WM_PROJECT_DIR/bin/tools/CleanFunctions
# omit this if you don't use '0.orig'
rm -rf ./0
cleanCase

# the run will be saved to 'log.parallelRun' file with the current directory
# name at the first line 
echo "Case ${PWD##*/}" >> log.parallelRun
clear

# RUNNING PART

# generate mesh
# you can just use 'blockMesh' if you use built-in mesh generation utility
ideasUnvToFoam yoshidaMeshFiner.unv | tee log.mesh 

# optional 'changeDictionary' unless you have to change names in the boundaries
changeDictionary | tee -a log.mesh 
checkMesh | tee -a log.mesh

# copy '0.orig' folder to '0' folder
cp -r ./0.orig ./0

# optional to set the initial conditions properly
setFields | tee log.preRun
# decompose the mesh for parallel run
decomposePar | tee -a log.preRun

# run the simulation in parallel with the desired number of cores
mpirun -np 16 multiphaseEulerFoam -parallel | tee -a log.parallelRun

# reconstruct the time driectories
reconstructPar

# create dummy.foam
touch myUniqueFileName.foam

# change the folder path in the file and save it as foldername.pvsm
sed 's?myUniqueString?'`pwd`'?' EARLIER_SAVED_STATE_FILE_NAME.pvsm > ${PWD##*/}.pvsm

# open in paraview
paraview --state=${PWD##*/}.pvsm
Let me know if it works for you.

Happy new year to you all.
nucerl is offline   Reply With Quote

Reply

Tags
automate, bash script, paraview, post processing, state file


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
[OpenFOAM] Cant view the results on ParaView OpenFOAM saugatshr4 ParaView 0 May 10, 2021 02:23
Suggestion for a new sub-forum at OpenFOAM's Forum wyldckat Site Help, Feedback & Discussions 20 October 28, 2014 10:04
OpenFOAM15 installables are incomplete problem with paraFoam tryingof OpenFOAM Bugs 17 December 7, 2008 05:41
Problem of compilation OF 14Allwmake command not found erik_d OpenFOAM Bugs 13 September 13, 2008 22:45
Regarding FoamX running Kindly help out hariya03 OpenFOAM Pre-Processing 0 April 18, 2008 05:26


All times are GMT -4. The time now is 20:12.