Skip to content

Commit

Permalink
update to release end of project
Browse files Browse the repository at this point in the history
  • Loading branch information
Duncan-Hunter committed Aug 30, 2019
1 parent 99b2c82 commit b61fd50
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 25 deletions.
46 changes: 30 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,41 @@
# pipemesh
These tools use the GMSH-SDK (or GMSH API), available [here](http://gmsh.info/).
These tools use the GMSH-SDK (or GMSH-API), available [here](http://gmsh.info/).

The documentation for pipemesh can be found [here](https://pipemesh.readthedocs.io/en/latest/).

If you use this in your work, please cite it so others can discover it, and the tools can be grown.
## Requirements:
- libgmsh.so, libgmsh.so.4.3, libgmsh.so.4.3.0 (or higher) from the GMSH SDK. Download the SDK and navigate to the lib/ folder to find these, or use the versions hosted in this repository.
- SciPy (and NumPy, installed with SciPy).

*pipemesh* is currently only supported on Linux systems (e.g. Ubuntu 16, 18).

## Installation
```python
python3 -m pip install --user pipemesh

```bash
$python3 -m pip install --user pipemesh
```

Once completed, navigate to site-packages/pipemesh. Place the files libgmsh.so, libgmsh.so.4.3 and libgmsh.so.4.3.0, which can be downloaded from the GMSH website (link above).
Once completed, navigate to site-packages/pipemesh of the python installation used. Place the files libgmsh.so, libgmsh.so.4.3 and libgmsh.so.4.3.0 in this folder.

A virtual environment can be useful to locate the site-packages directory more easily.

```bash
# If you don't have venv
$sudo apt-get install python3-venv

$mkdir virtual_env # Name of your virtual environment
$python3 -m venv virtual_env
$source virtual_env/bin/activate
$python3 -m pip install –upgrade pip
$python3 -m pip install --user scipy
$python3 -m pip install --user pipemesh
```
Then simply place the libgmsh files into virtual_env/lib/site-packages/pipemesh/. Ensure to use the virtual environment every time you need to use *pipemesh*.

If you really don't want to use pip to install, clone the repository, and add acse-9.../pipemesh/ to PATH so python can find it.

### pipes.py
Using the pieces above and the Network class, pipes and pipe networks can be easily built. A Network is started with:
Once installed, scripts to generate pipe and pipe network meshes can be created. A script is started by creating the *Network* object:
```python
from pipemesh import pipes
network = pipes.Network(1, 0.3, [1,0,0], 0.1)
Expand All @@ -27,7 +47,7 @@ network.add_t_junction([-1,-1,0], 0.05)
network.add_curve([0,1,0], 0.5, 0.05)
network.add_mitered([0, 1, 0], 0.05, out_number=2)
```
Where out_number specifies which outlet of the pipe the piece will be added to. For more information on each function, the documentation is currently only within the files.
Where out_number specifies which outlet of the pipe the piece will be added to. For more information on each function, please visit the documentation linked above.

Examples:
* Chicane with mitered bends:
Expand All @@ -50,20 +70,16 @@ network.add_curve([-1,0,0], 0.5, 0.05, out_number=3)
network.add_cylinder(1.5, 0.1, out_number=3)
```

Once the network is complete, you can fuse the objects together and create physical surfaces and volumes, and set the local mesh sizes. Information can be obtained and written to file. This is all done with one call.
Once the Network is complete, you can fuse the objects together and create physical surfaces and volumes, and set the local mesh sizes. Information can be obtained and written to file. This is all done with one call.
```python
network.generate(filename="example", binary=False, write_info=False, mesh_format="msh2", write_xml=False run_gui=False)
```
Which will write the file "example.msh", as a msh2 binary file.

Network has get_phys_ids methods, which can be used with AutoMPML.

### Requirements for pipes.py:
- libgmsh.so, libgmsh.so.4.3, libgmsh.so.4.3.0 from the GMSH SDK.
- NumPy, SciPy

### AutoMPML
The file auto_mpml.py contains the class AutoMPML. This edits a basic pipe flow simulation .mpml file used with IC-FERST by inputting the user values in the right places. This isn't actually automatic, but can save time by not editing mpml files with Diamond. Options that can be changed are relevant to conducting a pipe flow investigation with [IC-FERST](http://multifluids.github.io/).
The file auto_mpml.py contains the class *AutoMPML*. This edits a basic pipe flow simulation .mpml file used with IC-FERST by inputting the user values in the right places. This isn't actually automatic, but can save time by not editing mpml files with Diamond. Options that can be changed are relevant to conducting a pipe flow investigation with [IC-FERST](http://multifluids.github.io/).

Example:
```python
Expand Down Expand Up @@ -112,7 +128,7 @@ As the options can be set in python, this means that multiple simulations can be
Contains classes (and some useful functions for said classes) which represent cylindrical GMSH objects. The classes store information of the object, such as the centre and direction of its faces, as well as functions to update the information when transformations are applied to them. This makes the information a little easier to access than using just the GMSH API. To use these individually start your file with:

```python
from pipemesh import pieces
from pipemesh import pieces, gmsh
model = gmsh.model
mesh = model.mesh
gmsh.initialize()
Expand Down Expand Up @@ -168,5 +184,3 @@ To finish, and end use of gmsh, call
```python
gmsh.finalize()
```

As of yet, just using the pieces on their own is limited, as they do not have translate, or rotate functions, but if desired, the user can look into the GMSH-SDK and develop some, or use pipes (below) to generate pipe meshes.
8 changes: 8 additions & 0 deletions examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,12 @@
# network.add_mitered([0,0,-1], 0.1)
# network.add_cylinder(0.2, 0.1)

"""Helix"""
# for i in range(3):
# network.add_curve([0, 1, -0.25], 1, 0.1)
# network.add_curve([-1, 0, -0.25], 1, 0.1)
# network.add_curve([0, -1, -0.25], 1, 0.1)
# network.add_curve([1, 0, -0.25], 1, 0.1)


# network.generate(filename=None, binary=False, write_info=False, write_xml=False, run_gui=True)
31 changes: 24 additions & 7 deletions pipemesh/pipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class Network():
velocity magnitude.
"""

def __init__(self, length, radius, direction, lcar):
def __init__(self, length, radius, direction, lcar=0.1):
"""
Creates the inlet cylinder of a pipe.
Expand All @@ -99,6 +99,9 @@ def __init__(self, length, radius, direction, lcar):
lcar: (float) Mesh size of this piece. Maximum mesh size of model.
"""
gmsh.initialize()
if lcar <= 0:
print("Defaulting to lcar of 0.1")
lcar = 0.1
gmsh.option.setNumber("Mesh.CharacteristicLengthMax", lcar)

direction = np.array(direction)
Expand Down Expand Up @@ -150,7 +153,7 @@ def _out_number(self, out_number):
out_number -= 1
return out_number

def add_cylinder(self, length, lcar, out_number=0):
def add_cylinder(self, length, lcar=0.1, out_number=0):
"""Adds a pipe to the Network at the outlet.
Args:
Expand All @@ -159,6 +162,9 @@ def add_cylinder(self, length, lcar, out_number=0):
out_number: Out surface to add to. If <= 1, will add to the
first out surface.
"""
if lcar <= 0:
print("Defaulting to lcar of 0.1")
lcar = 0.1
out_number = self._out_number(out_number)
out_surface = self.out_surfaces[out_number]
piece = pieces.Cylinder(length, out_surface.radius,
Expand All @@ -170,7 +176,7 @@ def add_cylinder(self, length, lcar, out_number=0):
self.piece_list.append(piece)
self.out_surfaces[out_number] = piece.out_surface

def add_curve(self, new_direction, bend_radius, lcar, out_number=0):
def add_curve(self, new_direction, bend_radius, lcar=0.1, out_number=0):
"""Adds a curve to the Network at the outlet.
Args:
Expand All @@ -187,6 +193,9 @@ def add_curve(self, new_direction, bend_radius, lcar, out_number=0):
Bend radius isn't big enough (<1.1 inlet radius).
"""
# Check input
if lcar <= 0:
print("Defaulting to lcar of 0.1")
lcar = 0.1
out_number = self._out_number(out_number)
out_surface = self.out_surfaces[out_number]
if bend_radius < 1.1 * out_surface.radius:
Expand All @@ -202,7 +211,7 @@ def add_curve(self, new_direction, bend_radius, lcar, out_number=0):
self.piece_list.append(piece)
self.out_surfaces[out_number] = piece.out_surface

def add_mitered(self, new_direction, lcar, out_number=0):
def add_mitered(self, new_direction, lcar=0.1, out_number=0):
"""Adds a mitered bend to the Network at the outlet.
A mitered bend is a sharp change in direction. Hard to
Expand All @@ -215,6 +224,9 @@ def add_mitered(self, new_direction, lcar, out_number=0):
out_number: Out surface to add to. If <= 1, will add to the
first out surface.
"""
if lcar <= 0:
print("Defaulting to lcar of 0.1")
lcar = 0.1
out_number = self._out_number(out_number)
out_surface = self.out_surfaces[out_number]
# Create Piece
Expand All @@ -232,7 +244,7 @@ def add_change_radius(self,
length,
new_radius,
change_length,
lcar,
lcar=0.1,
out_number=0):
"""Adds a piece that changes the radius of the outlet.
Expand All @@ -253,6 +265,9 @@ def add_change_radius(self,
ValueErrors: change_length is not between length and 0.
If radius does not change.
"""
if lcar <= 0:
print("Defaulting to lcar of 0.1")
lcar = 0.1
out_number = self._out_number(out_number)
out_surface = self.out_surfaces[out_number]
# Create Piece
Expand All @@ -266,7 +281,7 @@ def add_change_radius(self,
self.piece_list.append(piece)
self.out_surfaces[out_number] = piece.out_surface

def add_t_junction(self, t_direction, lcar, t_radius=-1, out_number=0):
def add_t_junction(self, t_direction, lcar=0.1, t_radius=-1, out_number=0):
"""Adds a T junction to the Network at the outlet.
This represents a pipe joining this pipe, creating a place to
Expand All @@ -281,7 +296,9 @@ def add_t_junction(self, t_direction, lcar, t_radius=-1, out_number=0):
out_number: Out surface to add to. If <= 1, will add to the
first out surface.
"""

if lcar <= 0:
print("Defaulting to lcar of 0.1")
lcar = 0.1
out_number = self._out_number(out_number)
out_surface = self.out_surfaces[out_number]

Expand Down
52 changes: 50 additions & 2 deletions pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,53 @@ def test4():
assert(np.allclose(change_radius.out_surface.centre, [1, 0, 0]))
assert(np.allclose(change_radius.in_surface.centre, [0, 0, 0]))
gmsh.finalize()

gmsh.initialize()
curve = pieces.Curve(
0.25, [1, 0, 0], [0, 0, 1], 1, 0.1
)
assert(np.allclose(curve.out_surface.centre, np.array([1, 0, 1])))
assert(np.allclose(curve.in_surface.centre, np.array([0, 0, 0])))
assert(np.allclose(curve.out_surface.direction, np.array([0, 0, 1])))
assert(np.allclose(curve.in_surface.direction, np.array([1, 0, 0])))
gmsh.finalize()

gmsh.initialize()
mitered = pieces.Mitered(
0.25, [1, 1, 0], [0, 0, 1], 0.1
)
assert(np.allclose(mitered.in_surface.direction, np.array([1, 1, 0])))
assert(np.allclose(mitered.out_surface.direction, np.array([0, 0, 1])))
gmsh.finalize()

gmsh.initialize()
t_junc = pieces.TJunction(
0.3, 0.3, [0, 0, 1], [1, 0, 0], 0.1
)
assert(np.allclose(t_junc.in_surface.direction, np.array([0, 0, 1])))
assert(np.allclose(t_junc.t_surface.direction, np.array([1, 0, 0])))
gmsh.finalize()
print("Indiviual pieces created correctly.")


def test5():
"""Tests if network updates after rotation."""
network = pipes.Network(
1, 0.25, [1, 0, 0], 0.1
)
network.add_curve([0, 0, 1], 1, 0.1)
network.rotate_network([0, 1, 0], -np.pi/2)
network.generate(run_gui=False)
assert(np.allclose(
network.out_surfaces[0].direction, np.array([-1, 0, 0])
))
assert(np.allclose(
network.in_surfaces[0].direction, np.array([0, 0, -1])
))
print("Rotate whole network works correctly.")


def test6():
"""Tests creation of velocities."""
network = pipes.Network(
1, 0.25, [1, 1, 1], 0.1
Expand All @@ -86,9 +129,12 @@ def test5():
network.generate(run_gui=False)
velos = network.get_velocities_reynolds([1, 3], 10000, 1000, 1e-3)
assert(np.allclose(velos[1], np.array([-0.02, 0, 0])))
velos_2 = network.get_velocities_vel_mag([1, 3], 0.02)
assert(np.allclose(velos_2[1], np.array([-0.02, 0, 0])))
print("Get velocities methods working correctly.")


def test6():
def test7():
"""Tests get_ids methods."""
network = pipes.Network(
1, 0.25, [1, 1, 1], 0.1
Expand All @@ -99,10 +145,12 @@ def test6():
assert(np.allclose(inlet_phys_ids, np.array([1, 2, 3])))
cyl_phys_ids = network.get_cyl_phys_ids()
assert(np.allclose(np.array([cyl_phys_ids]), np.array([4, 5, 6, 7])))
print("Get IDs method working correctly.")

test1()
test2()
test3()
test4()
test5()
test6()
test6()
test7()

0 comments on commit b61fd50

Please sign in to comment.