Skip to content
This repository has been archived by the owner on Apr 23, 2021. It is now read-only.

Commit

Permalink
Integration OpenFoam wrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
jmarcelogimenez committed May 14, 2015
1 parent 13e2f48 commit 03a2385
Show file tree
Hide file tree
Showing 73 changed files with 133,161 additions and 14 deletions.
24 changes: 24 additions & 0 deletions Allwclean
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash
python setup.py clean
rm -rf dist build foam_wrappers.egg-info
pushd .
cd openfoam-interface
wclean
rm -rf build
popd
pushd .
cd openfoam-interface/internal-interface/libs
wclean incompressibleTurbulenceModel/turbulenceModel
wclean incompressibleTurbulenceModel/RAS
#wclean incompressibleTurbulenceModel/LES
rm -rf incompressibleTurbulenceModel
popd
pushd .
cd openfoam-interface/internal-interface/wrapper
python setup.py clean
wclean
rm -rf build
popd
find . -iname "*~" | xargs rm -f
find . -iname "log" | xargs rm -f
find . -iname "*pyc" | xargs rm -f
5 changes: 5 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@ Release 0.1.1

* Surface tension setup fixed (#21)

Release 0.1.2
-------------

* Internal Interfaces wrapper added (#21)

This comment has been minimized.

Copy link
@khiltunen

khiltunen May 18, 2015

Contributor

Here the issue number should be #23

This comment has been minimized.

Copy link
@jmarcelogimenez

jmarcelogimenez May 18, 2015

Author Contributor

Fixed


6 changes: 5 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ Simphony-openfoam is hosted on github: https://github.com/simphony/simphony-open
Installation
------------

Package foam_controlwrapper requires python 2.7.x, OpenFOAM 2.2.x and pyFoam 0.6.4
Package foam_controlwrapper requires python 2.7.x, OpenFOAM 2.2.2 and pyFoam 0.6.4

Installing the OpenFoam interface wrappers
$ ./install_foam_interface.sh

This comment has been minimized.

Copy link
@khiltunen

khiltunen May 18, 2015

Contributor

Maybe it is better to use bash shell here (while the script uses pushd which is not found in sh for example)

This comment has been minimized.

Copy link
@jmarcelogimenez

jmarcelogimenez May 18, 2015

Author Contributor

Fixed


Installation is based on setuptools::

# build and install
Expand All @@ -42,3 +45,4 @@ Subpackages:


- foam_controlwrapper -- wrapper class and tests for OpenFOAM -wrapping using pyFoam

This comment has been minimized.

Copy link
@khiltunen

khiltunen May 18, 2015

Contributor

Ths would be better to change

  • foam_controlwrapper -- wrapper class and tests for OpenFOAM using IO wrapping

This comment has been minimized.

Copy link
@jmarcelogimenez

jmarcelogimenez May 18, 2015

Author Contributor

Modified

- foam_internalwrapper -- wrapper class and tests for OpenFOAM -wrapping using internal interfaces
6 changes: 3 additions & 3 deletions foam_controlwrapper/examples/poiseuille.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
"""

from simphony.core.cuba import CUBA
from simphony.engine import openfoam
from simphony.engine import openfoam_file_io
from simphony.io.h5_cuds import H5CUDS
import os

wrapper = openfoam.FoamControlWrapper()
CUBAExt = openfoam.CUBAExt
wrapper = openfoam_file_io.FoamControlWrapper()
CUBAExt = openfoam_file_io.CUBAExt

name = 'poiseuille'

Expand Down
6 changes: 3 additions & 3 deletions foam_controlwrapper/examples/poiseuille_vof.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
"""

from simphony.core.cuba import CUBA
from simphony.engine import openfoam
from simphony.engine import openfoam_file_io
from simphony.io.h5_cuds import H5CUDS
import os

wrapper = openfoam.FoamControlWrapper()
CUBAExt = openfoam.CUBAExt
wrapper = openfoam_file_io.FoamControlWrapper()
CUBAExt = openfoam_file_io.CUBAExt

name = 'poiseuille_vof'

Expand Down
4 changes: 2 additions & 2 deletions foam_controlwrapper/tests/test_plugin_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ def test_plugin_integration(self):
"""

# Assert that we can import the openfoam plugin
from simphony.engine import openfoam
from simphony.engine import openfoam_file_io

# Check that the expected top level objects are available
self.assertTrue(hasattr(openfoam, 'FoamControlWrapper'))
self.assertTrue(hasattr(openfoam_file_io, 'FoamControlWrapper'))


if __name__ == '__main__':
Expand Down
5 changes: 5 additions & 0 deletions foam_internalwrapper/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Functions, classes and constants exported here will be available
# when the `openfoam` module is imported.
from .foam_internalwrapper import FoamInternalWrapper
from .cuba_extension import CUBAExt
__all__ = ['FoamInternalWrapper', 'CUBAExt']
20 changes: 20 additions & 0 deletions foam_internalwrapper/cuba_extension.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
""" Provisional CUBA keywords specific for this revision
"""

from enum import IntEnum, unique


@unique
class CUBAExt(IntEnum):

INCOMPRESSIBLE = 1
COMPRESSIBLE = 2
VOF = 3
LAMINAR_MODEL = 4
GE = 5
PATCH_TYPE = 6
PHASE_LIST = 7
MAX_COURANT_NUMBER = 8
SURFACE_TENSION = 9
NUMBER_OF_CORES = 10
14 changes: 14 additions & 0 deletions foam_internalwrapper/examples/foam_mesh_to_h5cuds.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""Example to convert mesh from OpenFoam's format to H5CUDS
"""

from foam_controlwrapper.foam_controlwrapper import FoamControlWrapper

This comment has been minimized.

Copy link
@khiltunen

khiltunen May 18, 2015

Contributor

Is it possible to use internal wrapper here ? If not then this should be removed from the package (and the needed foam files under poiseuille directory).

This comment has been minimized.

Copy link
@jmarcelogimenez

jmarcelogimenez May 18, 2015

Author Contributor

Unneeded files were deleted.

from simphony.io.h5_cuds import H5CUDS

foam_controlwrapper = FoamControlWrapper()
name = 'poiseuille'
path = '.'
mesh_inside_wrapper = foam_controlwrapper.read_foammesh(name, path)
mesh_file = H5CUDS.open("poiseuille.cuds")
print 'Adding mesh ', mesh_inside_wrapper.name
mesh_file.add_mesh(mesh_inside_wrapper)
63 changes: 63 additions & 0 deletions foam_internalwrapper/examples/poiseuille.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
"""Example to solve 2D poiseuille flow
"""

from simphony.core.cuba import CUBA
from simphony.engine import openfoam_internal
from simphony.io.h5_cuds import H5CUDS
import os

# Only for postprocessing purposes
import matplotlib.pyplot as plt

wrapper = openfoam_internal.FoamInternalWrapper()
CUBAExt = openfoam_internal.CUBAExt

name = 'poiseuille'

wrapper.CM[CUBA.NAME] = name

wrapper.CM_extensions[CUBAExt.GE] = (CUBAExt.INCOMPRESSIBLE,
CUBAExt.LAMINAR_MODEL)

wrapper.CM_extensions[CUBAExt.NUMBER_OF_CORES] = 1

wrapper.SP[CUBA.TIME_STEP] = 1
wrapper.SP[CUBA.NUMBER_OF_TIME_STEPS] = 1000
wrapper.SP[CUBA.DENSITY] = 1.0
wrapper.SP[CUBA.DYNAMIC_VISCOSITY] = 1.0

# this is just an example. It is not enough for general setting of BC's
wrapper.BC[CUBA.VELOCITY] = {'boundary0': (0, 0, 0),
'boundary2': 'zeroGradient',
'boundary1': (0.1, 0, 0),
'boundary3': 'empty'}
wrapper.BC[CUBA.PRESSURE] = {'boundary0': 'zeroGradient',
'boundary2': 0,
'boundary1': 'zeroGradient',
'boundary3': 'empty'}

mesh_file = H5CUDS.open(os.path.join(name, 'poiseuille.cuds'))
mesh_from_file = mesh_file.get_mesh(name)

print "Mesh name ", mesh_from_file.name

mesh_inside_wrapper = wrapper.add_mesh(mesh_from_file)

print "Case directory ", mesh_inside_wrapper.path

for cell in mesh_inside_wrapper.iter_cells():
cell.data[CUBA.PRESSURE] = 1.0
cell.data[CUBA.VELOCITY] = [0.0, 0.0, 0.0]
mesh_inside_wrapper.update_cell(cell)

# run returns the latest time
lastTime = wrapper.run()

print "post-processing"
XYZUVW = mesh_inside_wrapper.getXYZUVW()
plt.quiver(XYZUVW[:,0],XYZUVW[:,1],XYZUVW[:,3],XYZUVW[:,4])
plt.axis('equal')
plt.savefig("result.png")
plt.show()

24 changes: 24 additions & 0 deletions foam_internalwrapper/examples/poiseuille/constant/RASProperties
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 2.2.1 |
| \\ / A nd | Web: www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object RASProperties;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

RASModel laminar;

turbulence off;

printCoeffs on;


// ************************************************************************* //
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 2.2.1 |
| \\ / A nd | Web: www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object blockMeshDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

convertToMeters 1;

vertices
(
(0 0 0)
(30 0 0)
(30 5 0)
(0 5 0)
(0 0 0.1)
(30 0 0.1)
(30 5 0.1)
(0 5 0.1)
);

blocks
(
hex (0 1 2 3 4 5 6 7) (500 20 1) simpleGrading (1 1 1)
);

edges
(
);

boundary
(
sides
{
type patch;
faces
(
(3 7 6 2)
(1 5 4 0)
);
}
inlet
{
type patch;
faces
(
(0 4 7 3)
);
}
outlet
{
type patch;
faces
(
(2 6 5 1)
);
}
frontAndBack
{
type empty;
faces
(
(0 3 2 1)
(4 5 6 7)
);
}
);

mergePatchPairs
(
);

// ************************************************************************* //
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 2.2.x |
| \\ / A nd | Web: www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class polyBoundaryMesh;
location "constant/polyMesh";
object boundary;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

4
(
sides
{
type patch;
nFaces 1000;
startFace 19480;
}
inlet
{
type patch;
nFaces 20;
startFace 20480;
}
outlet
{
type patch;
nFaces 20;
startFace 20500;
}
frontAndBack
{
type empty;
inGroups 1(empty);
nFaces 20000;
startFace 20520;
}
)

// ************************************************************************* //
Loading

5 comments on commit 03a2385

@santiagomarquezd
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments acknowledged, we'll work on that today.

@khiltunen
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looked at the tests and i think you should also include tests for FoamMesh and FoamFiles classes (more or less the same tests as in the IO wrapper side)

@jmarcelogimenez
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We added a test for FoamMesh. Test for FoamFiles is not required in internal wrapper.

@khiltunen
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the FoamFiles is not needed then you should remove the foam_files.py from the package

@santiagomarquezd
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've removed this file and it references in the code

Please sign in to comment.