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

Use common 0.2 #53

Merged
merged 12 commits into from
Nov 3, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Simphony-openfoam is hosted on github: https://github.com/simphony/simphony-open
Requirements
------------

- `simphony-common`_ == 0.1.3
- `simphony-common`_ == 0.2.0

.. _simphony-common: https://github.com/simphony/simphony-common

Expand All @@ -23,11 +23,16 @@ Installation

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


Before installing or using simphony-openfoam , make sure the OpenFOAM environment variables are set by the following command:
source /opt/openfoam222/etc/bashrc

Installation is based on setuptools::

# build and install
python setup.py install


Testing
-------

Expand Down
7 changes: 5 additions & 2 deletions foam_controlwrapper/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Functions, classes and constants exported here will be available
# when the `openfoam` module is imported.
from .foam_controlwrapper import FoamControlWrapper, read_foammesh
from .foam_controlwrapper import FoamControlWrapper
from .io_utils import read_foammesh
from .blockmesh_utils import create_quad_mesh
from .cuba_extension import CUBAExt
__all__ = ['FoamControlWrapper', 'CUBAExt', 'read_foammesh']
__all__ = ['FoamControlWrapper', 'CUBAExt', 'read_foammesh',
'create_quad_mesh']
69 changes: 69 additions & 0 deletions foam_controlwrapper/blockmesh_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
""" Utility functions for blockMesh

"""

import os


from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile

from .foam_files import write_default_files
from .foam_templates import blockMeshDict
from .foam_runner import FoamRunner
from .io_utils import read_foammesh


def create_quad_mesh(path, name, mesh_engine, corner_points,
nex, ney, nez):
""" create and add mesh to engine

Parameters
----------
path : str
path to mesh parent directory
name : str
name of mesh
mesh_engine : ABCModelingEngine
Mesh engine
corner_points : list
list of 8 [x,y,z] corner points
nex : int
number of elements in x -direction
ney : int
number of elements in y -direction
nez : int
number of elements in z -direction

"""
file_name = 'blockMeshDict'
case = os.path.join(path, name)
templateName = 'simpleFoam'
write_default_files(case, templateName, '0', True)
full_name = os.path.join(os.path.join(
os.path.join(case, 'constant'), 'polyMesh'), file_name)
with open(full_name, 'w') as f:
f.write(blockMeshDict)

blockMesh = ParsedParameterFile(full_name)

for i in range(8):
corner_points[i] = str(corner_points[i]).replace(',', ' ')

blockMesh["vertices"] = corner_points

blockLines = [""]
blockLines[0] = 'hex (0 1 2 3 4 5 6 7) (%i %i %i) simpleGrading (1 1 1)'\
% (nex, ney, nez)
blockMesh["blocks"] = blockLines

blockMesh.writeFile()

ncores = 1
solver = 'blockMesh'
runner = FoamRunner(solver, case, ncores)
runner.run()

foam_mesh = read_foammesh(name, path)

# add mesh to engine
mesh_engine.add_dataset(foam_mesh)
2 changes: 2 additions & 0 deletions foam_controlwrapper/cuba_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ class CUBAExt(IntEnum):
MAX_COURANT_NUMBER = 8
SURFACE_TENSION = 9
NUMBER_OF_CORES = 10
DYNAMIC_PRESSURE = 11
FLUX = 12
15 changes: 0 additions & 15 deletions foam_controlwrapper/examples/foam_mesh_to_h5cuds.py

This file was deleted.

11 changes: 11 additions & 0 deletions foam_controlwrapper/examples/foam_mesh_to_simphony_mesh.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"""Example to convert mesh from OpenFoam's format to SimPhony

"""

from simphony.engine import openfoam_file_io

wrapper = openfoam_file_io.FoamControlWrapper()

name = 'poiseuille'
path = '.'
mesh_inside_wrapper = openfoam_file_io.read_foammesh(name, path)
21 changes: 13 additions & 8 deletions foam_controlwrapper/examples/poiseuille.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@

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

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

path = '.'
name = 'poiseuille'

wrapper.CM[CUBA.NAME] = name
Expand All @@ -31,12 +30,18 @@
'boundary2': '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)
corner_points = [(0.0, 0.0, 0.0), (20.0e-3, 0.0, 0.0),
(20.0e-3, 1.0e-3, 0.0), (0.0, 1.0e-3, 0.0),
(0.0, 0.0, 0.1), (20.0e-3, 0.0, 0.1),
(20.0e-3, 1.0e-3, 0.1), (0.0, 1.0e-3, 0.1)]
# elements in x -direction
nex = 10
# elements in y -direction
ney = 4
openfoam_file_io.create_quad_mesh(path, name, wrapper, corner_points,
nex, ney, 1)

mesh_inside_wrapper = wrapper.get_dataset(name)

print "Case directory ", mesh_inside_wrapper.path

Expand Down
22 changes: 22 additions & 0 deletions foam_controlwrapper/examples/poiseuille/0/U
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@


FoamFile
{
version 2.2;
format ascii;
class volVectorField;
location "0";
object U;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //


dimensions [ 0 1 -1 0 0 0 0 ];

internalField uniform (0 0 0);

boundaryField
{

}

22 changes: 22 additions & 0 deletions foam_controlwrapper/examples/poiseuille/0/p
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@


FoamFile
{
version 2.2;
format ascii;
class volScalarField;
location "0";
object p;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //


dimensions [ 0 2 -2 0 0 0 0 ];

internalField uniform 0;

boundaryField
{

}

17 changes: 6 additions & 11 deletions foam_controlwrapper/examples/poiseuille/constant/RASProperties
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
/*--------------------------------*- 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;
version 2.2;
format ascii;
class dictionary;
location "constant";
object RASProperties;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //


RASModel laminar;

turbulence off;

printCoeffs on;


// ************************************************************************* //

Loading