Helper utilities for OpenFOAM blockMeshDict generation.
Project description
# ofblockmeshdicthelper
Helper utilities for OpenFOAM blockMeshDict generation.
## For what?
The aim of ofblocmeshdicthekper is to provide name-based access to the elements of
blockDictMesh file, such as vertex, block, face, etc.
## Installation
From PyPI simply,
```
pip install ofblockmeshdicthelper
```
Or, it is allowed to install directory from github repository (this or your own forked one).
## Example
Here is an example which generate wedged model shown at
https://openfoamwiki.net/index.php/Main_ContribExamples/AxiSymmetric
```python
""" example of ofblockmeshdicthelper
try to generate wedged pype object shown at
https://openfoamwiki.net/index.php/Main_ContribExamples/AxiSymmetric
"""
from __future__ import unicode_literals, print_function
import math
from ofblockmeshdicthelper import BlockMeshDict, Vertex
wedgedegree = 5.0
# geometries
radius_x = 0.19
length_z = 1.1
# prepare ofblockmeshdicthelper.BlockMeshDict instance to
# gather vertices, blocks, faces and boundaries.
bmd = BlockMeshDict()
#
bmd.set_metric('m')
# base vertices which are rotated +- 2.5 degrees
basevs = [
Vertex(0, 0, 0, 'v0'),
Vertex(radius_x, 0, 0, 'v1'),
Vertex(radius_x, 0, length_z, 'v2'),
Vertex(0, 0, length_z, 'v3')]
# rotate wedgedegree/2 around z axis
# rotated vertices are named with '-y' or '+y' suffix.
# these verteces are added to BlockMeshDict instence to be referred
# by following blocks and faces...
cosd = math.cos(math.radians(wedgedegree/2.0))
sind = math.sin(math.radians(wedgedegree/2.0))
for v in basevs:
bmd.add_vertex(v.x*cosd, -v.x*sind, v.z, v.name+'-y')
bmd.add_vertex(v.x*cosd, v.x*sind, v.z, v.name+'+y')
# v0+y and v3+y have same coordinate as v0-y and v3-y, respectively.
bmd.reduce_vertex('v0-y', 'v0+y')
bmd.reduce_vertex('v3-y', 'v3+y')
# utility to to generate vertex names
def vnamegen(x0z0, x1z0, x1z1, x0z1):
return (x0z0+'-y', x1z0+'-y', x1z0+'+y', x0z0+'+y',
x0z1+'-y', x1z1+'-y', x1z1+'+y', x0z1+'+y')
# Noted that 'v0+y' and 'v3+y' are still valid
b0 = bmd.add_hexblock(vnamegen('v0', 'v1', 'v2', 'v3'), (19, 1, 300), 'b0')
# face element of block can be generated by Block.face method
bmd.add_boundary('wedge', 'front', [b0.face('ym')])
bmd.add_boundary('wedge', 'back', [b0.face('yp')])
bmd.add_boundary('wall', 'tankWall', [b0.face('xp')])
bmd.add_boundary('patch', 'inlet', [b0.face('zm')])
bmd.add_boundary('patch', 'outlet', [b0.face('zp')])
bmd.add_boundary('empty', 'axis', [b0.face('xm')])
# prepare for output
bmd.assign_vertexid()
# output
print(bmd.format())
```
Helper utilities for OpenFOAM blockMeshDict generation.
## For what?
The aim of ofblocmeshdicthekper is to provide name-based access to the elements of
blockDictMesh file, such as vertex, block, face, etc.
## Installation
From PyPI simply,
```
pip install ofblockmeshdicthelper
```
Or, it is allowed to install directory from github repository (this or your own forked one).
## Example
Here is an example which generate wedged model shown at
https://openfoamwiki.net/index.php/Main_ContribExamples/AxiSymmetric
```python
""" example of ofblockmeshdicthelper
try to generate wedged pype object shown at
https://openfoamwiki.net/index.php/Main_ContribExamples/AxiSymmetric
"""
from __future__ import unicode_literals, print_function
import math
from ofblockmeshdicthelper import BlockMeshDict, Vertex
wedgedegree = 5.0
# geometries
radius_x = 0.19
length_z = 1.1
# prepare ofblockmeshdicthelper.BlockMeshDict instance to
# gather vertices, blocks, faces and boundaries.
bmd = BlockMeshDict()
#
bmd.set_metric('m')
# base vertices which are rotated +- 2.5 degrees
basevs = [
Vertex(0, 0, 0, 'v0'),
Vertex(radius_x, 0, 0, 'v1'),
Vertex(radius_x, 0, length_z, 'v2'),
Vertex(0, 0, length_z, 'v3')]
# rotate wedgedegree/2 around z axis
# rotated vertices are named with '-y' or '+y' suffix.
# these verteces are added to BlockMeshDict instence to be referred
# by following blocks and faces...
cosd = math.cos(math.radians(wedgedegree/2.0))
sind = math.sin(math.radians(wedgedegree/2.0))
for v in basevs:
bmd.add_vertex(v.x*cosd, -v.x*sind, v.z, v.name+'-y')
bmd.add_vertex(v.x*cosd, v.x*sind, v.z, v.name+'+y')
# v0+y and v3+y have same coordinate as v0-y and v3-y, respectively.
bmd.reduce_vertex('v0-y', 'v0+y')
bmd.reduce_vertex('v3-y', 'v3+y')
# utility to to generate vertex names
def vnamegen(x0z0, x1z0, x1z1, x0z1):
return (x0z0+'-y', x1z0+'-y', x1z0+'+y', x0z0+'+y',
x0z1+'-y', x1z1+'-y', x1z1+'+y', x0z1+'+y')
# Noted that 'v0+y' and 'v3+y' are still valid
b0 = bmd.add_hexblock(vnamegen('v0', 'v1', 'v2', 'v3'), (19, 1, 300), 'b0')
# face element of block can be generated by Block.face method
bmd.add_boundary('wedge', 'front', [b0.face('ym')])
bmd.add_boundary('wedge', 'back', [b0.face('yp')])
bmd.add_boundary('wall', 'tankWall', [b0.face('xp')])
bmd.add_boundary('patch', 'inlet', [b0.face('zm')])
bmd.add_boundary('patch', 'outlet', [b0.face('zp')])
bmd.add_boundary('empty', 'axis', [b0.face('xm')])
# prepare for output
bmd.assign_vertexid()
# output
print(bmd.format())
```
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Close
Hashes for ofblockmeshdicthelper-0.1.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8084a3c8d37bce675ba282cb971a44a39446d507c5b9ed6176dfe0e52ad59302 |
|
MD5 | c2704cb6c4c0e907e5f3521d9a713215 |
|
BLAKE2b-256 | 4a771a82be625956765dc2eb035654a9b59f9534bfd64e7b520d3928d493581f |