Skip to content

Commit 5ad5fec

Browse files
Initial GitHub commit. Previously, BitBucket
0 parents  commit 5ad5fec

26 files changed

Lines changed: 1370 additions & 0 deletions

Allwclean

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
cd ${0%/*} || exit 1 # Run from this directory
3+
4+
# Clean solvers
5+
wclean applications/solvers/pythonPalIcoFoam
6+
7+
# Clean tutorials
8+
(cd tutorials && ./Allclean)
9+
10+
#------------------------------------------------------------------------------

Allwmake

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
cd ${0%/*} || exit 1 # run from this directory
3+
4+
# Stop at first error
5+
set -e
6+
7+
# Check if OpenFOAM/FOAM has been sourced
8+
if [[ -z "${WM_PROJECT}" ]]
9+
then
10+
echo "Please source the OpenFOAM/FOAM bashrc first!"
11+
exit 1
12+
fi
13+
14+
# Check required environment variaables are set
15+
if [[ -z "${PYBIND11_INC_DIR}" ]]
16+
then
17+
echo "Please set the PYBIND11_INC_DIR environment variable!"
18+
exit 1
19+
fi
20+
if [[ -z "${PYBIND11_LIB_DIR}" ]]
21+
then
22+
echo "Please set the PYBIND11_LIB_DIR environment variable!"
23+
exit 1
24+
fi
25+
26+
# Compile solvers
27+
echo; echo "Compiling applications"; echo
28+
(cd applications && ./Allwmake)
29+
30+
echo; echo; echo "All done: check for errors above"; echo

README.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# README #
2+
3+
### What is this? ###
4+
5+
This section contains OpenFOAM code and tutorials that show how to use Python interpreters to interact with OpenFOAM via pythonPal. pythonPal offers Python support and interoperability between the C++/Python data based on the pybind11 library [1]. The code in this repository is based on OpenFOAM-9, however, as noted below, the procedures are expected to compile with similar versions and forks of OpenFOAM.
6+
7+
### [Manual approach] How do I get set up? ###
8+
9+
In addition to an installation of OpenFOAM-9, a Python installation is required. The following libraries are required to run the tutorials:
10+
11+
* Python 3.8.12
12+
13+
* NumPy 1.18.5
14+
15+
* pybind11 2.8.1
16+
17+
These libraries can be installed from the supplied pythonpal-no-gpu.yml file using the conda software (https://conda.io). Once conda is installed, the Python environment is installed with:
18+
19+
conda env create -f pythonPal-no-gpu.yml
20+
21+
The conda environment can be activated with:
22+
23+
conda activate pythonPal-no-gpu
24+
25+
Please be aware that the examples may not work with other versions of Python libraries, although they are likely to work with similar versions, e.g. Python 3.8.*.
26+
27+
In addition, two pybind11 environment variables must be defined, for example, as:
28+
29+
export PYBIND11_INC_DIR=$(python3 -m pybind11 --includes)
30+
export PYBIND11_LIB_DIR=$(python3 -c 'from distutils import sysconfig; print(sysconfig.get_config_var("LIBDIR"))')
31+
32+
Once those environment variables have been defined, the OpenFOAM code included in the current section can be compiled with the Allwmake script in the parent folder:
33+
34+
./Allwmake
35+
36+
If the Allwmake script gives the error “libpython or lpython not found” then please manually update the LD_LIBRARY_PATH environment variable with "export LD_LIBRARY_PATH=$PYBIND11_LIB_DIR:$LD_LIBRARY_PATH” and run the “./Allwmake” command again.
37+
38+
This will install:
39+
40+
**./applications/solvers/**:
41+
42+
* pythonPalIcoFoam: This is a version of icoFoam that, once the simulation has converged, passes the velocity field to Python where the specific kinetic energy (k) is calculated. Then, OpenFOAM prints the k field.
43+
44+
### How do I run the cases? ###
45+
46+
Currently, there is only one tutorial case which solves the cavity case using pythonPalIcoFoam, as explained in the paper. To run it:
47+
48+
cd tutorials/pythonPalIcoFoam/cavity
49+
./Allrun
50+
51+
### Compatible OpenFOAM versions ###
52+
53+
pythonPal is independent of the OpenFOAM version/fork and is expected to work with all main versions. The included code compiles with the following versions and forks (it will probably work with others too):
54+
55+
* OpenFOAM-9
56+
* OpenFOAM-v2012
57+
* foam-extend-4.1
58+
59+
The presented tutorial has been tested using these three versions.
60+
61+
If desired, the user can make the small changes required to get the cases to work with their particular version of OpenFOAM.
62+
63+
64+
### Who do I talk to? ###
65+
66+
Simon Rodriguez
67+
simon.rodriguezluzardo@ucdconnect.ie
68+
https://www.linkedin.com/in/simonrodriguezl/
69+
70+
Philip Cardiff
71+
philip.cardiff@ucd.ie
72+
https://www.linkedin.com/in/philipcardiff/
73+
74+
75+
### References ###
76+
77+
[1] W. Jakob, J. Rhinelander, and D. Moldovan, “pybind11 – Seamless operability between C++11 and Python.” 2017.

applications/Allwmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
cd ${0%/*} || exit 1 # run from this directory
3+
4+
wmake all solvers
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pythonPalIcoFoam.C
2+
3+
EXE = $(FOAM_USER_APPBIN)/pythonPalIcoFoam
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
ifeq ($(WM_PROJECT), foam)
2+
VERSION_SPECIFIC_INC = -DFOAMEXTEND
3+
else
4+
ifneq (,$(findstring v,$(WM_PROJECT_VERSION)))
5+
VERSION_SPECIFIC_INC += -DOPENFOAMESI
6+
else
7+
VERSION_SPECIFIC_INC += -DOPENFOAMFOUNDATION
8+
endif
9+
endif
10+
11+
EXE_INC = \
12+
-Wno-old-style-cast \
13+
$(VERSION_SPECIFIC_INC) \
14+
-I$(LIB_SRC)/finiteVolume/lnInclude \
15+
-I$(LIB_SRC)/meshTools/lnInclude \
16+
$(PYBIND11_INC_DIR) \
17+
-I../../../src/pythonPal
18+
19+
EXE_LIBS = \
20+
-lfiniteVolume \
21+
-lmeshTools \
22+
-L$(PYBIND11_LIB_DIR) \
23+
-lpython3.8
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
Info<< "Reading transportProperties\n" << endl;
2+
3+
IOdictionary transportProperties
4+
(
5+
IOobject
6+
(
7+
"transportProperties",
8+
runTime.constant(),
9+
mesh,
10+
IOobject::MUST_READ_IF_MODIFIED,
11+
IOobject::NO_WRITE
12+
)
13+
);
14+
15+
dimensionedScalar nu
16+
(
17+
"nu",
18+
dimViscosity,
19+
transportProperties
20+
);
21+
22+
Info<< "Reading field p\n" << endl;
23+
volScalarField p
24+
(
25+
IOobject
26+
(
27+
"p",
28+
runTime.timeName(),
29+
mesh,
30+
IOobject::MUST_READ,
31+
IOobject::AUTO_WRITE
32+
),
33+
mesh
34+
);
35+
36+
37+
Info<< "Reading field U\n" << endl;
38+
volVectorField U
39+
(
40+
IOobject
41+
(
42+
"U",
43+
runTime.timeName(),
44+
mesh,
45+
IOobject::MUST_READ,
46+
IOobject::AUTO_WRITE
47+
),
48+
mesh
49+
);
50+
51+
52+
volScalarField k
53+
(
54+
IOobject
55+
(
56+
"k",
57+
mesh.time().timeName(),
58+
mesh,
59+
IOobject::READ_IF_PRESENT,
60+
IOobject::AUTO_WRITE
61+
),
62+
mesh,
63+
dimensionedScalar("k", dimensionSet(0, 2, -2, 0, 0, 0, 0), 0.0)
64+
);
65+
66+
67+
#include "createPhi.H"
68+
69+
70+
label pRefCell = 0;
71+
scalar pRefValue = 0.0;
72+
setRefCell(p, mesh.solutionDict().subDict("PISO"), pRefCell, pRefValue);
73+
mesh.setFluxRequired(p.name());
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
Info<< "Reading transportProperties\n" << endl;
2+
3+
IOdictionary transportProperties
4+
(
5+
IOobject
6+
(
7+
"transportProperties",
8+
runTime.constant(),
9+
mesh,
10+
IOobject::MUST_READ_IF_MODIFIED,
11+
IOobject::NO_WRITE
12+
)
13+
);
14+
15+
dimensionedScalar nu
16+
(
17+
transportProperties.lookup("nu")
18+
);
19+
20+
Info<< "Reading field p\n" << endl;
21+
volScalarField p
22+
(
23+
IOobject
24+
(
25+
"p",
26+
runTime.timeName(),
27+
mesh,
28+
IOobject::MUST_READ,
29+
IOobject::AUTO_WRITE
30+
),
31+
mesh
32+
);
33+
34+
35+
Info<< "Reading field U\n" << endl;
36+
volVectorField U
37+
(
38+
IOobject
39+
(
40+
"U",
41+
runTime.timeName(),
42+
mesh,
43+
IOobject::MUST_READ,
44+
IOobject::AUTO_WRITE
45+
),
46+
mesh
47+
);
48+
49+
50+
volScalarField k
51+
(
52+
IOobject
53+
(
54+
"k",
55+
mesh.time().timeName(),
56+
mesh,
57+
IOobject::READ_IF_PRESENT,
58+
IOobject::AUTO_WRITE
59+
),
60+
mesh,
61+
dimensionedScalar("k", dimensionSet(0, 2, -2, 0, 0, 0, 0), 0.0)
62+
);
63+
64+
65+
#include "createPhi.H"
66+
67+
68+
label pRefCell = 0;
69+
scalar pRefValue = 0.0;
70+
setRefCell(p, piso.dict(), pRefCell, pRefValue);
71+
mesh.schemesDict().setFluxRequired(p.name());
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
Info<< "Reading transportProperties\n" << endl;
2+
3+
IOdictionary transportProperties
4+
(
5+
IOobject
6+
(
7+
"transportProperties",
8+
runTime.constant(),
9+
mesh,
10+
IOobject::MUST_READ_IF_MODIFIED,
11+
IOobject::NO_WRITE
12+
)
13+
);
14+
15+
dimensionedScalar nu
16+
(
17+
"nu",
18+
dimViscosity,
19+
transportProperties.lookup("nu")
20+
);
21+
22+
Info<< "Reading field p\n" << endl;
23+
volScalarField p
24+
(
25+
IOobject
26+
(
27+
"p",
28+
runTime.timeName(),
29+
mesh,
30+
IOobject::MUST_READ,
31+
IOobject::AUTO_WRITE
32+
),
33+
mesh
34+
);
35+
36+
37+
Info<< "Reading field U\n" << endl;
38+
volVectorField U
39+
(
40+
IOobject
41+
(
42+
"U",
43+
runTime.timeName(),
44+
mesh,
45+
IOobject::MUST_READ,
46+
IOobject::AUTO_WRITE
47+
),
48+
mesh
49+
);
50+
51+
52+
volScalarField k
53+
(
54+
IOobject
55+
(
56+
"k",
57+
mesh.time().timeName(),
58+
mesh,
59+
IOobject::READ_IF_PRESENT,
60+
IOobject::AUTO_WRITE
61+
),
62+
mesh,
63+
dimensionedScalar("k", dimensionSet(0, 2, -2, 0, 0, 0, 0), 0.0)
64+
);
65+
66+
67+
#include "createPhi.H"
68+
69+
70+
label pRefCell = 0;
71+
scalar pRefValue = 0.0;
72+
setRefCell(p, mesh.solutionDict().subDict("PISO"), pRefCell, pRefValue);
73+
mesh.setFluxRequired(p.name());
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#ifdef OPENFOAMFOUNDATION
2+
#include "pythonPalIcoFoam.foundation.C"
3+
#elif OPENFOAMESI
4+
#include "pythonPalIcoFoam.esi.C"
5+
#else
6+
#include "pythonPalIcoFoam.foamextend.C"
7+
#endif

0 commit comments

Comments
 (0)