- problem can be now represented using potential energy or residual

force vector, autodiff takes care of linearization

- elasticity equations are now solved using e.g. principle of minimum
  potential energy. syntax is quite good, see notebook.

- updated how to interpolate fields, by introducing function spaces.
  syntax is now good. still have to figure out how to do time derivatives

- etc. etc. tutorial is broken at the moment, i took of get_lhs and
  get_rhs because they didn't really work.
This commit is contained in:
Jukka Aho
2015-10-26 05:40:41 +02:00
parent 2c11b2b2b2
commit 016e3cd8bf
15 changed files with 1870 additions and 826 deletions
@@ -10,7 +10,7 @@
"\n",
"**Abstract**: Elasticity equations design notes.\n",
"\n",
"##Weak form\n",
"###Weak form\n",
"\n",
"Given function spaces\n",
"\\begin{align}\n",
@@ -20,6 +20,38 @@
"find $\\boldsymbol{u}\\in\\boldsymbol{\\mathcal{U}}$ such that\n",
"\\begin{equation}\n",
"\\delta\\mathcal{W}:=\\int_{\\Omega_{0}}\\rho_{0}\\ddot{\\boldsymbol{u}}\\cdot\\delta\\boldsymbol{u}\\,\\mathrm{d}V_{0}+\\int_{\\Omega_{0}}\\boldsymbol{S}:\\delta\\boldsymbol{E}\\,\\mathrm{d}V_{0}-\\int_{\\Omega_{0}}\\hat{\\boldsymbol{b}}_{0}\\cdot\\delta\\boldsymbol{u}\\,\\mathrm{d}V_{0}-\\int_{\\Gamma_{\\sigma}}\\hat{\\boldsymbol{t}}_{0}\\cdot\\delta\\boldsymbol{u}\\,\\mathrm{d}A_{0} =0 \\qquad\\forall\\delta\\boldsymbol{u}\\in\\boldsymbol{\\mathcal{V}}\n",
"\\end{equation}\n",
"\n",
"### Some formulas\n",
"\\begin{align}\n",
"J & =\\det\\left(F\\right)\\\\\n",
"I_{c} & =\\mbox{tr}\\left(C\\right)\\\\\n",
"\\mathbf{C} & =\\mathbf{F}^{\\mathrm{T}}\\mathbf{F}\\\\\n",
"\\mathbf{F} & =\\mathbf{I}+\\nabla\\mathbf{u}\\\\\n",
"\\mathbf{E} & =\\frac{1}{2}\\left(\\mathbf{F}^{\\mathrm{T}}\\mathbf{F}-\\mathbf{I}\\right)\n",
"\\end{align}\n",
"\n",
"### Potential energy\n",
"\n",
"\\begin{equation}\n",
"\\underset{u\\in\\boldsymbol{\\mathcal{U}}}{\\min}\\Pi\\left(\\mathbf{u}\\right)\n",
"\\end{equation}\n",
"\\begin{equation}\n",
"\\Pi\\left(\\mathbf{u}\\right)=\\int_{\\Omega}\\psi\\left(\\mathbf{u}\\right)-\\int_{\\Omega}\\hat{\\mathbf{b}}_{0}\\cdot\\mathbf{u}-\\int_{\\Gamma_{\\sigma}}\\hat{\\mathbf{t}}_{0}\\cdot\\mathbf{u}\\,\\mathrm{d}A_{0}\n",
"\\end{equation}\n",
"\n",
"### Material models\n",
"\n",
"https://en.wikipedia.org/wiki/Strain_energy_density_function\n",
"\n",
"Saint-Venant-Kirchhoff model https://en.wikipedia.org/wiki/Hyperelastic_material\n",
"\\begin{equation}\n",
"\\psi\\left(\\mathbf{E}\\right)=\\frac{\\lambda}{2}\\left[\\mbox{tr}\\left(\\mathbf{E}\\right)\\right]^{2}+\\mu\\mbox{tr}\\left(\\mathbf{E}^2\\right)\n",
"\\end{equation}\n",
"\n",
"neo-Hookean material https://en.wikipedia.org/wiki/Neo-Hookean_solid\n",
"\\begin{equation}\n",
"\\psi=\\frac{\\mu}{2}\\left(I_{c}-3\\right)-\\mu\\ln\\left(J\\right)+\\frac{\\lambda}{2}\\ln\\left(J\\right)^{2}\n",
"\\end{equation}"
]
},
@@ -43,8 +75,9 @@
],
"source": [
"using ForwardDiff\n",
"using JuliaFEM: Quad4, Field, FieldSet, IntegrationPoint\n",
"using JuliaFEM: interpolate, get_element, get_dbasisdX, dinterpolate\n",
"using JuliaFEM: Quad4, Field, FieldSet, IntegrationPoint, Equation, LocalAssembly\n",
"using JuliaFEM: get_element, get_basis, grad, get_integration_points\n",
"using JuliaFEM: initialize_local_assembly, calculate_local_assembly!\n",
"using Logging\n",
"using FactCheck\n",
"Logging.configure(level=DEBUG)"
@@ -60,7 +93,7 @@
{
"data": {
"text/plain": [
"CPS4"
"size (generic function with 63 methods)"
]
},
"execution_count": 3,
@@ -69,10 +102,12 @@
}
],
"source": [
"abstract Elasticity <: JuliaFEM.Equation\n",
"abstract Elasticity <: Equation\n",
"abstract PlaneElasticity <: Elasticity\n",
"abstract PlaneStressElasticity <: PlaneElasticity\n",
"\n",
"JuliaFEM.get_unknown_field_name(equation::Elasticity) = \"displacement\"\n",
"\n",
"\"\"\" Plane stress formulation for 4-node bilinear element. \"\"\"\n",
"type CPS4 <: PlaneStressElasticity\n",
" element :: Quad4\n",
@@ -87,7 +122,9 @@
" IntegrationPoint(1.0/sqrt(3.0)*[-1, 1], 1.0)]\n",
" push!(element, FieldSet(\"displacement\"))\n",
" CPS4(element, integration_points, [])\n",
"end"
"end\n",
"\n",
"JuliaFEM.size(eq::CPS4) = 8\n"
]
},
{
@@ -101,7 +138,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 25,
"metadata": {
"collapsed": false
},
@@ -109,74 +146,83 @@
{
"data": {
"text/plain": [
"has_rhs (generic function with 4 methods)"
"has_potential_energy (generic function with 2 methods)"
]
},
"execution_count": 4,
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"function get_lhs_and_rhs(equation::CPS4, ip, time)\n",
" # boilerplate code start\n",
"\"\"\"\n",
"Calculate internal energy of system. This can be\n",
"used to define own material models.\n",
"\n",
"Parameters\n",
"----------\n",
"equation\n",
" field equation we are solving\n",
"ip\n",
" integration point, which can be used to access fields\n",
"time\n",
" current time\n",
"F\n",
" deformation gradient\n",
"\n",
"Returns\n",
"-------\n",
"Internal energy of system.\n",
"\"\"\"\n",
"function calculate_internal_energy(equation::Equation, ip::IntegrationPoint, time::Number, F::Matrix)\n",
" element = get_element(equation)\n",
" geometry = element[\"geometry\"](time)\n",
" basis = FEM.get_basis(element)\n",
" dbasis = FEM.diff(basis)(ip.xi)\n",
" grad(u) = dbasis*u*inv(dbasis*geometry)\n",
" # boilerplate code end -- replace with a macro?\n",
" basis = get_basis(element)\n",
"\n",
" # interpolate fields in temporal dimension\n",
" young = element[\"youngs modulus\"](time)\n",
" poisson = element[\"poissons ratio\"](time)\n",
" displacement = element[\"displacement\"](time)\n",
"\n",
" # interpolate material in spatial dimension\n",
" young = interpolate(basis, young, ip)\n",
" poisson = interpolate(basis, poisson, ip)\n",
" # material parameters\n",
" young = basis(\"youngs modulus\", ip, time)\n",
" poisson = basis(\"poissons ratio\", ip, time)\n",
" mu = young/(2*(1+poisson))\n",
" lambda = young*poisson/((1+poisson)*(1-2*poisson))\n",
" lambda = 2*lambda*mu/(lambda + 2*mu) # <- correction for 2d\n",
"\n",
" function W(data::Vector)\n",
" Wint = 0.0\n",
" # create new field u, similar to field displacement, and fill it with data\n",
" u = similar(displacement, data)\n",
" F = I + grad(u) # deformation gradient\n",
" E = 1/2*(F'*F - I) # strain\n",
" S = 2*mu*E + lambda*trace(E)*I # stress\n",
" Wint += 1/2*trace(S*E')\n",
"\n",
" Wext = 0.0\n",
" # any volume load?\n",
" if haskey(element, \"displacement volume load\")\n",
" b = interpolate(element, \"displacement volume load\", ip, time)\n",
" δu = interpolate(basis, u, ip)\n",
" Wext += dot(b, δu)\n",
" end\n",
" return Wint - Wext\n",
" if isa(equation, PlaneStressElasticity)\n",
" lambda = 2*lambda*mu/(lambda + 2*mu) # <- correction for 2d\n",
" end\n",
"\n",
" R = ForwardDiff.gradient(W, displacement[:])\n",
" K = ForwardDiff.hessian(W, displacement[:])\n",
" return K, -R\n",
" E = 1/2*(F'*F - I) # strain\n",
" Wint = 1/2*lambda*trace(E)^2 + mu*trace(E*E')\n",
" # alternative way to calculate this:\n",
" # S = lambda*trace(E)*I + 2*mu*E\n",
" # Wint = 1/2*trace(S*E')\n",
" return Wint\n",
"end\n",
"\n",
"function JuliaFEM.get_lhs(equation::CPS4, ip, time)\n",
" get_lhs_and_rhs(equation, ip, time)[1]\n",
"end\n",
"function JuliaFEM.get_rhs(equation::CPS4, ip, time)\n",
" get_lhs_and_rhs(equation, ip, time)[2]\n",
"function JuliaFEM.get_potential_energy(equation::Elasticity, ip, time; variation=nothing)\n",
" element = get_element(equation)\n",
" basis = get_basis(element)\n",
" dbasis = grad(basis)\n",
"\n",
" u = basis(\"displacement\", ip, time, variation)\n",
" ∇u = dbasis(\"displacement\", ip, time, variation)\n",
" F = I + ∇u # deformation gradient\n",
"\n",
" # internal energy\n",
" Wint = calculate_internal_energy(equation, ip, time, F)\n",
"\n",
" # external energy -- any volume load?\n",
" Wext = 0.0\n",
" if haskey(element, \"displacement volume load\")\n",
" b = basis(\"displacement volume load\", ip, time)\n",
" Wext += dot(b, u)\n",
" end\n",
"\n",
" return Wint - Wext\n",
"end\n",
"\n",
"JuliaFEM.has_lhs(equation::CPS4) = true\n",
"JuliaFEM.has_rhs(equation::CPS4) = true"
"JuliaFEM.has_potential_energy(equation::CPS4) = true"
]
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 26,
"metadata": {
"collapsed": false
},
@@ -185,19 +231,8 @@
"name": "stdout",
"output_type": "stream",
"text": [
"testing primary field with point load versus code aster solution\n",
"increment 1, norm = 5.77653, Wint = 0.000, Wext = 81.525, |Wint-Wext| = 81.52516\n",
"increment 2, norm = 0.99988, Wint = 173.895, Wext = 79.037, |Wint-Wext| = 94.85823\n",
"increment 3, norm = 0.28354, Wint = 87.084, Wext = 82.175, |Wint-Wext| = 4.90953\n",
"increment 4, norm = 0.07071, Wint = 82.548, Wext = 83.100, |Wint-Wext| = 0.55141\n",
"increment 5, norm = 0.00082, Wint = 83.116, Wext = 83.109, |Wint-Wext| = 0.00644\n",
"increment 6, norm = 0.00000, Wint = 83.109, Wext = 83.109, |Wint-Wext| = 0.00000\n",
"increment 7, norm = 0.00000, Wint = 83.109, Wext = 83.109, |Wint-Wext| = 0.00000\n",
"increment 8, norm = 0.00000, Wint = 83.109, Wext = 83.109, |Wint-Wext| = 0.00000\n",
"increment 9, norm = 0.00000, Wint = 83.109, Wext = 83.109, |Wint-Wext| = 0.00000\n",
"increment 10, norm = 0.00000, Wint = 83.109, Wext = 83.109, |Wint-Wext| = 0.00000\n",
"elapsed time: 4.257759666 seconds\n",
"1 fact verified.\n"
"testing primary field with nodal load versus code aster solution\n",
"increment "
]
},
{
@@ -206,50 +241,65 @@
"delayed_handler (generic function with 4 methods)"
]
},
"execution_count": 5,
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" 1, |du| = 5.77653\n",
"increment 2, |du| = 0.99988\n",
"increment 3, |du| = 0.28354\n",
"increment 4, |du| = 0.07071\n",
"increment 5, |du| = 0.00082\n",
"increment 6, |du| = 0.00000\n",
"increment 7, |du| = 0.00000\n",
"increment 8, |du| = 0.00000\n",
"increment 9, |du| = 0.00000\n",
"increment 10, |du| = 0.00000\n",
"elapsed time: 0.03522289 seconds\n",
"1 fact verified.\n"
]
}
],
"source": [
"facts(\"testing primary field with point load versus code aster solution\") do\n",
"facts(\"testing primary field with nodal load versus code aster solution\") do\n",
" element = Quad4([1, 2, 3, 4])\n",
" push!(element, FieldSet(\"geometry\", [Field(0.0, Vector[[0.0, 0.0], [10.0, 0.0], [10.0, 1.0], [0.0, 1.0]])]))\n",
" push!(element, FieldSet(\"youngs modulus\", [Field(0.0, 500.0)]))\n",
" push!(element, FieldSet(\"poissons ratio\", [Field(0.0, 0.3)]))\n",
" push!(element, FieldSet(\"displacement nodal load\", [Field(0.0, Vector[[0.0, 0.0], [0.0, 0.0], [0.0, -20.0], [0.0, 0.0]])]))\n",
" equation = CPS4(element)\n",
"\n",
" \n",
" u0 = Field(0.0, Vector[[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]])\n",
" push!(element[\"displacement\"], u0)\n",
" u = zeros(8)\n",
" du = zeros(8)\n",
" fd = [3, 4, 5, 6]\n",
" f = zeros(8)\n",
" f[6] = -20.0\n",
" la = initialize_local_assembly(equation)\n",
" tic()\n",
" for i=1:10\n",
" A = JuliaFEM.integrate_lhs(equation, 1.0)\n",
" b = JuliaFEM.integrate_rhs(equation, 1.0)\n",
" du[fd] = A[fd,fd] \\ (b[fd]+f[fd])\n",
" la = initialize_local_assembly(equation, la)\n",
" calculate_local_assembly!(la, equation)\n",
" du[fd] = la.stiffness_matrix[fd,fd] \\ la.force_vector[fd]\n",
" u += du\n",
" new_field = similar(u0, u)\n",
" new_field.time = 1.0\n",
" new_field.increment = i\n",
" push!(element[\"displacement\"], new_field)\n",
" Wint = (-b'*u)[1]\n",
" Wext = (f'*u)[1]\n",
" W = abs(Wint-Wext)\n",
" @printf(\"increment %2d, norm = %8.5f, Wint = %8.3f, Wext = %8.3f, |Wint-Wext| = %8.5f\\n\", i, norm(du), Wint, Wext, W)\n",
" @printf(\"increment %2d, |du| = %8.5f\\n\", i, norm(du))\n",
" end\n",
" toc()\n",
" # verified using Code Aster.\n",
" @fact interpolate(element, \"displacement\", [1.0, 1.0], Inf)[2] --> roughly(-4.15546385452579E+00)\n",
" @fact get_basis(element)(\"displacement\", [1.0, 1.0])[2] --> roughly(-4.15546385452579E+00)\n",
"end"
]
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 27,
"metadata": {
"collapsed": false
},
@@ -259,7 +309,7 @@
"output_type": "stream",
"text": [
"testing primary field with volume load versus code aster solution\n",
"increment "
"increment "
]
},
{
@@ -268,7 +318,7 @@
"delayed_handler (generic function with 4 methods)"
]
},
"execution_count": 6,
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
},
@@ -276,17 +326,17 @@
"name": "stdout",
"output_type": "stream",
"text": [
"1, norm = 14.44128, Wint = -509.167, Wext = 0.000, |Wint-Wext| = 509.16667\n",
"increment 2, norm = 4.01742, Wint = 4335.728, Wext = 0.000, |Wint-Wext| = 4335.72801\n",
"increment 3, norm = 1.54645, Wint = 705.913, Wext = 0.000, |Wint-Wext| = 705.91292\n",
"increment 4, norm = 1.12361, Wint = 60.492, Wext = 0.000, |Wint-Wext| = 60.49208\n",
"increment 5, norm = 0.79119, Wint = -1.486, Wext = 0.000, |Wint-Wext| = 1.48555\n",
"increment 6, norm = 0.12733, Wint = 5.743, Wext = 0.000, |Wint-Wext| = 5.74331\n",
"increment 7, norm = 0.00725, Wint = 0.080, Wext = 0.000, |Wint-Wext| = 0.07997\n",
"increment 8, norm = 0.00001, Wint = 0.000, Wext = 0.000, |Wint-Wext| = 0.00045\n",
"increment 9, norm = 0.00000, Wint = 0.000, Wext = 0.000, |Wint-Wext| = 0.00000\n",
"increment 10, norm = 0.00000, Wint = 0.000, Wext = 0.000, |Wint-Wext| = 0.00000\n",
"elapsed time: 0.068575305 seconds\n",
" 1, |du| = 14.44128\n",
"increment 2, |du| = 4.01742\n",
"increment 3, |du| = 1.54645\n",
"increment 4, |du| = 1.12361\n",
"increment 5, |du| = 0.79119\n",
"increment 6, |du| = 0.12733\n",
"increment 7, |du| = 0.00725\n",
"increment 8, |du| = 0.00001\n",
"increment 9, |du| = 0.00000\n",
"increment 10, |du| = 0.00000\n",
"elapsed time: 0.004752839 seconds\n",
"1 fact verified.\n"
]
}
@@ -306,26 +356,22 @@
" u = zeros(8)\n",
" du = zeros(8)\n",
" fd = [3, 4, 5, 6]\n",
" f = zeros(8)\n",
" f[6] = -20.0*0\n",
" la = initialize_local_assembly(equation)\n",
" tic()\n",
" for i=1:10\n",
" A = JuliaFEM.integrate_lhs(equation, 1.0)\n",
" b = JuliaFEM.integrate_rhs(equation, 1.0)\n",
" du[fd] = A[fd,fd] \\ (b[fd]+f[fd])\n",
" la = initialize_local_assembly(equation, la)\n",
" calculate_local_assembly!(la, equation)\n",
" du[fd] = la.stiffness_matrix[fd,fd] \\ la.force_vector[fd]\n",
" u += du\n",
" new_field = similar(u0, u)\n",
" new_field.time = 1.0\n",
" new_field.increment = i\n",
" push!(element[\"displacement\"], new_field)\n",
" Wint = (-b'*u)[1]\n",
" Wext = (f'*u)[1]\n",
" W = abs(Wint-Wext)\n",
" @printf(\"increment %2d, norm = %8.5f, Wint = %8.3f, Wext = %8.3f, |Wint-Wext| = %8.5f\\n\", i, norm(du), Wint, Wext, W)\n",
" @printf(\"increment %2d, |du| = %8.5f\\n\", i, norm(du))\n",
" end\n",
" toc()\n",
" # verified using Code Aster.\n",
" @fact interpolate(element, \"displacement\", [1.0, 1.0], Inf)[2] --> roughly(-8.77303119819776E+00)\n",
" @fact get_basis(element)(\"displacement\", [1.0, 1.0])[2] --> roughly(-8.77303119819776E+00)\n",
"end"
]
},
@@ -333,104 +379,14 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Method 2, Voigt notation, analytical linearization"
"### Method 2, Voigt notation, analytical linearization\n",
"\n",
"I think I don't need to mention which way is more elegant. Here's the linearization of system is done manually anyway, maybe it has better performance."
]
},
{
"cell_type": "code",
"execution_count": 170,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"get_rhs (generic function with 6 methods)"
]
},
"execution_count": 170,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"function get_lhs_and_rhs(equation::CPS4, ip, time)\n",
" element = get_element(equation)\n",
"\n",
" # fields\n",
" X = element[\"geometry\"](time)\n",
" u = element[\"displacement\"](time)\n",
" young = element[\"young\"](time)\n",
" poisson = element[\"poisson\"](time)\n",
"\n",
" # material\n",
" N = FEM.get_basis(element)\n",
" young = interpolate(N, young, ip)\n",
" poisson = interpolate(N, poisson, ip)\n",
"\n",
" dN = FEM.diff(N)(ip.xi)\n",
" invJ = inv(dN*X)\n",
" dNdX = dN*invJ\n",
"\n",
" # kinematics\n",
" gradu = dN*u*invJ\n",
" F = I + gradu # deformation gradient\n",
" E = 1/2*(F'*F - I) # GL strain tensor\n",
" E = [E[1,1], E[2,2], E[1,2]*2] # go to Voigt\n",
"\n",
" # constitutive equations\n",
" D = young/(1-poisson^2) * [1 poisson 0; poisson 1 0; 0 0 1/2*(1-poisson)]\n",
" S = D*E\n",
" T = zeros(4, 4)\n",
" T[1,1] = S[1]\n",
" T[2,2] = S[2]\n",
" T[1,2] = T[2,1] = S[3]\n",
" T[3:4,3:4] = T[1:2,1:2]\n",
"\n",
" # linear part\n",
" B_L = zeros(3, 8)\n",
" for i=1:4\n",
" B_L[1, 2*(i-1)+1] = F[1,1]*dNdX[i,1]\n",
" B_L[1, 2*(i-1)+2] = F[2,1]*dNdX[i,1]\n",
" B_L[2, 2*(i-1)+1] = F[1,2]*dNdX[i,2]\n",
" B_L[2, 2*(i-1)+2] = F[2,2]*dNdX[i,2]\n",
" B_L[3, 2*(i-1)+1] = F[1,1]*dNdX[i,2] + F[1,2]*dNdX[i,1]\n",
" B_L[3, 2*(i-1)+2] = F[2,1]*dNdX[i,2] + F[2,2]*dNdX[i,1]\n",
" end\n",
" K_L = B_L'*D*B_L\n",
"\n",
" # nonlinear part\n",
" B_NL = zeros(4, 8)\n",
" for i=1:4\n",
" B_NL[1, 2*(i-1)+1] = dNdX[i,1]\n",
" B_NL[2, 2*(i-1)+1] = dNdX[i,2]\n",
" B_NL[3, 2*(i-1)+2] = dNdX[i,1]\n",
" B_NL[4, 2*(i-1)+2] = dNdX[i,2]\n",
" end\n",
" K_NL = B_NL'*T*B_NL\n",
"\n",
" fint = B_L'*S\n",
"\n",
" R = fint\n",
" Kt = K_L + K_NL\n",
"\n",
" print('.')\n",
" \n",
" return Kt, -R\n",
"end\n",
"\n",
"function JuliaFEM.get_lhs(equation::CPS4, ip, time)\n",
" get_lhs_and_rhs(equation, ip, time)[1]\n",
"end\n",
"function JuliaFEM.get_rhs(equation::CPS4, ip, time)\n",
" get_lhs_and_rhs(equation, ip, time)[2]\n",
"end"
]
},
{
"cell_type": "code",
"execution_count": 172,
"execution_count": 24,
"metadata": {
"collapsed": false
},
@@ -439,24 +395,17 @@
"name": "stdout",
"output_type": "stream",
"text": [
".."
"testing primary field with nodal load versus code aster solution\n",
"increment "
]
},
{
"data": {
"text/plain": [
"8x8 Array{Float64,2}:\n",
" 119.461 13.486 61.8587 … -26.0246 -113.693 2.80625\n",
" 13.486 309.576 15.6443 -148.518 -3.10973 -316.14 \n",
" 61.8587 15.6443 130.663 -53.2776 -60.0524 1.57406\n",
" 9.73233 155.082 36.0593 -303.877 1.51267 -163.427 \n",
" -67.6267 -26.0206 -132.47 63.0312 56.539 10.2937 \n",
" -26.0246 -148.518 -53.2776 … 299.439 16.271 152.956 \n",
" -113.693 -3.10973 -60.0524 16.271 117.207 -14.674 \n",
" 2.80625 -316.14 1.57406 152.956 -14.674 326.611 "
"delayed_handler (generic function with 4 methods)"
]
},
"execution_count": 172,
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
},
@@ -464,70 +413,143 @@
"name": "stdout",
"output_type": "stream",
"text": [
".."
" 1, |du| = 5.77653\n",
"increment 2, |du| = 1.05083\n",
"increment 3, |du| = 0.39176\n",
"increment 4, |du| = 0.21527\n",
"increment 5, |du| = 0.16285\n",
"increment 6, |du| = 0.13115\n",
"increment 7, |du| = 0.10774\n",
"increment 8, |du| = 0.08994\n",
"increment 9, |du| = 0.07617\n",
"increment 10, |du| = 0.06533\n",
"elapsed time: 0.004335419 seconds\n",
" Failure :: (line:-1) :: fact was false\n",
" Expression: ((get_basis(element))(\"displacement\",[1.0,1.0]))[2] --> roughly(-4.15546385452579)\n",
" Expected: -5.091745430627231 ≅ -4.15546385452579\n",
"Out of 1 total fact:\n",
" Failed: 1\n"
]
}
],
"source": [
"JuliaFEM.integrate_lhs(equation, Inf)"
]
},
{
"cell_type": "code",
"execution_count": 169,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"2.927103942720631"
]
},
"execution_count": 169,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"(1/2*u'*JuliaFEM.integrate_lhs(equation, 0.0)*u)[1]"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"get_lhs (generic function with 2 methods)"
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"\"\"\"\n",
"1-node point force element for plane stress problems.\n",
"\"\"\"\n",
"type CPS1 <: Elasticity\n",
" element :: Point1\n",
"\"\"\" Plane stress formulation for 4-node bilinear element, manual formulation. \"\"\"\n",
"type CPS4M <: PlaneStressElasticity\n",
" element :: Quad4\n",
" integration_points :: Array{IntegrationPoint, 1}\n",
" global_dofs :: Array{Int64, 1}\n",
"end\n",
"function CPS1(el::Point1)\n",
" integration_points = []\n",
" set_field(el, \"displacement\", zeros(2, 1))\n",
" set_field(el, \"displacement nodal load\", zeros(2, 1))\n",
" CPS1(el, integration_points)\n",
"function CPS4M(element::Quad4)\n",
" integration_points = [\n",
" IntegrationPoint(1.0/sqrt(3.0)*[-1, -1], 1.0),\n",
" IntegrationPoint(1.0/sqrt(3.0)*[ 1, -1], 1.0),\n",
" IntegrationPoint(1.0/sqrt(3.0)*[ 1, 1], 1.0),\n",
" IntegrationPoint(1.0/sqrt(3.0)*[-1, 1], 1.0)]\n",
" push!(element, FieldSet(\"displacement\"))\n",
" CPS4M(element, integration_points, [])\n",
"end\n",
"get_rhs(eq::CPS1) = get_field(get_element(eq), \"displacement nodal load\")\n",
"get_lhs(eq::CPS1) = None"
"\n",
"JuliaFEM.size(eq::CPS4M) = 8\n",
"\n",
"function JuliaFEM.calculate_local_assembly!(assembly::LocalAssembly, equation::CPS4M, time::Number=Inf)\n",
" initialize_local_assembly(assembly, equation)\n",
" element = get_element(equation)\n",
" basis = get_basis(element)\n",
" dbasis = grad(basis)\n",
" detJ = det(basis)\n",
" ndofs = size(equation)\n",
" nnodes = round(Int, ndofs/2)\n",
"\n",
" B_L = zeros(3, ndofs)\n",
" B_NL = zeros(4, ndofs)\n",
"\n",
" for ip in get_integration_points(equation)\n",
"\n",
" fill!(B_L, 0.0)\n",
" fill!(B_NL, 0.0)\n",
"\n",
" u = basis(\"displacement\", ip, time)\n",
" ∇u = dbasis(\"displacement\", ip, time)\n",
" young = basis(\"youngs modulus\", ip, time)\n",
" poisson = basis(\"poissons ratio\", ip, time)\n",
"\n",
" # kinematics\n",
" F = I + ∇u # deformation gradient\n",
" E = 1/2*(F'*F - I) # GL strain tensor\n",
" E = [E[1,1], E[2,2], E[1,2]*2] # go to Voigt\n",
"\n",
" # constitutive equations -- calculate stress\n",
" D = young/(1-poisson^2) * [1 poisson 0; poisson 1 0; 0 0 1/2*(1-poisson)]\n",
" S = D*E\n",
" T = zeros(4, 4)\n",
" T[1,1] = S[1]\n",
" T[2,2] = S[2]\n",
" T[1,2] = T[2,1] = S[3]\n",
" T[3:4,3:4] = T[1:2,1:2]\n",
"\n",
" dNdX = dbasis(ip, time)\n",
"\n",
" # linear part\n",
" for i=1:nnodes\n",
" B_L[1, 2*(i-1)+1] = F[1,1]*dNdX[1,i]\n",
" B_L[1, 2*(i-1)+2] = F[2,1]*dNdX[1,i]\n",
" B_L[2, 2*(i-1)+1] = F[1,2]*dNdX[2,i]\n",
" B_L[2, 2*(i-1)+2] = F[2,2]*dNdX[2,i]\n",
" B_L[3, 2*(i-1)+1] = F[1,1]*dNdX[2,i] + F[1,2]*dNdX[1,i]\n",
" B_L[3, 2*(i-1)+2] = F[2,1]*dNdX[2,i] + F[2,2]*dNdX[1,i]\n",
" end\n",
"\n",
" # nonlinear part\n",
" for i=1:nnodes\n",
" B_NL[1, 2*(i-1)+1] = dNdX[1,i]\n",
" B_NL[2, 2*(i-1)+1] = dNdX[2,i]\n",
" B_NL[3, 2*(i-1)+2] = dNdX[1,i]\n",
" B_NL[4, 2*(i-1)+2] = dNdX[2,i]\n",
" end\n",
"\n",
" s = ip.weight*detJ(ip)\n",
" assembly.stiffness_matrix += s*B_L'*D*B_L + s*B_NL'*T*B_NL\n",
" assembly.force_vector += -s*B_L'*S\n",
"\n",
" end\n",
"\n",
" if haskey(element, \"displacement nodal load\")\n",
" assembly.force_vector += element[\"displacement nodal load\"](time)[:]\n",
" end\n",
"\n",
"end\n",
"\n",
"facts(\"testing primary field with nodal load versus code aster solution\") do\n",
" element = Quad4([1, 2, 3, 4])\n",
" push!(element, FieldSet(\"geometry\", [Field(0.0, Vector[[0.0, 0.0], [10.0, 0.0], [10.0, 1.0], [0.0, 1.0]])]))\n",
" push!(element, FieldSet(\"youngs modulus\", [Field(0.0, 500.0)]))\n",
" push!(element, FieldSet(\"poissons ratio\", [Field(0.0, 0.3)]))\n",
" push!(element, FieldSet(\"displacement nodal load\", [Field(0.0, Vector[[0.0, 0.0], [0.0, 0.0], [0.0, -20.0], [0.0, 0.0]])]))\n",
" equation = CPS4M(element)\n",
" \n",
" u0 = Field(0.0, Vector[[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]])\n",
" push!(element[\"displacement\"], u0)\n",
" u = zeros(8)\n",
" du = zeros(8)\n",
" \n",
" fd = [3, 4, 5, 6]\n",
" la = initialize_local_assembly(equation)\n",
" tic()\n",
" for i=1:10\n",
" la = initialize_local_assembly(equation, la)\n",
" calculate_local_assembly!(la, equation)\n",
" du[fd] = la.stiffness_matrix[fd,fd] \\ la.force_vector[fd]\n",
" u += du\n",
" new_field = similar(u0, u)\n",
" new_field.time = 1.0\n",
" new_field.increment = i\n",
" push!(element[\"displacement\"], new_field)\n",
" @printf(\"increment %2d, |du| = %8.5f\\n\", i, norm(du))\n",
" end\n",
" toc()\n",
" # verified using Code Aster. Noh, toimi se eilen.\n",
" @fact get_basis(element)(\"displacement\", [1.0, 1.0])[2] --> roughly(-4.15546385452579E+00)\n",
"end"
]
},
{