diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index 5e1c752..e312508 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -5,12 +5,14 @@ on: branches: - main - "2.0" + - "2.0_merge" tags: - "v*.*.*" pull_request: branches: - main - "2.0" + - "2.0_merge" concurrency: group: ci-${{ github.ref }} @@ -150,4 +152,4 @@ jobs: run: | for pkg in dist/*/*.tar.bz2; do conda run -n base anaconda upload "$pkg" --force - done + done \ No newline at end of file diff --git a/AUTHORS.rst b/AUTHORS.rst index 5273ddd..21444a1 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -14,5 +14,6 @@ Contributions * Edward Villegas Pulgarin (`@cosmoscalibur`) * Guillaume Huet (`@guillaumehuet`) +* Marc Gehring (`mg494`) diff --git a/CITATION.cff b/CITATION.cff new file mode 100644 index 0000000..955e21a --- /dev/null +++ b/CITATION.cff @@ -0,0 +1,35 @@ +# This CITATION.cff file was generated with cffinit. +# Visit https://bit.ly/cffinit to generate yours today! + +cff-version: 1.1.0 +title: 'SolidsPy: 2D-Finite Element Analysis with Python' +message: >- + If you use this software, please cite it using the + metadata from this file. +type: software +authors: + - given-names: Nicolás + family-names: Guarín-Zapata + email: nguarinz@eafit.edu.co + affiliation: Universidad EAFIT + orcid: 'https://orcid.org/0000-0002-9435-1914' + - given-names: Juan David + family-names: Gómez + email: jgomezc1@eafit.edu.co + affiliation: Universidad EAFIT +identifiers: + - type: doi + value: 10.5281/zenodo.4029270 +url: 'https://github.com/AppliedMechanics-EAFIT/SolidsPy' +abstract: >- + SolidsPy is a simple finite element analysis code + for 2D elasticity problems. The code uses as input + simple-to-create text files defining a model in + terms of nodal, element, material, and load data. +keywords: + - finite element method + - scientific computing + - computational mechanics + - elasticity + - python +license: MIT diff --git a/HISTORY.rst b/HISTORY.rst index 8a04e0b..1d01e88 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -1,6 +1,11 @@ History ------- +1.1.0 (2023-11-03) +~~~~~~~~~~~~~~~~~~ + +* Remove NumPy types in the code that were removed since NumPy 1.24 + 1.0.15 (2018-05-09) ~~~~~~~~~~~~~~~~~~ diff --git a/README.md b/README.md new file mode 100644 index 0000000..a76df3e --- /dev/null +++ b/README.md @@ -0,0 +1,142 @@ +# SolidsPy: 2D-Finite Element Analysis with Python + +![](https://raw.githubusercontent.com/AppliedMechanics-EAFIT/SolidsPy/master/docs/img/wrench.png) +[![PyPI download](https://img.shields.io/pypi/v/solidspy.svg)](https://pypi.python.org/pypi/continuum_mechanics) +[![Documentation Status](https://readthedocs.org/projects/solidspy/badge/?version=latest)](https://solidspy.readthedocs.io/en/latest/) +[![Downloads frequency](https://img.shields.io/pypi/dm/solidspy)](https://pypistats.org/packages/solidspy) +[![image](https://zenodo.org/badge/48294591.svg)](https://zenodo.org/badge/latestdoi/48294591) + +A simple finite element analysis code for 2D elasticity problems. The code uses +as input simple-to-create text files defining a model in terms of nodal, +element, material and load data. + +- Documentation: +- GitHub: +- PyPI: +- Free and open source software: [MIT license](http://en.wikipedia.org/wiki/MIT_License) + +## Features + +- It is based on an open-source environment. +- It is easy to use. +- The code allows to find displacement, strain and stress solutions + for arbitrary two-dimensional domains discretized into finite + elements and subject to point loads. +- The code is organized in independent modules for pre-processing, + assembly and post-processing allowing the user to easily modify it + or add features like new elements or analyses pipelines. +- It was created with academic and research purposes. +- It has been used to tech the following courses: + - Introduction to Solid Mechanics. + - Computational Modeling. + - Introduction to the Finite Element Methods. + - Introduction to Soil Mechanics. + +## Installation + +The code is written in Python and it depends on `numpy`, and `scipy` and. It +has been tested under Windows, Mac, Linux and Android. + +To install *SolidsPy* open a terminal and type: + + pip install solidspy + +To specify through a GUI the folder where the input files are stored you will +need to install [easygui](http://easygui.readthedocs.org/en/master/). + +To easily generate the required SolidsPy text files out of a +[Gmsh](http://gmsh.info/) model you will need [meshio](https://github.com/nschloe/meshio). + +These two can be installed with: + + pip install easygui + pip install meshio + +## How to run a simple model + +For further explanation check the [docs](http://solidspy.readthedocs.io/en/latest/). + +Let's suppose that we have a simple model represented by the following files +(see [tutorials/square example](http://solidspy.readthedocs.io/en/latest/tutorials/square_example.html) +for further explanation). + +- `nodes.txt` + +``` + 0 0.00 0.00 0 -1 + 1 2.00 0.00 0 -1 + 2 2.00 2.00 0 0 + 3 0.00 2.00 0 0 + 4 1.00 0.00 -1 -1 + 5 2.00 1.00 0 0 + 6 1.00 2.00 0 0 + 7 0.00 1.00 0 0 + 8 1.00 1.00 0 0 +``` + + +- `eles.txt` + +``` + 0 1 0 0 4 8 7 + 1 1 0 4 1 5 8 + 2 1 0 7 8 6 3 + 3 1 0 8 5 2 6 +``` + + +- `mater.txt` + +``` + 1.0 0.3 +``` + + +- `loads.txt` + +``` + 3 0.0 1.0 + 6 0.0 2.0 + 2 0.0 1.0 +``` + + +Run it in Python as follows: + +``` python +import matplotlib.pyplot as plt # load matplotlib +from solidspy import solids_GUI # import our package +disp = solids_GUI() # run the Finite Element Analysis +plt.show() # plot contours +``` + +For Mac users it is suggested to use an IPython console to run the example. + +## License + +This project is licensed under the [MIT license](http://en.wikipedia.org/wiki/MIT_License). +The documents are licensed under [Creative Commons Attribution License](http://creativecommons.org/licenses/by/4.0/). + +## Citation + +To cite SolidsPy in publications use + +> Nicolás Guarín-Zapata, Juan Gomez (2023). SolidsPy: Version 1.1.0 +> (Version v1.1.0). Zenodo. + +A BibTeX entry for LaTeX users is + +```bibtex +@software{solidspy, + title = {SolidsPy: 2D-Finite Element Analysis with Python}, + version = {1.1.0}, + author = {Guarín-Zapata, Nicolás and Gómez, Juan}, + year = 2023, + keywords = {Python, Finite elements, Scientific computing, Computational mechanics}, + abstract = {SolidsPy is a simple finite element analysis code for 2D elasticity + problems. The code uses as input simple-to-create text files defining a model + in terms of nodal, element, material and load data.}, + url = {https://github.com/AppliedMechanics-EAFIT/SolidsPy}, + doi = {https://doi.org/10.5281/zenodo.7694030} +} +``` diff --git a/README.rst b/README.rst index a137849..accf1f5 100644 --- a/README.rst +++ b/README.rst @@ -2,9 +2,7 @@ SolidsPy: 2D-Finite Element Analysis with Python ================================================ .. figure:: https://raw.githubusercontent.com/AppliedMechanics-EAFIT/SolidsPy/master/docs/img/wrench.png - :alt: Wrench under bending. - - + :alt: Wrench under bending .. image:: https://img.shields.io/pypi/v/solidspy.svg :target: https://pypi.python.org/pypi/continuum_mechanics @@ -18,6 +16,8 @@ SolidsPy: 2D-Finite Element Analysis with Python :target: https://pypistats.org/packages/solidspy :alt: Downloads frequency +.. image:: https://zenodo.org/badge/48294591.svg + :target: https://zenodo.org/badge/latestdoi/48294591 A simple finite element analysis code for 2D elasticity problems. @@ -57,8 +57,8 @@ Features Installation ------------ -The code is written in Python and it depends on ``numpy``, ``scipy`` and -``sympy``. It has been tested under Windows, Mac, Linux and Android. +The code is written in Python and it depends on ``numpy``, and ``scipy`` +and. It has been tested under Windows, Mac, Linux and Android. To install *SolidsPy* open a terminal and type: @@ -90,63 +90,54 @@ Let's suppose that we have a simple model represented by the following files (see `tutorials/square example `__ for further explanation). -.. code:: python - import numpy as np - from solidspy.solids_GUI import solids_auto +- ``nodes.txt`` + +:: + + 0 0.00 0.00 0 -1 + 1 2.00 0.00 0 -1 + 2 2.00 2.00 0 0 + 3 0.00 2.00 0 0 + 4 1.00 0.00 -1 -1 + 5 2.00 1.00 0 0 + 6 1.00 2.00 0 0 + 7 0.00 1.00 0 0 + 8 1.00 1.00 0 0 - ### Define the data - nodes = np.array([ - [0, 0.00, 0.00], - [1, 2.00, 0.00], - [2, 2.00, 2.00], - [3, 0.00, 2.00], - [4, 1.00, 0.00], - [5, 2.00, 1.00], - [6, 1.00, 2.00], - [7, 0.00, 1.00], - [8, 1.00, 1.00]]) +- ``eles.txt`` - cons = np.array([ - [0, -1], - [0, -1], - [0, 0], - [0, 0], - [-1, -1], - [0, 0], - [0, 0], - [0, 0], - [0, 0]]) +:: + + 0 1 0 0 4 8 7 + 1 1 0 4 1 5 8 + 2 1 0 7 8 6 3 + 3 1 0 8 5 2 6 + +- ``mater.txt`` - elements = np.array([ - [0, 1, 0, 0, 4, 8, 7], - [1, 1, 0, 4, 1, 5, 8], - [2, 1, 0, 7, 8, 6, 3], - [3, 1, 0, 8, 5, 2, 6]]) +:: - mats = np.array([[1.0, 0.3]]) + 1.0 0.3 - loads = np.array([ - [2, 0.0, 1.0], - [3, 0.0, 1.0], - [6, 0.0, 2.0]]) +- ``loads.txt`` - data = {"nodes": nodes, - "cons": cons, - "elements": elements, - "mats": mats, - "loads": loads} +:: - ### Run the simulation - disp = solids_auto(data) - plt.show() + 3 0.0 1.0 + 6 0.0 2.0 + 2 0.0 1.0 +Run it in Python as follows: -Save it as ``example_solidspy.py`` and run it in your terminal: +.. code:: python -.. code:: bash + import matplotlib.pyplot as plt # load matplotlib + from solidspy import solids_GUI # import our package + disp = solids_GUI() # run the Finite Element Analysis + plt.show() # plot contours - python example_solidspy.py +For Mac users it is suggested to use an IPython console to run the example. License @@ -162,8 +153,8 @@ Citation To cite SolidsPy in publications use - Juan Gómez, Nicolás Guarín-Zapata (2018). SolidsPy: 2D-Finite - Element Analysis with Python, . + Nicolás Guarín-Zapata, Juan Gomez (2020). SolidsPy: Version 1.0.16 + (Version v1.0.16). Zenodo. http://doi.org/10.5281/zenodo.4029270 A BibTeX entry for LaTeX users is @@ -171,12 +162,14 @@ A BibTeX entry for LaTeX users is @software{solidspy, title = {SolidsPy: 2D-Finite Element Analysis with Python}, - author = {Gómez, Juan and Guarín-Zapata, Nicolás}, - year = 2018, + version = {1.0.16}, + author = {Guarín-Zapata, Nicolás and Gómez, Juan}, + year = 2020, keywords = {Python, Finite elements, Scientific computing, Computational mechanics}, abstract = {SolidsPy is a simple finite element analysis code for 2D elasticity problems. The code uses as input simple-to-create text files defining a model in terms of nodal, element, material and load data.}, - url = {https://github.com/AppliedMechanics-EAFIT/SolidsPy} + url = {https://github.com/AppliedMechanics-EAFIT/SolidsPy}, + doi = {http://doi.org/10.5281/zenodo.4029270} } diff --git a/docs/conf.py b/docs/conf.py index 9de8422..0c74d6c 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -53,17 +53,17 @@ # General information about the project. project = 'SolidsPy' -copyright = u'2018, Juan Gómez & Nicolás Guarín-Zapata' -author = u'Juan Gómez & Nicolás Guarín-Zapata' +copyright = u'2023, Nicolás Guarín-Zapata & Juan Gómez' +author = u'Nicolás Guarín-Zapata & Juan Gómez' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. -version = '1.0' +version = '1.1' # The full version, including alpha/beta/rc tags. -release = "1.5.5" +release = '1.1.0' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -150,7 +150,7 @@ # author, documentclass [howto, manual, or own class]). latex_documents = [ (master_doc, 'SolidsPy.tex', 'SolidsPy Documentation', - u'Juan Gómez \\& Nicolás Guarín-Zapata', 'manual'), + u'Nicolás Guarín-Zapata \\& Juan Gómez', 'manual'), ] diff --git a/docs/readme.rst b/docs/readme.rst index 72a3355..251a438 100644 --- a/docs/readme.rst +++ b/docs/readme.rst @@ -1 +1,175 @@ -.. include:: ../README.rst +SolidsPy: 2D-Finite Element Analysis with Python +================================================ + +.. figure:: https://raw.githubusercontent.com/AppliedMechanics-EAFIT/SolidsPy/master/docs/img/wrench.png + :alt: Wrench under bending. + +.. image:: https://img.shields.io/pypi/v/solidspy.svg + :target: https://pypi.python.org/pypi/continuum_mechanics + :alt: PyPI download + +.. image:: https://readthedocs.org/projects/solidspy/badge/?version=latest + :target: https://solidspy.readthedocs.io/en/latest/ + :alt: Documentation Status + +.. image:: https://img.shields.io/pypi/dm/solidspy + :target: https://pypistats.org/packages/solidspy + :alt: Downloads frequency + +.. image:: https://zenodo.org/badge/48294591.svg + :target: https://zenodo.org/badge/latestdoi/48294591 + + +A simple finite element analysis code for 2D elasticity problems. +The code uses as input simple-to-create text files +defining a model in terms of nodal, element, material and load data. + +- Documentation: http://solidspy.readthedocs.io +- GitHub: https://github.com/AppliedMechanics-EAFIT/SolidsPy +- PyPI: https://pypi.org/project/solidspy/ +- Free and open source software: `MIT license `__ + + + +Features +-------- + +* It is based on an open-source environment. + +* It is easy to use. + +* The code allows to find displacement, strain and stress solutions for + arbitrary two-dimensional domains discretized into finite elements and + subject to point loads. + +* The code is organized in independent modules for pre-processing, assembly and + post-processing allowing the user to easily modify it or add features like + new elements or analyses pipelines. + +* It was created with academic and research purposes. + +* It has been used to tech the following courses: + + - Computational Modeling. + - Introduction to the Finite Element Methods. + + +Installation +------------ + +The code is written in Python and it depends on ``numpy``, and ``scipy`` +and. It has been tested under Windows, Mac, Linux and Android. + +To install *SolidsPy* open a terminal and type: + +:: + + pip install solidspy + +To specify through a GUI the folder where the input +files are stored you will need to install `easygui `__. + +To easily generate the required SolidsPy text files out of a +`Gmsh `__ model you will need +`meshio `__. + +These two can be installed with: + +:: + + pip install easygui + pip install meshio + + +How to run a simple model +------------------------- + +For further explanation check the `docs `__. + +Let's suppose that we have a simple model represented by the following +files (see `tutorials/square example `__ +for further explanation). + + +- ``nodes.txt`` + +:: + + 0 0.00 0.00 0 -1 + 1 2.00 0.00 0 -1 + 2 2.00 2.00 0 0 + 3 0.00 2.00 0 0 + 4 1.00 0.00 -1 -1 + 5 2.00 1.00 0 0 + 6 1.00 2.00 0 0 + 7 0.00 1.00 0 0 + 8 1.00 1.00 0 0 + +- ``eles.txt`` + +:: + + 0 1 0 0 4 8 7 + 1 1 0 4 1 5 8 + 2 1 0 7 8 6 3 + 3 1 0 8 5 2 6 + +- ``mater.txt`` + +:: + + 1.0 0.3 + +- ``loads.txt`` + +:: + + 3 0.0 1.0 + 6 0.0 2.0 + 2 0.0 1.0 + +Run it in Python as follows: + +.. code:: python + + import matplotlib.pyplot as plt # load matplotlib + from solidspy import solids_GUI # import our package + disp = solids_GUI() # run the Finite Element Analysis + plt.show() # plot contours + +For Mac users it is suggested to use an IPython console to run the example. + + +License +------- + +This project is licensed under the `MIT +license `__. The documents are +licensed under `Creative Commons Attribution +License `__. + +Citation +-------- + +To cite SolidsPy in publications use + + Nicolás Guarín-Zapata, Juan Gomez (2023). SolidsPy: Version 1.1.0 + (Version v1.1.0). Zenodo. + +A BibTeX entry for LaTeX users is + +.. code:: bibtex + + @software{solidspy, + title = {SolidsPy: 2D-Finite Element Analysis with Python}, + version = {1.1.0}, + author = {Guarín-Zapata, Nicolás and Gómez, Juan}, + year = 2023, + keywords = {Python, Finite elements, Scientific computing, Computational mechanics}, + abstract = {SolidsPy is a simple finite element analysis code for + 2D elasticity problems. The code uses as input simple-to-create text + files defining a model in terms of nodal, element, material and + load data.}, + url = {https://github.com/AppliedMechanics-EAFIT/SolidsPy}, + doi = {http://doi.org/10.5281/zenodo.4029270} + } diff --git a/src/solidspy/__init__.py b/src/solidspy/__init__.py index c99cc58..6af58bf 100755 --- a/src/solidspy/__init__.py +++ b/src/solidspy/__init__.py @@ -11,13 +11,12 @@ "uelutil", "solids_GUI"] -__version__ = "1.5.5" - +__version__ = "1.1.0" __citation__ = """@software{solidspy, title = {SolidsPy: 2D-Finite Element Analysis with Python}, - author = {Gómez, Juan and Guarín-Zapata, Nicolás}, - year = 2018, + author = {Guarín-Zapata, Nicolás and Gómez, Juan}, + year = 2023, keywords = {Python, Finite elements, Scientific computing, Computational mechanics}, abstract = {SolidsPy is a simple finite element analysis code for 2D elasticity problems. The code uses as input simple-to-create text diff --git a/tests/test_femutil.py b/tests/test_femutil.py index b8fe853..7d3ba6d 100755 --- a/tests/test_femutil.py +++ b/tests/test_femutil.py @@ -9,28 +9,31 @@ #%% Tests for Shape functions and derivatives -def test_shape_tri3(): +result = np.eye(3) +@pytest.mark.parametrize("r, s, res",[ + [0.0, 0.0,result[0]], + [1.0, 0.0,result[1]], + [0.0, 1.0,result[2]] +]) +def test_shape_tri3(r,s,res): # Interpolation condition check - coords = np.array([ - [0.0, 0.0], - [1.0, 0.0], - [0.0, 1.0]]) - N, _ = fem.shape_tri3(coords[:, 0], coords[:, 1]) - assert np.allclose(N, np.eye(3)) - - -def test_shape_tri6(): + N, _ = fem.shape_tri3(r,s) + assert np.allclose(N,res) + +result = np.eye(6) +@pytest.mark.parametrize("r, s, res",[ + [0.0, 0.0,result[0]], + [1.0, 0.0,result[1]], + [0.0, 1.0,result[2]], + [0.5, 0.0,result[3]], + [0.5, 0.5,result[4]], + [0.0, 0.5,result[5]]]) +def test_shape_tri6_N(r,s,res): # Interpolation condition check - coords = np.array([ - [0.0, 0.0], - [1.0, 0.0], - [0.0, 1.0], - [0.5, 0.0], - [0.5, 0.5], - [0.0, 0.5]]) - N, _ = fem.shape_tri6(coords[:, 0], coords[:, 1]) - assert np.allclose(N, np.eye(6)) + N, _ = fem.shape_tri6(r,s) + assert np.allclose(N, res) +def test_shape_tri6_dNdr(): # Evaluation at (1/3, 1/3) N, dNdr = fem.shape_tri6(1/3, 1/3) N_exp = np.array([-1., -1., -1., 4., 4., 4.])/9 @@ -40,38 +43,41 @@ def test_shape_tri6(): assert np.allclose(N, N_exp) assert np.allclose(dNdr, dNdr_exp) - -def test_shape_quad4(): +result = np.eye(4) +@pytest.mark.parametrize("r, s, res",[ + [-1.0, -1.0,result[0]], + [1.0, -1.0,result[1]], + [1.0, 1.0,result[2]], + [-1.0, 1.0,result[3]]]) +def test_shape_quad4_N(r,s,res): # Interpolation condition check - coords = np.array([ - [-1.0, -1.0], - [1.0, -1.0], - [1.0, 1.0], - [-1.0, 1.0]]) - N, _ = fem.shape_quad4(coords[:, 0], coords[:, 1]) - assert np.allclose(N, np.eye(4)) + N, _ = fem.shape_quad4(r,s) + assert np.allclose(N, res) +def test_shape_quad4_dNdr(): # For point (0, 0) N, _ = fem.shape_quad4(0, 0) N_ex = 0.25 * np.array([[1, 1, 1, 1]]) assert np.allclose(N, N_ex) -def test_shape_quad9(): +result = np.eye(9) +@pytest.mark.parametrize("r, s, res",[ + [-1.0, -1.0,result[0]], + [ 1.0, -1.0,result[1]], + [ 1.0, 1.0,result[2]], + [-1.0, 1.0,result[3]], + [ 0.0, -1.0,result[4]], + [ 1.0, 0.0,result[5]], + [ 0.0, 1.0,result[6]], + [-1.0, 0.0,result[7]], + [ 0.0, 0.0,result[8]]]) +def test_shape_quad9_N(r,s,res): # Interpolation condition check - coords = np.array([ - [-1.0, -1.0], - [ 1.0, -1.0], - [ 1.0, 1.0], - [-1.0, 1.0], - [ 0.0, -1.0], - [ 1.0, 0.0], - [ 0.0, 1.0], - [-1.0, 0.0], - [ 0.0, 0.0]]) - N, _ = fem.shape_quad9(coords[:, 0], coords[:, 1]) - assert np.allclose(N, np.eye(9)) + N, _ = fem.shape_quad9(r, s) + assert np.allclose(N, res) +def test_shape_quad9_dNdr(): # Evaluation at (1/4, 1/4) N, dNdr = fem.shape_quad9(0.25, 0.25) N_exp = np.array( @@ -87,47 +93,49 @@ def test_shape_quad9(): assert np.allclose(N, N_exp) assert np.allclose(dNdr, dNdr_exp) - -def test_shape_quad8(): +result = np.eye(8) +@pytest.mark.parametrize("r, s, res",[ + [-1.0, -1.0,result[0]], + [ 1.0, -1.0,result[1]], + [ 1.0, 1.0,result[2]], + [-1.0, 1.0,result[3]], + [ 0.0, -1.0,result[4]], + [ 1.0, 0.0,result[5]], + [ 0.0, 1.0,result[6]], + [-1.0, 0.0,result[7]]]) +def test_shape_quad8(r,s,res): # Interpolation condition check - coords = np.array([ - [-1.0, -1.0], - [ 1.0, -1.0], - [ 1.0, 1.0], - [-1.0, 1.0], - [ 0.0, -1.0], - [ 1.0, 0.0], - [ 0.0, 1.0], - [-1.0, 0.0]]) - N, _ = fem.shape_quad8(coords[:, 0], coords[:, 1]) - assert np.allclose(N, np.eye(8)) + N, _ = fem.shape_quad8(r,s) + assert np.allclose(N, res) # 3D elements -def test_shape_tet4(): +result = np.eye(4) +@pytest.mark.parametrize("r, s, t, res",[ + [0.0, 0.0, 0.0,result[0]], + [1.0, 0.0, 0.0,result[1]], + [0.0, 1.0, 0.0,result[2]], + [0.0, 0.0, 1.0,result[3]] +]) +def test_shape_tet4(r,s,t,res): # Interpolation condition check - coords = np.array([ - [0.0, 0.0, 0.0], - [1.0, 0.0, 0.0], - [0.0, 1.0, 0.0], - [0.0, 0.0, 1.0]]) - N, _ = fem.shape_tet4(coords[:, 0], coords[:, 1], coords[:, 2]) - assert np.allclose(N, np.eye(4)) - - -def test_shape_hex(): + N, _ = fem.shape_tet4(r, s, t) + assert np.allclose(N, res) + +result = np.eye(8) +@pytest.mark.parametrize("r, s, t, res",[ + [-1.0, -1.0, -1.0,result[0]], + [ 1.0, -1.0, -1.0,result[1]], + [ 1.0, 1.0, -1.0,result[2]], + [-1.0, 1.0, -1.0,result[3]], + [-1.0, -1.0, 1.0,result[4]], + [ 1.0, -1.0, 1.0,result[5]], + [ 1.0, 1.0, 1.0,result[6]], + [-1.0, 1.0, 1.0,result[7]]]) +def test_shape_hex(r,s,t,res): # Interpolation condition check - coords = np.array([ - [-1.0, -1.0, -1.0], - [ 1.0, -1.0, -1.0], - [ 1.0, 1.0, -1.0], - [-1.0, 1.0, -1.0], - [-1.0, -1.0, 1.0], - [ 1.0, -1.0, 1.0], - [ 1.0, 1.0, 1.0], - [-1.0, 1.0, 1.0]]) - N, _ = fem.shape_hex8(coords[:, 0], coords[:, 1], coords[:, 2]) - assert np.allclose(N, np.eye(8)) + N, _ = fem.shape_hex8(r, s, t) + assert np.allclose(N, res) #%% Jacobian