CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Post-Processing (https://www.cfd-online.com/Forums/openfoam-post-processing/)
-   -   Shell script to handle Segmentation faults arising from execFlowFunctionObjects (https://www.cfd-online.com/Forums/openfoam-post-processing/148940-shell-script-handle-segmentation-faults-arising-execflowfunctionobjects.html)

pruthvi1991 February 22, 2015 14:20

Shell script to handle Segmentation faults arising from execFlowFunctionObjects
 
Hello foamers!

I frequently face segmentation faults and corrupted double linked list errors when using execFlowFunctionObjects for post processing. I get this error when I run cases with pmpleDyMFoam solver.

As a work around for this problem I wrote a simple shell script which will find out the time at which execFlowFunctionObjects crashed and makes it restart from that point. This is not an elegant way of fixing the problem but it works

The code is on github

Code:

#!/bin/bash

echo "This script will call execFlowFunctionObjects to integrate the pressure and viscous forces over the chosen patches.
This function may take a few minutes to execute, please be patient. Make sure you entered the desired function object
in system/controlDict. For Eg: #include "forceCoeffs" . If the function is commented this script will not work"

sleep 2

echo "Deleting log files from previous runs. You have 8 seconds to abort by holding ctrl-c"

sleep 8
#mkdir previous_data
rm log.forces # ./previous_data/
rm -r postProcessing # ./previous_data/

endTime=$(grep -w 'endTime' ./system/controlDict | grep '[0-9]' | sed 's/;//g' | awk '{print$2}')        # Gets endTime value from controlDict
intendTime=$(grep -w 'endTime' ./system/controlDict | grep '[0-9]' | sed 's/;//g' | awk '{print$2*1000}')      # Multiplying by 1000 to convert to integer in case endTime is float
writeTime=$(grep -w 'writeInterval' ./system/controlDict | grep '[0-9]' | sed 's/;//g' | awk '{print$2}') # Gets writeInterval from controlDict
execFlowFunctionObjects >> log.forces &                # Executes the function execFlowFunctionObjects and writes output to log.forces

sleep 15        # If there is no sleep time, bash proceeds to the next command before execFlowFunctionObjects is run. Increase this if your simulation is large

presentTime=$(tail -22 log.forces | grep Time | awk '{print$3}' | awk NR==1)        # Checks for many time steps the function ran and gets the last time value
intpresentTime=$(tail -22 log.forces | grep Time | awk '{print$3*1000}' | awk NR==1)        # Converting a possible float to integer

echo "endTime = $endTime, presentTime = $presentTime, Integer endTime = $intendTime, Integer presentTime = $intpresentTime, writeInterval = $writeTime"

echo "Entering Loop at $presentTime"

while [ $intpresentTime -lt $intendTime ];                # If the function failed to execute at some point this loop will make it start again
do
#        startTime=$(python -c print " $presentTime + $writeTime ")  # Finds time from which the function must start again
        startTime=$(echo "$presentTime+$writeTime" | bc)  # Finds time from which the function must start again
        echo "Crashed at $presentTime, re-starting from $startTime"
        execFlowFunctionObjects -time $startTime: >> log.forces &
        sleep 10        # Waits for 15 seconds before executing next command. This is necessary to ensure execFlowFunctionObjects is not re-run midway
        presentTime=$(tail -22 log.forces | grep Time | awk '{print$3}' | awk NR==1)
        echo $presentTime
        intpresentTime=$(tail -22 log.forces | grep Time | awk '{print$3*1000}' | awk NR==1)
done
               
echo "Finally reached $presentTime"

After the script is run, numerous force/ forceCoeffs files will be generated in the postProcessing directory. I wrote another script to merge them together and parse the data. Here is the github link.

Thanks,
Pruthvi.


All times are GMT -4. The time now is 03:34.