{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Hyperelasticity Example" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# dependencies\n", "using LFAToolkit\n", "using LinearAlgebra\n", "using Pkg\n", "Pkg.activate(\"./\")\n", "Pkg.instantiate()\n", "using Plots" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "code_folding": [ 20, 49 ] }, "outputs": [], "source": [ "# setup\n", "mesh = Mesh3D(1.0, 1.0, 1.0)\n", "finep = 2\n", "coarsep = 1\n", "numbercomponents = 3\n", "dimension = 3\n", "finebasis = TensorH1LagrangeBasis(finep + 1, finep + 1, numbercomponents, dimension)\n", "coarsebasis = TensorH1LagrangeBasis(coarsep + 1, finep + 1, numbercomponents, dimension)\n", "ctofbasis = TensorH1LagrangeBasis(coarsep + 1, finep + 1, numbercomponents, dimension, lagrangequadrature = true)\n", "\n", "# constants\n", "E = 1E6 # Young's modulus\n", "ν = 0.3 # Poisson's ratio\n", "K = E/(3*(1 - 2*ν)) # bulk modulus\n", "λ = E*ν/((1 + ν)*(1 - 2*ν)) # Lamé parameters\n", "μ = E/(2*(1 + ν))\n", "\n", "# state\n", "gradu = [1; 2; 3]*ones(1, 3);\n", "\n", "function neohookeanweakform(deltadu::Array{Float64}, w::Array{Float64})\n", " # dP = dF S + F dS\n", "\n", " # deformation gradient\n", " F = gradu + I\n", " J = det(F)\n", " # Green-Lagrange strain tensor\n", " E = (gradu*gradu' + gradu'*gradu)/2\n", " # right Cauchy-Green tensor\n", " C = 2*E + I\n", " C_inv = C^-1\n", " # second Piola-Kirchhoff\n", " S = λ*log(J)*C_inv + 2*μ*C_inv*E\n", "\n", " # delta du\n", " deltadu = deltadu'\n", " # dF\n", " dF = deltadu + I\n", " # deltaE\n", " deltaE = (deltadu*deltadu' + deltadu'*deltadu)/2\n", " # dS\n", " dS = λ*sum(C_inv.*deltaE)*C_inv + 2*(μ - λ*log(J))*C_inv*deltaE*C_inv\n", " # dP\n", " dP = (dF*S + F*dS) * w[1]\n", "\n", " return [dP']\n", "end\n", "\n", "# linearized Neo-Hookean operators\n", "function makeoperator(basis::TensorBasis)\n", " inputs = [\n", " OperatorField(basis, [EvaluationMode.gradient], \"gradent of deformation\"),\n", " OperatorField(basis, [EvaluationMode.quadratureweights], \"quadrature weights\"),\n", " ]\n", " outputs = [\n", " OperatorField(\n", " basis,\n", " [EvaluationMode.gradient],\n", " \"test function gradient of deformation\",\n", " ),\n", " ]\n", " return Operator(neohookeanweakform, mesh, inputs, outputs)\n", "end\n", "fineoperator = makeoperator(finebasis)\n", "coarseoperator = makeoperator(coarsebasis)\n", "\n", "# Chebyshev smoother\n", "chebyshev = Chebyshev(fineoperator)\n", "\n", "# p-multigrid preconditioner\n", "multigrid =\n", " PMultigrid(fineoperator, coarseoperator, chebyshev, [ctofbasis, ctofbasis, ctofbasis])" ] } ], "metadata": { "kernelspec": { "display_name": "Julia 1.5.2", "language": "julia", "name": "julia-1.5" }, "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", "version": "1.5.2" } }, "nbformat": 4, "nbformat_minor": 4 }