diff --git a/examples/structural_mechanics/python_interface/.gitignore b/examples/structural_mechanics/python_interface/.gitignore new file mode 100644 index 000000000..848ba680f --- /dev/null +++ b/examples/structural_mechanics/python_interface/.gitignore @@ -0,0 +1,2 @@ +.ipynb_checkpoints +*.so diff --git a/examples/structural_mechanics/python_interface/_bernoulli_beam_2.msh b/examples/structural_mechanics/python_interface/_bernoulli_beam_2.msh new file mode 100644 index 000000000..f2cd27e88 --- /dev/null +++ b/examples/structural_mechanics/python_interface/_bernoulli_beam_2.msh @@ -0,0 +1,14 @@ +$MeshFormat +2.2 0 8 +$EndMeshFormat +$Nodes +3 +1 0 0 0 +2 10 0 0 +3 18 0 0 +$EndNodes +$Elements +2 +1 1 2 0 1 1 2 +2 1 2 0 1 2 3 +$EndElements diff --git a/examples/structural_mechanics/python_interface/structural_mechanics_python_interface_test.ipynb b/examples/structural_mechanics/python_interface/structural_mechanics_python_interface_test.ipynb new file mode 100644 index 000000000..31b08e9a1 --- /dev/null +++ b/examples/structural_mechanics/python_interface/structural_mechanics_python_interface_test.ipynb @@ -0,0 +1,355 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Test of Structural Mechanics\n", + "We will now test the python interface of teh structural mechanics part.\n", + "For that we will use the test `test/test_model/test_structural_mechanics_model/test_structural_mechanics_model_bernoulli_beam_2.cc`, which we will simply reproduce.\n" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import py11_akantu as pyaka" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Creating the Mesh" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "# Create a mesh for the two dimensional case\n", + "beam = pyaka.Mesh(2)" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "# read in the mesh description\n", + "beam.read(\"_bernoulli_beam_2.msh\", pyaka.MeshIOType._miot_gmsh_struct)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Creating the Model" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "model = pyaka.StructuralMechanicsModel(beam)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Setting up the Modell" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##### Creating and Inserting the Materials" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "mat1 = pyaka.StructuralMaterial()\n", + "mat1.E = 3e10;\n", + "mat1.I = 0.0025;\n", + "mat1.A = 0.01;\n", + "model.addMaterial(mat1)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "mat2 = pyaka.StructuralMaterial()\n", + "mat2.E = 3e10;\n", + "mat2.I = 0.00128;\n", + "mat2.A = 0.01;\n", + "model.addMaterial(mat2)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##### Initializing the Model" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [], + "source": [ + "#model.initFull(pyaka.AnalysisMethod._static)\n", + "model.initFull()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##### Assigning the Materials" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [], + "source": [ + "materials = model.getElementMaterialMap(pyaka.ElementType._bernoulli_beam_2)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[1693225798],\n", + " [ 21951]], dtype=uint32)" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "materials" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Once we have written to the `materials` variable, everything becomes unstable.\n", + "And the kernel will die." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "materials[0][0] = 0\n", + "materials[1][0] = 1" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "materials" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##### Setting Boundaries" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "M = 3600.\n", + "q = -6000.\n", + "L = 10." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "forces = model.getExternalForce()\n", + "forces" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Neumann\n", + "forces = model.getExternalForce()\n", + "forces[2, 2] = -M\n", + "forces[0, 1] = q * L / 2\n", + "forces[0, 2] = q * L * L / 12\n", + "forces[1, 1] = q * L / 2\n", + "forces[1, 2] = -q * L * L / 12\n", + "forces" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Dirichlets\n", + "boundary = model.getBlockedDOFs()\n", + "boundary[0, :] = True\n", + "boundary[1, :] = False\n", + "boundary[2, :] = False\n", + "boundary[2, 1] = True" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "model.getExternalForce()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Solving the System" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "model.solveStep()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "disp = model.getDisplacement()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "d1 = disp[1, 2]\n", + "d2 = disp[2, 2]\n", + "d3 = disp[1, 0]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "d1, 5.6 / 4800" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.1" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +}