From 7916ecf0fed927f7e27cc4ced35856a0798d96bd Mon Sep 17 00:00:00 2001 From: lcharleux Date: Sun, 14 Jan 2018 21:50:07 +0100 Subject: [PATCH] v0.2 --- argiope/__init__.py | 2 +- argiope/mesh.py | 7 +- doc/examples/mesh/Mesh.py | 68 +++++++++++++++----- doc/notebooks_index.template | 2 +- pip_upload.txt | 1 + tests/test_mesh.py | 120 ++++++++++++++++++++++++++++++++++- 6 files changed, 178 insertions(+), 22 deletions(-) create mode 100644 pip_upload.txt diff --git a/argiope/__init__.py b/argiope/__init__.py index 43e95b2..be97ad4 100644 --- a/argiope/__init__.py +++ b/argiope/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.1" +__version__ = "0.2" try: from . import utils, mesh, materials, models, abq diff --git a/argiope/mesh.py b/argiope/mesh.py index 0d1e08b..d126f56 100644 --- a/argiope/mesh.py +++ b/argiope/mesh.py @@ -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. """ @@ -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. """ @@ -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 diff --git a/doc/examples/mesh/Mesh.py b/doc/examples/mesh/Mesh.py index eca55e3..77d86dc 100644 --- a/doc/examples/mesh/Mesh.py +++ b/doc/examples/mesh/Mesh.py @@ -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, + ) diff --git a/doc/notebooks_index.template b/doc/notebooks_index.template index 34f9be2..6f9de2b 100644 --- a/doc/notebooks_index.template +++ b/doc/notebooks_index.template @@ -1,4 +1,4 @@ -Notebooks +$title =========== .. toctree:: diff --git a/pip_upload.txt b/pip_upload.txt new file mode 100644 index 0000000..ec03c5d --- /dev/null +++ b/pip_upload.txt @@ -0,0 +1 @@ +python setup.py bdist_wheel --universal diff --git a/tests/test_mesh.py b/tests/test_mesh.py index 056ea3c..c9e80c6 100644 --- a/tests/test_mesh.py +++ b/tests/test_mesh.py @@ -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): @@ -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()