{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "3a4b7e63-10d0-4af2-bc97-5360ea402ff5", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import akantu as aka" ] }, { "cell_type": "code", "execution_count": 2, "id": "91261137-56d5-49b9-b386-dfb54d40da2a", "metadata": {}, "outputs": [], "source": [ "# import subprocess\n", "\n", "# ret = subprocess.run(\"gmsh -3 -order 1 -o out.msh in.geo\", shell=True)\n", "# if ret.returncode:\n", "# print(\"Beware, gmsh could not run: mesh is not regenerated\")\n", "# else:\n", "# print(\"Mesh generated\")" ] }, { "cell_type": "code", "execution_count": 3, "id": "c1339e28-e6b1-4155-b25e-f3b848025838", "metadata": {}, "outputs": [], "source": [ "material_file = \"\"\"\n", "material elastic [\n", " name = steel\n", " rho = 7800 # density\n", " E = 210e6 # young's modulus\n", " nu = 0.3 # poisson's ratio\n", "]\"\"\"\n", "# writing the material file\n", "open('material.dat', 'w').write(material_file)\n", "#reading the material file\n", "material_file = 'material.dat'" ] }, { "cell_type": "code", "execution_count": 4, "id": "30c1bb68-80b2-41ea-9aa6-a08daf741c9b", "metadata": {}, "outputs": [], "source": [ "aka.parseInput(material_file)\n", "\n", "spatial_dimension = 3\n", "mesh = aka.Mesh(spatial_dimension)\n", "mesh.read('cube.msh')\n", "\n", "model = aka.SolidMechanicsModel(mesh)\n", "model.initFull(_analysis_method=aka._static)" ] }, { "cell_type": "code", "execution_count": 5, "id": "9bb306b5-2e9c-4b3e-aaeb-347e7a1ee5f8", "metadata": {}, "outputs": [], "source": [ "for dir in [aka._x, aka._y, aka._z]:\n", " model.applyBC(aka.FixedValue(0.0, dir), \"bottom\")\n", "\n", "# trac = np.eye(3)\n", "trac = [0, 0, 1e8]\n", "model.applyBC(aka.FromTraction(trac), \"top\")\n", "np.set_printoptions(threshold=10)\n" ] }, { "cell_type": "code", "execution_count": 6, "id": "4d56ac9e-37db-48d3-8366-f8f8cb000bb6", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "steel = model.getMaterial('steel')\n", "steel" ] }, { "cell_type": "code", "execution_count": 7, "id": "845b08f6-cda8-4a72-8fa0-f1ba47fb432f", "metadata": {}, "outputs": [], "source": [ "solver = model.getNonLinearSolver()\n", "solver.set(\"max_iterations\", 6)\n", "solver.set(\"threshold\", 1e-8)\n", "solver.set(\"convergence_type\", aka.SolveConvergenceCriteria.residual)\n", "\n", "model.solveStep()" ] }, { "cell_type": "code", "execution_count": 10, "id": "2a96374a-1ade-42cf-8024-69c1dd27f02e", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "24" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mesh.getConnectivity(aka._tetrahedron_4)\n", "stress_field = model.getMaterial(0).getStress(aka._tetrahedron_4)\n", "np.set_printoptions(threshold=100)\n", "stress_field\n", "mesh.getNbElement()" ] }, { "cell_type": "code", "execution_count": null, "id": "23e23201-534c-4b3b-8121-6f8504b57243", "metadata": {}, "outputs": [], "source": [ "np.argmax(stress_field,0)\n", "np.size(stress_field,0)\n", "stress_normal = stress_field[:,(0,4,8)]\n", "np.size(stress_normal,0)" ] }, { "cell_type": "code", "execution_count": null, "id": "60a70c37-31bf-48bf-a4ac-8333abd62e93", "metadata": {}, "outputs": [], "source": [ "# specify what field to output into paraview files\n", "model.setBaseName(\"cube\")\n", "model.addDumpFieldVector(\"displacement\")\n", "model.addDumpFieldVector(\"external_force\")\n", "model.addDumpField(\"strain\")\n", "model.addDumpField(\"stress\")\n", "model.addDumpField(\"blocked_dofs\")\n", "\n", "model.dump()" ] }, { "cell_type": "code", "execution_count": null, "id": "ac9c3e33-7117-4809-a433-3e7fef3a3344", "metadata": {}, "outputs": [], "source": [ "import pyvista as pv\n", "\n", "p = pv.Plotter(off_screen=False, notebook=False)\n", "p.background_color = 'white'\n", "\n", "cyl_msh = pv.read(f'paraview/cube_{0:04d}.pvtu')\n", "cyl_msh.set_active_scalars('displacement')\n", "cyl_warped = cyl_msh.warp_by_vector('displacement')\n", "cyl_warped.set_active_scalars('displacement')\n", "\n", "cyl_warped.plot()\n" ] }, { "cell_type": "code", "execution_count": null, "id": "738e4f52-bea5-4ae3-9454-2456af57c208", "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.8.10" } }, "nbformat": 4, "nbformat_minor": 5 }