OpenFoamSimu to post-process simulation

This example shows how to organize the results of a simulation into an OpenFoamSimu object that contains all the results of one simulation.

First create a simulation object with OpenFoamSimu

Note

This class allows you to create an object associated to a simulation

# import the class OpenFoamSimu
from fluidfoam import OpenFoamSimu

#path were all simulations are located
path = '../../output_samples'
#Name of the simulation to load, if not given, the program lists all simulations
#located in path and ask you to choose which one to load
simu = 'box'
#time step to load, if not given, load last time step
timeStep = '4'

#Load simulation and create an object called mySimu that contain the results of
#the simulation, structured=True indicates that the mesh is structured
mySimu = OpenFoamSimu(path=path, simu=simu, timeStep=timeStep, structured=True)
# .. note:: Each file saved at timeStep of the simulation  are
#           automatically loaded as variables of object mySimu.
#           You can know what variables have been loaded using function keys() of
#           the class

mySimu.keys()

# .. note:: function keys() indicates that variables named U, nut and p have
#           been loaded. You can access them simply by typing for example mySimu.U
#           for the velocity field

mySimu.U
Reading file ../../output_samples/box//constant/polyMesh/owner
Reading file ../../output_samples/box//constant/polyMesh/faces
Reading file ../../output_samples/box//constant/polyMesh/points
Reading file ../../output_samples/box//constant/polyMesh/neighbour
Reading file ../../output_samples/box/4/nut
Reading file ../../output_samples/box//constant/polyMesh/owner
Reading file ../../output_samples/box//constant/polyMesh/faces
Reading file ../../output_samples/box//constant/polyMesh/points
Reading file ../../output_samples/box//constant/polyMesh/neighbour
Reading file ../../output_samples/box/4/p
Reading file ../../output_samples/box//constant/polyMesh/owner
Reading file ../../output_samples/box//constant/polyMesh/faces
Reading file ../../output_samples/box//constant/polyMesh/points
Reading file ../../output_samples/box//constant/polyMesh/neighbour
Reading file ../../output_samples/box/4/U
Reading file ../../output_samples/box//constant/polyMesh/owner
Reading file ../../output_samples/box//constant/polyMesh/faces
Reading file ../../output_samples/box//constant/polyMesh/points
Reading file ../../output_samples/box//constant/polyMesh/neighbour
Loaded available variables are :
['nut', 'p', 'U']

array([[[[ 3.18992e-02,  1.79405e-02,  1.85248e-02, ...,  2.07018e-02,
           2.18473e-02,  4.01484e-02],
         [ 5.45512e-02,  2.20373e-02,  3.37097e-02, ...,  3.63537e-02,
           3.65411e-02,  7.03408e-02],
         [ 9.64050e-02,  5.14858e-02,  6.60540e-02, ...,  7.79280e-02,
           8.04698e-02,  1.16315e-01],
         ...,
         [ 3.96455e-02,  5.08090e-02,  1.15117e-01, ...,  6.56267e-02,
           7.19338e-02,  4.01245e-02],
         [ 2.11214e-02,  3.61928e-02,  7.55611e-02, ...,  3.47472e-02,
           3.71378e-02,  2.26417e-02],
         [ 1.20526e-02,  1.23910e-02,  4.44112e-02, ...,  2.04318e-02,
           2.16031e-02,  1.34423e-02]],

        [[ 3.26646e-02,  2.00377e-02,  1.94394e-02, ...,  1.87730e-02,
           2.49159e-02,  3.52195e-02],
         [ 5.80944e-02,  2.46078e-02,  3.17509e-02, ...,  3.15628e-02,
           4.35643e-02,  6.52370e-02],
         [ 1.05022e-01,  6.52484e-02,  5.84404e-02, ...,  6.88878e-02,
           8.10161e-02,  1.19481e-01],
         ...,
         [ 3.87072e-02,  4.75148e-02,  1.17276e-01, ...,  6.59377e-02,
           7.26811e-02,  4.35011e-02],
         [ 2.10653e-02,  2.99974e-02,  7.03449e-02, ...,  3.41233e-02,
           3.69766e-02,  2.45663e-02],
         [ 1.23754e-02,  1.43732e-02,  3.77137e-02, ...,  2.01094e-02,
           2.26093e-02,  1.46607e-02]],

        [[ 3.16753e-02,  2.09653e-02,  1.87914e-02, ...,  1.90877e-02,
           2.41407e-02,  2.70096e-02],
         [ 5.62772e-02,  3.82019e-02,  3.03069e-02, ...,  3.11023e-02,
           4.60455e-02,  4.49955e-02],
         [ 1.04903e-01,  5.13360e-02,  5.04449e-02, ...,  5.33476e-02,
           8.86924e-02,  1.04078e-01],
         ...,
         [ 3.72512e-02,  5.42535e-02,  1.14961e-01, ...,  6.76110e-02,
           7.31055e-02,  4.58660e-02],
         [ 2.10945e-02,  2.67728e-02,  5.22082e-02, ...,  3.38472e-02,
           4.01594e-02,  2.47811e-02],
         [ 1.28640e-02,  1.59485e-02,  2.52787e-02, ...,  1.88499e-02,
           2.29339e-02,  1.42788e-02]],

        ...,

        [[ 2.10110e-02,  1.58239e-02,  1.71158e-02, ...,  1.93919e-02,
           2.18244e-02,  3.20522e-02],
         [ 3.32812e-02,  2.23170e-02,  3.11740e-02, ...,  3.43311e-02,
           4.73305e-02,  5.14514e-02],
         [ 5.47667e-02,  4.05091e-02,  6.10295e-02, ...,  6.81035e-02,
           8.04988e-02,  7.97360e-02],
         ...,
         [ 3.67845e-02,  5.27457e-02,  9.30992e-02, ...,  7.62478e-02,
           6.10209e-02,  3.17175e-02],
         [ 2.09944e-02,  2.74006e-02,  6.02779e-02, ...,  4.04399e-02,
           2.75262e-02,  1.82754e-02],
         [ 1.25483e-02,  1.55108e-02,  3.68839e-02, ...,  2.33335e-02,
           1.96690e-02,  1.04692e-02]],

        [[ 2.45636e-02,  1.52846e-02,  1.74154e-02, ...,  2.17054e-02,
           2.08747e-02,  3.60227e-02],
         [ 3.92183e-02,  2.07494e-02,  3.30393e-02, ...,  3.69546e-02,
           3.77244e-02,  6.03639e-02],
         [ 6.25909e-02,  3.91597e-02,  7.29379e-02, ...,  6.51149e-02,
           8.80845e-02,  8.50655e-02],
         ...,
         [ 3.75764e-02,  5.39175e-02,  1.00008e-01, ...,  7.48765e-02,
           6.36199e-02,  3.31145e-02],
         [ 2.23479e-02,  4.69155e-02,  7.06649e-02, ...,  3.67162e-02,
           2.82184e-02,  1.93503e-02],
         [ 1.37299e-02,  1.44704e-02,  4.15440e-02, ...,  2.15754e-02,
           1.95848e-02,  1.13547e-02]],

        [[ 2.85475e-02,  1.59666e-02,  1.80183e-02, ...,  2.29304e-02,
           2.03935e-02,  3.87283e-02],
         [ 4.92924e-02,  2.54433e-02,  3.42915e-02, ...,  3.97380e-02,
           3.39281e-02,  6.79486e-02],
         [ 7.63345e-02,  3.72513e-02,  7.51616e-02, ...,  7.20266e-02,
           8.53194e-02,  1.04755e-01],
         ...,
         [ 3.76133e-02,  8.87271e-02,  1.09970e-01, ...,  6.65887e-02,
           6.62168e-02,  3.58228e-02],
         [ 2.19142e-02,  4.24531e-02,  7.37609e-02, ...,  3.47382e-02,
           3.56335e-02,  2.01614e-02],
         [ 1.29698e-02,  1.21604e-02,  4.37596e-02, ...,  1.97192e-02,
           1.98143e-02,  1.18009e-02]]],


       [[[ 7.84279e-04,  5.47106e-04, -8.21631e-04, ..., -1.11664e-04,
           2.08206e-04, -5.19400e-04],
         [ 1.39026e-03,  9.00218e-04, -1.76744e-03, ..., -5.17103e-04,
           4.37167e-04, -1.43493e-03],
         [ 1.46458e-03,  2.79096e-03, -4.10754e-03, ..., -1.51365e-03,
          -1.64057e-03, -4.25778e-03],
         ...,
         [-1.56645e-03, -4.01416e-03,  3.25295e-03, ..., -1.62787e-03,
           7.39715e-05,  1.78847e-04],
         [-5.17724e-04, -9.69123e-04,  9.90531e-04, ..., -5.14880e-04,
          -1.14499e-04,  2.57391e-04],
         [-1.95333e-04, -5.23292e-04,  5.60509e-04, ..., -2.18410e-04,
          -4.90563e-05,  1.63185e-04]],

        [[ 4.44843e-04,  9.04593e-04, -1.15291e-03, ..., -4.36677e-04,
           5.50935e-04, -7.08876e-04],
         [ 7.25699e-04,  1.61511e-03, -1.91988e-03, ..., -7.77636e-04,
           1.13815e-03, -1.42614e-03],
         [ 9.08462e-04,  3.25245e-03, -4.42358e-03, ..., -1.65696e-03,
          -1.60247e-03, -3.86300e-03],
         ...,
         [-1.50284e-03, -2.00554e-03,  1.35983e-03, ..., -1.07225e-03,
           1.37933e-04, -4.74335e-04],
         [-4.18433e-04, -7.45759e-04,  4.91048e-04, ..., -4.87104e-04,
          -4.67593e-04, -8.59092e-05],
         [-1.31601e-04, -6.05762e-05,  2.79449e-04, ..., -3.00915e-04,
          -6.36434e-05, -1.90407e-05]],

        [[ 1.97729e-05,  8.08211e-04, -6.48533e-04, ..., -1.23010e-04,
           6.97042e-04, -4.93388e-04],
         [-4.20549e-05,  1.64312e-03, -1.17454e-03, ..., -8.63789e-05,
           1.18361e-03, -5.41687e-04],
         [-2.36747e-04,  4.12082e-03, -2.19435e-03, ..., -3.92024e-04,
          -1.83017e-03, -1.66362e-03],
         ...,
         [-1.81059e-03, -3.11806e-03,  4.82269e-04, ..., -1.68911e-04,
           4.22794e-04, -1.00459e-03],
         [-5.29763e-04, -1.00495e-03,  4.36633e-04, ..., -2.06172e-04,
           2.29263e-04, -4.10152e-04],
         [-1.89720e-04, -1.81242e-04,  3.18442e-04, ..., -1.69489e-04,
           4.02346e-05, -1.81635e-04]],

        ...,

        [[ 1.46079e-04, -8.25166e-04,  6.09599e-04, ..., -2.35004e-04,
           2.42891e-04, -7.51496e-05],
         [ 1.20524e-04, -3.11857e-04,  1.04892e-03, ..., -4.87344e-04,
           3.43499e-04, -6.75418e-04],
         [-2.78686e-04,  1.95781e-05,  1.39853e-03, ..., -8.46590e-04,
           9.31528e-04, -3.42571e-03],
         ...,
         [ 4.96518e-04, -3.48306e-03,  2.17695e-03, ...,  8.87406e-04,
          -5.75233e-04,  1.93982e-04],
         [ 4.16109e-04, -1.92033e-03,  9.48353e-04, ...,  3.12548e-04,
          -4.58189e-04,  1.26472e-04],
         [ 2.53736e-04, -6.88038e-04,  3.39592e-04, ...,  1.26221e-04,
          -1.58602e-04,  1.00377e-04]],

        [[ 6.19570e-04, -4.15901e-04,  2.07242e-04, ..., -3.77105e-04,
           1.09699e-04, -1.83479e-04],
         [ 1.13080e-03,  1.80459e-04,  2.04156e-04, ..., -7.53989e-04,
           4.09488e-04, -8.32334e-04],
         [ 1.16754e-03,  5.21672e-04, -7.78524e-04, ..., -1.55456e-03,
          -1.13852e-04, -3.89561e-03],
         ...,
         [-1.46650e-05, -6.04571e-03,  3.87313e-03, ...,  1.03792e-03,
          -6.57619e-04, -2.99752e-04],
         [ 6.11913e-05, -1.26989e-03,  1.73945e-03, ...,  2.74474e-04,
          -6.51257e-04,  4.25862e-05],
         [ 2.19103e-04, -1.16641e-03,  7.31279e-04, ...,  9.97285e-05,
          -3.03561e-04,  5.61145e-05]],

        [[ 6.65368e-04, -4.43151e-06, -2.01946e-04, ..., -1.33367e-04,
           2.22934e-05, -2.33348e-04],
         [ 1.32565e-03,  1.36880e-04, -6.54239e-04, ..., -3.98235e-04,
           2.00215e-04, -1.03888e-03],
         [ 1.06385e-03,  1.41124e-03, -1.67270e-03, ..., -1.44708e-03,
          -4.56157e-04, -3.82760e-03],
         ...,
         [-1.14635e-03, -2.81073e-03,  3.70703e-03, ...,  5.03686e-04,
          -3.10570e-04, -8.05578e-05],
         [-2.74711e-04, -1.71081e-03,  1.61273e-03, ..., -7.04135e-05,
          -2.20637e-04,  1.66443e-04],
         [-7.68263e-05, -1.18094e-03,  6.73337e-04, ...,  4.97206e-05,
          -1.69600e-04,  1.08526e-04]]],


       [[[ 6.63459e-03, -3.37437e-03, -3.35515e-03, ..., -9.49669e-04,
          -2.68579e-03,  6.50514e-03],
         [ 9.12968e-03, -7.22581e-03, -4.24501e-03, ..., -1.74703e-03,
          -3.16699e-03,  7.67820e-03],
         [ 7.71626e-03, -5.52429e-03, -5.33153e-03, ..., -5.28505e-03,
          -4.05202e-03,  2.99451e-04],
         ...,
         [ 6.25965e-04, -1.46304e-02, -1.00215e-02, ...,  1.30336e-02,
           1.25806e-02,  2.51707e-03],
         [ 1.05628e-03, -1.25478e-02, -6.49182e-03, ...,  8.77716e-03,
           8.51097e-03,  9.86680e-04],
         [ 8.46178e-04, -5.89148e-03, -4.56450e-03, ...,  5.49236e-03,
           5.21531e-03,  6.13888e-04]],

        [[ 9.18522e-03, -3.34208e-04, -2.39649e-03, ...,  3.60521e-04,
          -5.05526e-03,  5.14981e-03],
         [ 1.26161e-02, -2.14244e-03, -2.56397e-03, ...,  3.53038e-04,
          -6.92290e-03,  6.06733e-03],
         [ 1.33491e-02,  2.36725e-03, -2.92752e-03, ..., -3.35320e-03,
          -2.51424e-03,  5.33454e-03],
         ...,
         [ 6.41317e-04, -1.11011e-02, -7.15145e-03, ...,  1.18647e-02,
           1.32795e-02,  1.04717e-03],
         [ 4.36028e-05, -8.66245e-03, -5.07126e-03, ...,  4.11300e-03,
           5.72037e-03,  6.54708e-04],
         [-4.09412e-04, -4.54788e-03, -3.41828e-03, ...,  2.83627e-03,
           4.41921e-03,  1.58301e-04]],

        [[ 8.31052e-03,  4.22921e-03, -2.25483e-03, ...,  1.62446e-03,
          -8.43620e-03,  4.50279e-03],
         [ 1.12922e-02,  7.32371e-03, -2.67745e-03, ...,  9.30869e-04,
          -1.05722e-02,  6.20631e-03],
         [ 1.51287e-02,  7.26134e-03, -2.06695e-03, ..., -6.27430e-04,
          -3.00904e-03,  3.32246e-03],
         ...,
         [ 3.06024e-03, -1.37916e-02, -5.65459e-03, ...,  9.70211e-03,
           1.33434e-02,  3.95776e-03],
         [ 8.89846e-04, -9.20753e-03, -5.94054e-03, ...,  2.57700e-03,
           6.30693e-03,  3.13410e-03],
         [ 2.43406e-04, -3.55492e-03, -4.87791e-03, ...,  1.14833e-03,
           3.77411e-03,  1.79569e-03]],

        ...,

        [[-3.61441e-03,  5.61957e-04, -1.76350e-03, ..., -3.86098e-03,
          -7.64555e-04, -1.81228e-03],
         [-5.77974e-03,  3.37529e-03, -2.58588e-03, ..., -5.50819e-03,
          -5.59090e-03, -6.50543e-03],
         [-1.03968e-02,  2.45157e-03,  1.56374e-03, ..., -8.25061e-03,
          -1.14900e-02, -1.65243e-02],
         ...,
         [ 1.58778e-03, -6.07027e-03, -1.43842e-02, ..., -6.30615e-04,
           4.46550e-03,  2.52009e-03],
         [ 1.97764e-03, -4.89974e-03, -5.45858e-03, ...,  1.29130e-03,
           3.02918e-03,  1.56723e-03],
         [ 1.81484e-03, -1.97926e-03, -3.17147e-03, ...,  1.43749e-03,
           3.16560e-03,  1.32316e-03]],

        [[ 4.75758e-04, -9.07907e-04, -4.15461e-03, ..., -2.57788e-03,
          -8.36229e-04,  4.90096e-03],
         [ 1.58048e-04, -1.19511e-03, -5.86699e-03, ..., -3.95150e-03,
          -2.93053e-03,  2.74922e-03],
         [-4.47718e-03, -1.55299e-03, -6.32151e-03, ..., -5.88115e-03,
          -1.04109e-02, -1.16235e-02],
         ...,
         [ 7.47676e-05, -1.12330e-02, -6.18615e-03, ...,  8.57690e-04,
           7.60502e-03,  2.27585e-03],
         [ 2.03538e-03, -1.20773e-02, -5.51093e-03, ...,  5.80025e-03,
           4.67897e-03,  1.90197e-03],
         [ 2.04935e-03, -3.69004e-03, -3.95621e-03, ...,  3.49550e-03,
           4.45277e-03,  1.03283e-03]],

        [[ 3.08374e-03, -2.43060e-03, -4.58880e-03, ..., -1.95476e-03,
          -1.10620e-03,  7.17587e-03],
         [ 5.43264e-03, -3.69010e-03, -6.30989e-03, ..., -3.34521e-03,
          -1.40561e-03,  7.79084e-03],
         [-3.47941e-04, -7.73706e-03, -8.57942e-03, ..., -4.39765e-03,
          -6.43783e-03, -4.53129e-03],
         ...,
         [ 5.35697e-04, -1.75389e-02, -5.19963e-03, ...,  9.27936e-03,
           1.02390e-02,  3.56798e-03],
         [ 2.43026e-03, -1.46963e-02, -7.67725e-03, ...,  9.30935e-03,
           8.80783e-03,  1.99104e-03],
         [ 2.36526e-03, -5.37717e-03, -5.44804e-03, ...,  5.87688e-03,
           5.58616e-03,  1.34276e-03]]]])

Averaging along x and z axis (1 and 3)

import numpy as np

mySimu.vel_averaged = np.mean(np.mean(mySimu.U, 3), 1)

Now plot the profile of the averaged first velocity component

import matplotlib.pyplot as plt

plt.figure()
plt.plot(mySimu.vel_averaged[0], mySimu.y[0, :, 0])

#Setting axis labels
plt.xlabel('U (m/s)')
plt.ylabel('y (m)')

# add grid
plt.grid()

# show figure
plt.show()
plot using openfoamsimu

Total running time of the script: (0 minutes 3.015 seconds)

Gallery generated by Sphinx-Gallery