Skip to content

Commit

Permalink
v0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
lcharleux committed Jan 14, 2018
1 parent bc872a0 commit 7916ecf
Show file tree
Hide file tree
Showing 6 changed files with 178 additions and 22 deletions.
2 changes: 1 addition & 1 deletion argiope/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.1"
__version__ = "0.2"

try:
from . import utils, mesh, materials, models, abq
Expand Down
7 changes: 4 additions & 3 deletions argiope/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class Mesh(argiope.utils.Container):
A simple example is given below.
.. literalinclude:: ../tests/mesh_example.py
.. literalinclude:: examples/mesh/Mesh.py
For more complex examples, follow the notebook tutorials.
"""
Expand Down Expand Up @@ -455,7 +455,7 @@ def angles(self, zfill = 3):
out = pd.concat(out).sort_index(axis = 1)
return out

def edges(self):
def edges(self, zfill = 3):
"""
Returns the aspect ratio of all elements.
"""
Expand All @@ -466,7 +466,8 @@ def edges(self):
edges["l"] = np.linalg.norm(edges[["lx", "ly", "lz"]], axis = 1)
edges = (edges.l).unstack()
edges.columns = pd.MultiIndex.from_product([["length"],
["e{0}".format(s) for s in np.arange(edges.shape[1])]])
["e" + "{0}".format(s).zfill(zfill)
for s in np.arange(edges.shape[1])]])
edges[("stats", "lmax")] = edges.length.max(axis = 1)
edges[("stats", "lmin")] = edges.length.min(axis = 1)
edges[("stats", "aspect_ratio")] = edges.stats.lmax / edges.stats.lmin
Expand Down
68 changes: 53 additions & 15 deletions doc/examples/mesh/Mesh.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,57 @@
import argiope as ag
import numpy as np
import argiope as ag

# NODE COORDINATES
coords = np.array([[0., 0., 0.], #1
[1., 0., 0.], #2
[2., 0., 0.], #3
[1., 1., 0.], #4
[0., 1., 0.], #5
[0., 0., 1.], #6
[1., 0., 1.], #7
[2., 0., 1.], #8
[1., 1., 1.], #9
[0., 1., 1.], #10
[0., 0., 2.], #11
[1., 0., 2.], #12
[2., 0., 2.], #13
[1., 1., 2.], #14
[0., 1., 2.], #15
[1., 0., 3.], #16
])

# NODE LABELS
nlabels = np.arange(len(coords)) +1

# NODE SETS
nsets = {"nset1": nlabels > 2}

# CONNECTIVITY :
# Warning = nothing, only used to ensure renctangularity of the table.
conn = [[ 1, 2, 4, 5, 0, 0, 0, 0], #1 = QUAD4
[ 2, 3, 4, 0, 0, 0, 0, 0], #2 = TRI3
[ 6, 7, 9, 10, 11, 12, 14, 15], # 3 = HEXA8
[ 7, 8, 9, 12, 13, 14, 0, 0], # 4 = PRISM6
[12, 13, 14, 16, 0, 0, 0, 0], # 5 = TETRA4
]

elabels = np.arange(1, len(conn) + 1)

types = np.array(["quad4", "tri3", "hexa8", "prism6", "tetra4"])

stypes = np.array(["CPS4", "CAX3", "C3D8",
"C3D6", "C3D4"]) # Abaqus element naming convention.

esets = {"eset1": elabels < 2}

materials = np.array(["mat1", "mat2", "mat2", "mat2", "mat2"])

nlabels = np.arange(4) + 1
coords = np.array([[0., 0., 0.],
[1., 0., 0.],
[1., 1., 0.],
[0., 1., 0.],])
elabels = np.array([1])
conn = np.array([[1, 2, 3, 4]])
types = ["quad4"]
stypes = ["CPS4"]

mesh = ag.mesh.Mesh(nlabels = nlabels,
coords = coords,
coords = coords,
nsets = nsets,
conn = conn,
elabels = elabels,
conn = conn,
types = types,
stype = stypes)
esets = esets,
types = types,
stypes = stypes,
)
2 changes: 1 addition & 1 deletion doc/notebooks_index.template
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Notebooks
$title
===========

.. toctree::
Expand Down
1 change: 1 addition & 0 deletions pip_upload.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python setup.py bdist_wheel --universal
120 changes: 118 additions & 2 deletions tests/test_mesh.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,73 @@
import unittest
import numpy as np
import argiope as ag
from mesh_example import *

# MESH SETUP
import numpy as np
import argiope as ag

################################################################################
# NODE COORDINATES
################################################################################

coords = np.array([[0., 0., 0.], #1
[1., 0., 0.], #2
[2., 0., 0.], #3
[1., 1., 0.], #4
[0., 1., 0.], #5
[0., 0., 1.], #6
[1., 0., 1.], #7
[2., 0., 1.], #8
[1., 1., 1.], #9
[0., 1., 1.], #10
[0., 0., 2.], #11
[1., 0., 2.], #12
[2., 0., 2.], #13
[1., 1., 2.], #14
[0., 1., 2.], #15
[1., 0., 3.], #16
])

# NODE LABELS
nlabels = np.arange(len(coords)) +1

# NODE SETS
nsets = {"nset1": nlabels > 2}

# CONNECTIVITY :
# Warning = nothing, only used to ensure renctangularity of the table.
conn = [[1, 2, 4, 5, 0, 0, 0, 0], #1 = QUAD4
[2, 3, 4, 0, 0, 0, 0, 0], #2 = TRI3
[6, 7, 9, 10, 11, 12, 14, 15], # 3 = HEXA8
[7, 8, 9, 12, 13, 14, 0, 0], # 4 = PRISM6
[12, 13, 14, 16, 0, 0, 0, 0], # 5 = TETRA4
]

elabels = np.arange(1, len(conn) + 1)

types = np.array(["quad4", "tri3", "hexa8", "prism6", "tetra4"])

stypes = np.array(["CPS4", "CAX3", "C3D8",
"C3D6", "C3D4"]) # Abaqus element naming convention.

esets = {"eset1": elabels < 2}

materials = np.array(["mat1", "mat2", "mat2", "mat2", "mat2"])

mesh = ag.mesh.Mesh(nlabels = nlabels,
coords = coords,
nsets = nsets,
conn = conn,
elabels = elabels,
esets = esets,
types = types,
stypes = stypes,
materials = materials
)
fields = {}
################################################################################
# TESTING
################################################################################

class MyTest(unittest.TestCase):

Expand Down Expand Up @@ -47,7 +113,57 @@ def test_volumes(self):
vout = mesh.centroids_and_volumes().volume.values
vin = np.array([1., .5, 1., .5, 1./6.])
self.assertTrue(
((vin -vout)**2).sum() < 1.e10, 0 )
((vin - vout)**2).sum() < 1.e-10 )

def test_centroids(self):
"""
Tests if centroid computations are correct.
"""
vout = mesh.centroids_and_volumes().centroid.values
vin = np.array(
[[ 0.5 , 0.5 , 0. ],
[ 1.33333333, 0.33333333, 0. ],
[ 0.5 , 0.5 , 1.5 ],
[ 1.33333333, 0.33333333, 1.5 ],
[ 1.25 , 0.25 , 2.25 ]])
self.assertTrue(
((vin -vout)**2).sum() < 1.e-10)


def test_angles(self):
"""
Tests if volume computations are correct.
"""
vout = mesh.angles().angles.stack().values
vin = np.array(
[ 90., 90., 90., 90., 90., 45., 45., 90., 90., 90., 90.,
90., 90., 90., 90., 90., 90., 90., 90., 90., 90., 90.,
90., 90., 90., 90., 90., 90., 90., 90., 90., 90., 45.,
45., 90., 45., 45., 90., 90., 90., 90., 90., 90., 90.,
90., 90., 90., 90., 90., 90., 45., 45., 90., 45., 45.,
60., 60., 60., 45., 45., 90.])
self.assertTrue(
((vin -vout)**2).sum() < 1.e-10)

def test_edges(self):
"""
Tests if edges computations are correct.
"""
vout = mesh.edges().length.stack().values
vin = np.array(
[ 1. , 1. , 1. , 1. , 1. ,
1.41421356, 1. , 1. , 1. , 1. ,
1. , 1. , 1. , 1. , 1. ,
1. , 1. , 1. , 1. , 1. ,
1.41421356, 1. , 1. , 1.41421356, 1. ,
1. , 1. , 1. , 1. , 1.41421356,
1.41421356, 1. ])

self.assertTrue(
((vin -vout)**2).sum() < 1.e15, 0 )




if __name__ == '__main__':
unittest.main()

0 comments on commit 7916ecf

Please sign in to comment.