Skip to content

Commit

Permalink
Merge branch 'master' of github.com:fluiddyn/fluidfoam
Browse files Browse the repository at this point in the history
  • Loading branch information
CyrilleBonamy committed Jan 8, 2023
2 parents 37b632e + 3adfed1 commit 95dc3b5
Show file tree
Hide file tree
Showing 36 changed files with 755 additions and 81 deletions.
11 changes: 2 additions & 9 deletions .github/workflows/build_and_pypi.yml
Expand Up @@ -12,7 +12,7 @@ jobs:
version_changed: ${{ steps.check_file_changed.outputs.files_changed }}
steps:
- run: pip install -U pip pipenv coverage
- run: pip install -U numpy==1.21.2 scipy==1.7.3 matplotlib
- run: pip install -U numpy scipy matplotlib
- name: Check out repository code
uses: actions/checkout@v2
- run: set -o pipefail
Expand All @@ -35,19 +35,12 @@ jobs:
Publish-Pypi:
needs: build
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master'
if: startsWith(github.event.ref, 'refs/tags')
steps:
- name: Check out repository code
uses: actions/checkout@v2
- uses: actions/setup-python@v2
# - uses: dorny/paths-filter@v2
# id: changes
# with:
# filters: |
# src:
# - 'fluidfoam/_version.py'
- name: Deploy package
# if: steps.changes.outputs.src == 'true'
uses: casperdcl/deploy-pypi@v2
with:
password: ${{ secrets.PYPI_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build_and_test.yml
Expand Up @@ -12,7 +12,7 @@ jobs:
version_changed: ${{ steps.check_file_changed.outputs.files_changed }}
steps:
- run: pip install -U pip pipenv coverage
- run: pip install -U numpy==1.21.2 scipy==1.7.3 matplotlib
- run: pip install -U numpy scipy matplotlib
- name: Check out repository code
uses: actions/checkout@v2
- run: set -o pipefail
Expand Down
2 changes: 1 addition & 1 deletion .readthedocs.yml
Expand Up @@ -18,7 +18,7 @@ formats: all

# Optionally set the version of Python and requirements required to build your docs
python:
version: 3.7
version: 3.8
install:
- requirements: doc/requirements.txt
- method: setuptools
Expand Down
4 changes: 2 additions & 2 deletions README.rst
Expand Up @@ -26,8 +26,8 @@ What is this repository for?
----------------------------

* Openfoam Tools
* Version : 0.2.3
* Supported OpenFoam Versions : 2.4.0, 4.1 to 9, v1712plus to v2112plus
* Version : 0.2.4
* Supported OpenFoam Versions : 2.4.0, 4.1 to 9, v1712plus to v2212plus
* Supported Python Versions : >= 3.8

Documentation and Examples
Expand Down
2 changes: 1 addition & 1 deletion dev-requirements.txt
@@ -1,4 +1,4 @@
numpy>=1.11
scipy==1.7.3
scipy>=1.7.3
matplotlib>=1.5
wheel
6 changes: 3 additions & 3 deletions doc/index.rst
Expand Up @@ -13,9 +13,9 @@ What is this repository for?
----------------------------

* Openfoam Tools
* Version : 0.2.3
* Supported OpenFoam Versions : 2.4.0, 4.1 to 9, v1712plus to v2112plus
* Supported Python Versions : >= 3.7
* Version : 0.2.4
* Supported OpenFoam Versions : 2.4.0, 4.1 to 9, v1712plus to v2212plus
* Supported Python Versions : >= 3.8

Deployment instructions
-----------------------
Expand Down
49 changes: 49 additions & 0 deletions examples/advanced/generateDFSEMdata.py
@@ -0,0 +1,49 @@
"""
Create and plot boundaryData for DFSEM from a 1D RANS simulation
=======================================
This example shows how to create a boundary data for turbulentDFSEM
inlet boundary condition. In addition, the script also plots the
profiles for verification.
"""

from fluidfoam import create1dprofilDFSEM, read1dprofilDFSEM
import os

basepath = "../../output_samples//DFSEM/"

case3d = "3D/"
case1d = "1D/"

sol1d = os.path.join(basepath, case1d)
sol3d = os.path.join(basepath, case3d)

boundary_name = "inlet/"
axis = "Y"

create1dprofilDFSEM(sol1d, sol3d, boundary_name, "200", axis,
"U","k","omega","turbulenceProperties:R","Y")
# if turbulenceProperties:R does not exist type:
# "pimpleFoam -postProcess -func R -time 200"
# in a terminal

Y, U, L, R, ny = read1dprofilDFSEM(sol3d, boundary_name, "0", axis)

import matplotlib.pyplot as plt

dummy, axarr = plt.subplots(1, 3, sharey=True)
axarr[0].set_ylabel("Y (m)")

axarr[0].plot(U[:], Y)
axarr[0].set_title("U")
axarr[0].set_xlabel("U (m/s)")

axarr[1].plot(L[:], Y)
axarr[1].set_title("L")
axarr[1].set_xlabel("L (m)")

axarr[2].plot(R[:,1], Y)
axarr[2].set_title("R")
axarr[2].set_xlabel(r"R ($m^2/s^2$)")

plt.show()
147 changes: 147 additions & 0 deletions examples/advanced/plot_unstructured_simu.py
@@ -0,0 +1,147 @@
"""
Plot bed interface from unstructured mesh
=======================================
This example shows how to create a pointer list of profiles from an
unstructured mesh and to extract the bed interface elevation. The
results are plotted as a scatter plot.
"""

###############################################################################

#path where the simulation is located
path = '../../output_samples'
#Name of the simulation to load
simu = '3dscour'
#time step to load
timeStep = '0'
#Switch to save postprocessed data on output
saveOutput = 1

###############################################################################
# Read the mesh and extract the pointerList
# --------------------------------------
#
# import python packages
from fluidfoam import readmesh,readfield
import os
import numpy as np
#
#---read mesh (in folder constant, if not done type writeCellCenters -time constant in a terminal)
#
sol = os.path.join(path, simu)
Xb, Yb, Zb = readfield(sol, 'constant', 'C', precision=12)
#
#---create a list of (x,y) positions correpsonding to Zb = min(Zb)
#
print("Generate pointer list")
pbed = np.where(Zb == np.amin(Zb))[0]

n2d = np.size(pbed)
nz = 0
profileList = []
for i in range(n2d):
#Extract the list of points having the same (Xb, Yb) values
indices = np.where(np.logical_and(Xb == Xb[pbed[i]],
Yb == Yb[pbed[i]]))[0]
nz = max(nz, np.size(indices))
profile = list(indices)
#Sort the list of points by increasing Zb values (profile)
profileSorted = [x for _, x in sorted(zip(Zb[profile], profile))]
#Append the list to the profileList
profileList.append(profileSorted)

# Convert profileList to numpy.array
pointer = np.array(profileList)

###############################################################################
# Extract bed surface from alpha.a profiles: min{ Zb | alpha.a <= 0.57 }
# --------------------------------------------------------------
#
print("Extract bed surface")
a = readfield(sol, timeStep, 'alpha.a')

zbed = np.zeros(n2d)
for i in range(n2d):
bed_surface=np.where(a[pointer[i,:]] <= 0.57)[0]
zbed[i] = np.min(Zb[pointer[i,bed_surface]])

###############################################################################
# Now plot the zbed elevation
# --------------------------------------------------------------
#
import matplotlib.pyplot as plt

D = 0.1
zmin = np.min([np.min(zbed), -np.max(zbed)])
zmax = np.max([-np.min(zbed), np.max(zbed)])
zlevels = np.linspace(zmin, zmax, 51)

plt.figure()
plt.scatter(Xb[pbed]/D, Yb[pbed]/D, c=zbed,
vmin=zmin, vmax=zmax, cmap = 'seismic')
plt.colorbar()

#Setting axis labels
plt.xlabel('x/D')
plt.ylabel('y/D')

# add grid
plt.grid()

# show figure
plt.show()


###############################################################################
# save NetCDF files in constant and timeStep folders
# --------------------------------------
#
if saveOutput == 1:
from netCDF4 import Dataset

postProcFile = os.path.join(sol, 'constant/pointerpostproc.nc')
print ("save postprocFile in:",postProcFile)

# NetCDF file creation
rootgrp = Dataset(postProcFile, 'w')

# Dimensions creation
rootgrp.createDimension('XY', n2d)
rootgrp.createDimension('Z', nz)

# Variables creation
pb_file = rootgrp.createVariable('pbed', np.int64, 'XY')
x_file = rootgrp.createVariable('x', np.float64, 'XY')
y_file = rootgrp.createVariable('y', np.float64, 'XY')
z_file = rootgrp.createVariable('z', np.float64, ('XY','Z'))
p_file = rootgrp.createVariable('p', np.int64, ('XY','Z'))

# Writing variables
pb_file[:] = pbed
x_file[:] = Xb[pbed]
y_file[:] = Yb[pbed]
z_file[:,:] = Zb[pointer[:,:]]
p_file[:,:] = pointer[:,:]

# File closing
rootgrp.close()

postProcFile2 = os.path.join(sol, timeStep, 'zbed.nc')
print ("save zbed file in:",postProcFile2)

# NetCDF file creation
rootgrp = Dataset(postProcFile2, 'w')

# Dimensions creation
rootgrp.createDimension('XY', n2d)
rootgrp.createDimension('Z', nz)

# Variables creation
zb_file = rootgrp.createVariable('zbed', np.float64, 'XY')

# Writing variables
zb_file[:] = zbed

# File closing
rootgrp.close()
4 changes: 2 additions & 2 deletions examples/plot_3_postprocprobe.py
Expand Up @@ -18,8 +18,8 @@
sol = '../output_samples/ascii/'

# import readprobes function from fluidfoam package
timeU, u = readprobes(sol, time_name = 'mergeTime', name = 'U')
timeP, p = readprobes(sol, time_name = 'mergeTime', name = 'p')
probes_locU, timeU, u = readprobes(sol, time_name = 'mergeTime', name = 'U')
probes_locP, timeP, p = readprobes(sol, time_name = 'mergeTime', name = 'p')

###############################################################################
# Now plots the pressure and y velocity for the first probe
Expand Down
1 change: 1 addition & 0 deletions fluidfoam/__init__.py
Expand Up @@ -5,6 +5,7 @@
from fluidfoam.readof import typefield, OpenFoamFile
from fluidfoam.processing1d import create1dprofil, read1dprofil
from fluidfoam.processing1d import create1dprofil_spe, plot1dprofil
from fluidfoam.processing1d import create1dprofilDFSEM, read1dprofilDFSEM
from fluidfoam.meshdesign import getgz, getdzs
from fluidfoam.readpostpro import readforce, readprobes
from fluidfoam.meshvisu import MeshVisu
Expand Down
2 changes: 1 addition & 1 deletion fluidfoam/_version.py
Expand Up @@ -11,4 +11,4 @@
'a' or 'alpha' means alpha version (internal testing),
'b' or 'beta' means beta version (external testing).
"""
__version__ = "0.2.3"
__version__ = "0.2.4"

0 comments on commit 95dc3b5

Please sign in to comment.