|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +cd ${0%/*} || exit 1 # Run from this directory |
| 4 | +. $WM_PROJECT_DIR/bin/tools/RunFunctions # Tutorial run functions |
| 5 | + |
| 6 | +# This script prepares and runs all the participants in one terminal, |
| 7 | +# forwarding the solvers' output to log files. |
| 8 | +# Alternatively, you may execute the script "runFluid" and start the Solid participants manually |
| 9 | +# in separate terminals. |
| 10 | + |
| 11 | +# Run this script with "-parallel" for parallel simulations |
| 12 | + |
| 13 | +# The script "Allclean" cleans-up the result and log files. |
| 14 | +# Set up the run parameters: |
| 15 | + |
| 16 | +# 1 for true, 0 for false |
| 17 | +parallel=0 |
| 18 | +if [ "$1" = "-parallel" ]; then |
| 19 | + parallel=1 |
| 20 | +fi |
| 21 | + |
| 22 | +# =============== Participant 1: Fluid =========================== |
| 23 | +Participant1="Fluid" |
| 24 | + |
| 25 | + # Prepare |
| 26 | + echo "Preparing the ${Participant1} participant..." |
| 27 | + |
| 28 | + cd $Participant1 |
| 29 | + echo " Restoring 0/ from 0.orig/..." |
| 30 | + rm -rfv 0 |
| 31 | + cp -r 0.orig 0 |
| 32 | + cd .. |
| 33 | + |
| 34 | + echo " Preparing the mesh..." |
| 35 | + blockMesh -case ${Participant1} > ${Participant1}_blockMesh.log 2>&1 |
| 36 | + checkMesh -case ${Participant1} > ${Participant1}_checkMesh.log 2>&1 |
| 37 | + |
| 38 | + # get application information |
| 39 | + cd ${Participant1} |
| 40 | + Solver1=$(getApplication) # solver |
| 41 | + echo " ${Participant1} Solver: ${Solver1}." |
| 42 | + cd .. |
| 43 | + |
| 44 | + # Run and get the process id |
| 45 | + if [ $parallel -eq 1 ]; then |
| 46 | + echo " Decomposing the case..." |
| 47 | + decomposePar -force -case ${Participant1} > ${Participant1}_decomposePar.log 2>&1 |
| 48 | + cd ${Participant1} |
| 49 | + nproc=$(getNumberOfProcessors) |
| 50 | + cd .. |
| 51 | + echo " Starting the ${Participant1} participant in parallel..." |
| 52 | + mpirun -np ${nproc} ${Solver1} -parallel -case ${Participant1} > ${Participant1}.log 2>&1 & |
| 53 | + else |
| 54 | + echo " Starting the ${Participant1} participant in serial..." |
| 55 | + ${Solver1} -case ${Participant1} > ${Participant1}.log 2>&1 & |
| 56 | + fi |
| 57 | + PIDParticipant1=$! |
| 58 | + |
| 59 | +# =============== Participant 2: Solid1 =========================== |
| 60 | +Participant2="Solid1" |
| 61 | +Solver2="linear_elasticity1" |
| 62 | + |
| 63 | + # Run |
| 64 | + echo " Starting the ${Participant2} participant..." |
| 65 | + ./runSolid1 -linear > ${Participant2}.log 2>&1 & |
| 66 | + PIDParticipant2=$! |
| 67 | + |
| 68 | + |
| 69 | +# =============== Participant 3: Solid2 =========================== |
| 70 | +Participant3="Solid2" |
| 71 | +Solver3="linear_elasticity2" |
| 72 | + |
| 73 | + # Run |
| 74 | + echo " Starting the ${Participant3} participant..." |
| 75 | + ./runSolid2 -linear > ${Participant3}.log 2>&1 & |
| 76 | + PIDParticipant3=$! |
| 77 | + |
| 78 | + |
| 79 | +# =============== Wait for all the participants to finish ======= |
| 80 | +echo "Waiting for the participants to exit..., PIDs: ${PIDParticipant1}, ${PIDParticipant2}, ${PIDParticipant3}" |
| 81 | +echo "(you may run 'tail -f ${Participant1}.log' in another terminal to check the progress)" |
| 82 | + |
| 83 | +echo "To interrupt the simulation, press 'c'. Ctrl+C will only send the processes to the background." |
| 84 | +while [ -e /proc/${PIDParticipant1} ]; do |
| 85 | + read -r -t1 -n1 input |
| 86 | + if [ "$input" = "c" ]; then |
| 87 | + kill ${PIDParticipant1} |
| 88 | + kill ${PIDParticipant2} |
| 89 | + kill ${PIDParticipant3} |
| 90 | + false |
| 91 | + fi |
| 92 | +done |
| 93 | + |
| 94 | +if [ $? -ne 0 ] || [ "$(grep -c -E "error:" ${Participant1}.log)" -ne 0 ] || [ "$(grep -c -E "error:" ${Participant2}.log)" -ne 0 ] || [ "$(grep -c -E "error:" ${Participant3}.log)" -ne 0 ]; then |
| 95 | + echo "" |
| 96 | + echo "Something went wrong... See the log files for more." |
| 97 | + # Precaution |
| 98 | + kill ${PIDParticipant1} |
| 99 | + kill ${PIDParticipant2} |
| 100 | + kill ${PIDParticipant3} |
| 101 | + |
| 102 | +else |
| 103 | + echo "" |
| 104 | + echo "The simulation completed! (check for any errors)" |
| 105 | + if [ $parallel -eq 1 ]; then |
| 106 | + echo "Reconstructing fields..." |
| 107 | + reconstructPar -case ${Participant1} > ${Participant1}_reconstructPar.log 2>&1 & |
| 108 | + fi |
| 109 | + |
| 110 | + # Workaround for issue #26 |
| 111 | + echo "Problems with time directories without results? Run the script removeObsoleteFolders.sh and see issue #26 on GitHub." |
| 112 | + # ./removeObsoleteFolders.sh |
| 113 | + |
| 114 | + echo "You may now open '${Participant1}/${Participant1}.foam' in ParaView." |
| 115 | + # Note: ".foam" triggers the native OpenFOAM reader of ParaView. |
| 116 | + # Change to ".OpenFOAM" to use the OpenFOAM reader provided with OpenFOAM. |
| 117 | +fi |
| 118 | + |
| 119 | +echo "" |
| 120 | +echo "### NOTE ### Make sure to use the correct solver for your OpenFOAM version! (pimpleFoam for OpenFOAM v1806, OpenFOAM 6, or newer, vs pimpleDyMFoam for older) You may change this in your Fluid/system/controlDict file, if needed." |
0 commit comments