Cleanup of obsolete files

A lot of old files from old documentation systems etc. is in package.
These are now removed or moved. Old notebooks are in docs/tutorials.
This PR closes issue #124.
This commit is contained in:
Jukka Aho
2017-08-05 11:44:31 +03:00
parent 3d3e9bb441
commit 0f0c49da62
47 changed files with 1723 additions and 1163 deletions
File diff suppressed because one or more lines are too long
@@ -0,0 +1,699 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Solving elasticity problems using JuliaFEM\n",
"\n",
"Author(s): Jukka Aho\n",
"\n",
"**Abstract**: Solving elasticity equations using JuliaFEM.\n",
"\n",
"### Weak form\n",
"\n",
"Given function spaces\n",
"\\begin{align}\n",
"\\boldsymbol{\\mathcal{U}} & =\\left\\{ \\boldsymbol{u}\\in H^{1}\\left(\\Omega\\right)|\\boldsymbol{u}\\left(\\boldsymbol{X},t\\right)=\\hat{\\boldsymbol{u}}\\left(\\boldsymbol{X},t\\right)\\text{ on }\\Gamma_{\\mathrm{u}}\\right\\} ,\\\\\n",
"\\boldsymbol{\\mathcal{V}} & =\\left\\{ \\delta\\boldsymbol{u}\\in H^{1}\\left(\\Omega\\right)|\\delta\\boldsymbol{u}\\left(\\boldsymbol{X}\\right)=0\\text{ on }\\Gamma_{\\mathrm{u}}\\right\\} ,\n",
"\\end{align}\n",
"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}"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"using JuliaFEM.API: Model, Material, add_material!, LoadCase, add_element_set!, ForceBC, DisplacementBC\n",
"using JuliaFEM.API: add_boundary_condition!, add_load_case!, add_solver!\n",
"using JuliaFEM.Interfaces: solve!\n",
"using JuliaFEM.Preprocess: parse_abaqus"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"INFO: Parsing nodes\n",
"INFO: Parsing elements. Type: Tet10\n",
"INFO: Parsing elements. Type: Tri6\n",
"INFO: Creating elset BC1\n",
"INFO: Creating elset BC2\n",
"INFO: model loaded.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" 4.209444 seconds (19.12 M allocations: 565.872 MB, 11.55% gc time)\n"
]
}
],
"source": [
"@time begin\n",
" # Linear models\n",
" #model = open(JuliaFEM.Core.parse_abaqus, \"../geometry/piston/piston_8789_P1.inp\")\n",
" #model = open(JuliaFEM.Core.parse_abaqus, \"../geometry/piston/piston_16436_P1.inp\")\n",
" #model = open(JuliaFEM.Core.parse_abaqus, \"../geometry/piston/piston_27343_P1.inp\")\n",
" #model = open(JuliaFEM.Core.parse_abaqus, \"../geometry/piston/piston_45510_P1.inp\")\n",
" #model = open(JuliaFEM.Core.parse_abaqus, \"../geometry/piston/piston_75470_P1.inp\")\n",
" #model = open(JuliaFEM.Core.parse_abaqus, \"../geometry/wrench/wrench_128903_P1.inp\")\n",
"\n",
" # Quadratic models\n",
" #model = open(JuliaFEM.Core.parse_abaqus, \"../geometry/piston/piston_19611_P2.inp\")\n",
" #model = open(JuliaFEM.Core.parse_abaqus, \"../geometry/piston/piston_55950_P2.inp\")\n",
" #model = open(JuliaFEM.Core.parse_abaqus, \"/Temp/piston_107168_P2.inp\")\n",
" #model = open(JuliaFEM.Core.parse_abaqus, \"../geometry/piston/piston_345757_P2.inp\")\n",
"\n",
" mesh = open(parse_abaqus, \"/Temp/piston_107168_P2.inp\")\n",
" model = Model(\"piston model\", mesh)\n",
" info(\"model loaded.\")\n",
"end"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"JuliaFEM.API.Material(\"steel\",Dict(\"poissons ratio\"=>0.3,\"youngs modulus\"=>210000.0))"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mat = Material(\"steel\")\n",
"mat[\"youngs modulus\"] = 210.0e3\n",
"mat[\"poissons ratio\"] = 0.3\n",
"add_material!(model, \"PISTON\", mat)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"1-element Array{ASCIIString,1}:\n",
" \"PISTON\""
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"simulation = LoadCase(:ElasticityProblem)\n",
"\n",
"# simulation = Simulation(:ElasticityProblem, \"elasticity equations\")\n",
"# add_element_set!(simulation, \"PISTON\")\n",
"# add_boundary_condition!(simulation, bc1, bc2)\n",
"# add_simulation!(model, simulation)\n",
"# add_solver!(simulation, :DirectSolver)\n",
"# solve!(model, \"elasticity equations\", 0.0)\n",
"# solve!(model, \"heat equations\", 0.0)\n",
"# solve!(model, \"solve equations 3\", 0.0)\n",
"\n",
"add_element_set!(simulation, \"PISTON\")"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"1-element Array{JuliaFEM.API.DirichletBC,1}:\n",
" JuliaFEM.API.DirichletBC(\"BC2\",\"displacement\"=>0.0)"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"traction = Vector{Float64}[[0.0, 0.0, -10.0] for i in 1:6]\n",
"bc1 = ForceBC(\"BC1\", \"displacement traction force\" => traction)\n",
"bc2 = DisplacementBC(\"BC2\", \"displacement\" => 0.0)\n",
"\n",
"# JuliaFEM.API.add_boundary_condition!(prob, bc1, bc2)\n",
"add_boundary_condition!(simulation, bc1)\n",
"add_boundary_condition!(simulation, bc2)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"JuliaFEM.API.LoadCase(:ElasticityProblem,[JuliaFEM.API.NeumannBC(\"BC1\",\"displacement traction force\"=>[[0.0,0.0,-10.0],[0.0,0.0,-10.0],[0.0,0.0,-10.0],[0.0,0.0,-10.0],[0.0,0.0,-10.0],[0.0,0.0,-10.0]])],[JuliaFEM.API.DirichletBC(\"BC2\",\"displacement\"=>0.0)],:DirectSolver,ASCIIString[\"PISTON\"])"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"add_solver!(simulation, :DirectSolver)\n",
"add_load_case!(model, \"elasticity equations\", simulation)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"solver = JuliaFEM.Interfaces.get_solver(model, \"elasticity equations\", 0.0);"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"JuliaFEM.Core.Element{JuliaFEM.Core.Tet10}([1,2,3,4,5,6,7,8,9,10],Dict{ASCIIString,JuliaFEM.Core.Field{A<:Union{JuliaFEM.Core.Continuous,JuliaFEM.Core.Discrete},B<:Union{JuliaFEM.Core.Constant,JuliaFEM.Core.Variable},C<:Union{JuliaFEM.Core.TimeInvariant,JuliaFEM.Core.TimeVariant}}}(\"poissons ratio\"=>JuliaFEM.Core.Field{JuliaFEM.Core.Discrete,JuliaFEM.Core.Constant,JuliaFEM.Core.TimeInvariant}(0.3),\"geometry\"=>JuliaFEM.Core.Field{JuliaFEM.Core.Discrete,JuliaFEM.Core.Variable,JuliaFEM.Core.TimeInvariant}([[13.96894,1.54855,-2.99382],[15.71724,2.88794,-2.79243],[14.76115,1.1419,-1.23125],[15.93754,1.0623,-2.82067],[14.84309,2.21825,-2.89313],[15.2392,2.01492,-2.01184],[14.36505,1.34523,-2.11254],[14.95324,1.30543,-2.90725],[15.82739,1.97512,-2.80655],[15.34935,1.1021,-2.02596]]),\"youngs modulus\"=>JuliaFEM.Core.Field{JuliaFEM.Core.Discrete,JuliaFEM.Core.Constant,JuliaFEM.Core.TimeInvariant}(210000.0)))"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"celements = solver.field_problems[1].elements;\n",
"celements[1]"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"INFO: 0 surface elements\n"
]
}
],
"source": [
"surface_elements = filter((e) -> isa(e, JuliaFEM.Core.Element{JuliaFEM.Core.Tri6}), celements)\n",
"info(\"$(length(surface_elements)) surface elements\")"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"62454"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"length(celements)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"INFO: # of field problems: 1\n",
"INFO: # of boundary problems: 1\n",
"INFO: Starting iteration 1\n",
"INFO: Assembling field problems...\n",
"INFO: Assembling body 1...\n",
"INFO: Assembly: 10.0 % done. \n",
"INFO: Assembly: 20.0 % done. \n",
"INFO: Assembly: 30.0 % done. \n",
"INFO: Assembly: 40.0 % done. \n",
"INFO: Assembly: 50.0 % done. \n",
"INFO: Assembly: 60.0 % done. \n",
"INFO: Assembly: 70.0 % done. \n",
"INFO: Assembly: 80.0 % done. \n",
"INFO: Assembly: 90.0 % done. \n",
"INFO: Assembly: 100.0 % done. \n",
"INFO: Assembling boundary problems...\n",
"INFO: Assembling boundary 1...\n",
"INFO: Assembly: 10.0 % done. \n",
"INFO: Assembly: 20.0 % done. \n",
"INFO: Assembly: 30.0 % done. \n",
"INFO: Assembly: 40.0 % done. \n",
"INFO: Assembly: 50.0 % done. \n",
"INFO: Assembly: 60.0 % done. \n",
"INFO: Assembly: 70.0 % done. \n",
"INFO: Assembly: 80.0 % done. \n",
"INFO: Assembly: 90.0 % done. \n",
"INFO: Assembly: 100.0 % done. \n",
"INFO: Solving system\n",
"INFO: all dofs = 321504\n",
"INFO: interior dofs = 312936\n",
"INFO: boundary dofs = 8568\n",
"INFO: preparation in 3.385999917984009 seconds\n",
"INFO: displacement on boundary solved.\n",
"INFO: norm[u_boundary_dofs] = 0.0\n",
"INFO: homogeneous dirichlet boundary\n",
"INFO: solve boundary = 0.42100000381469727\n",
"INFO: factorizations done in 14.133000135421753 seconds\n",
"INFO: solved interior in 0.2969999313354492 seconds. norm = 0.0\n",
"INFO: timing info for non-linear iteration:\n"
]
},
{
"data": {
"text/plain": [
"(1,true)"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"INFO: boundary assembly : 2.1679999828338623\n",
"INFO: field assembly : 279.9069998264313\n",
"INFO: dump matrices to disk : 0.0\n",
"INFO: solve problem : 19.37600016593933\n",
"INFO: update element data : 1.6999998092651367\n",
"INFO: non-linear iteration : 303.1509997844696\n",
"INFO: solver finished in 304.5089998245239 seconds.\n"
]
}
],
"source": [
"solve!(model, \"elasticity equations\", 0.0)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Saving results to file"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"<Grid Name=\"Grid\">\n",
" <Time Value=\"0\"/>\n",
"</Grid>\n"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"xdoc, xmodel = JuliaFEM.Postprocess.xdmf_new_model()\n",
"temporal_collection = JuliaFEM.Postprocess.xdmf_new_temporal_collection(xmodel)\n",
"grid = JuliaFEM.Postprocess.xdmf_new_grid(temporal_collection; time=0)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Save geometry to xdmf file"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"INFO: number of nodes in model: 8789\n",
"INFO: Number of elements in model: 31437\n"
]
}
],
"source": [
"nnodes = length(model[\"nodes\"])\n",
"info(\"number of nodes in model: $nnodes\")\n",
"\n",
"X = zeros(3, nnodes)\n",
"for nid in keys(model[\"nodes\"])\n",
" X[:, perm[nid]] = model[\"nodes\"][nid]\n",
"end\n",
"\n",
"nelements = length(model[\"elsets\"][\"PISTON\"])\n",
"info(\"Number of elements in model: $nelements\")\n",
"elmap = zeros(Int64, 5, nelements)\n",
"#elmap[1,:] = 0x0026\n",
"elmap[1,:] = 0x6\n",
"for (i, elid) in enumerate(model[\"elsets\"][\"PISTON\"])\n",
" elmap[2:end,i] = Int64[perm[nid] for nid in model[\"elements\"][elid]]\n",
"end"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"true"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"JuliaFEM.Postprocess.xdmf_new_mesh(grid, X, elmap)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Save nodal data to model"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"(3,8789)"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"using JuliaFEM.Core: get_connectivity\n",
"\n",
"u = zeros(3, nnodes)\n",
"\n",
"for element in values(elements)\n",
" isa(element, Element{Tet4}) || continue\n",
" connectivity = get_connectivity(element)\n",
" field = element[\"displacement\"](0.0)\n",
" for (i, nid) in enumerate(connectivity)\n",
" u[:, nid] = field[i]\n",
" end\n",
"end\n",
"size(u)"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"true"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"JuliaFEM.Postprocess.xdmf_new_field(grid, \"Displacement\", \"nodes\", u)"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"1525505"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"JuliaFEM.Postprocess.xdmf_save_model(xdoc, \"/tmp/piston_8789_P1.xmf\")"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"3x10 Array{Float64,2}:\n",
" 0.0582911 0.339694 0.431768 … 0.124351 0.346492 0.000617283\n",
" 0.0900323 0.22174 0.433814 0.140503 0.275036 0.0044649 \n",
" 0.0838928 -0.148224 0.00262483 -0.11171 0.0843743 -0.0175412 "
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"u[:, 1:10]"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"1x3 Array{Float64,2}:\n",
" -0.0471355 -0.468786 -0.222571"
]
},
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"minimum(u, 2)'"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"1x3 Array{Float64,2}:\n",
" 0.511168 0.563004 0.66328"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"maximum(u, 2)'"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"38.52232721814439"
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"piston_8789_P1_solution_norm = 38.52232721814439"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"@assert isapprox(norm(vec(u)), piston_8789_P1_solution_norm)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Julia 0.4.1",
"language": "julia",
"name": "julia-0.4"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "0.4.1"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
@@ -0,0 +1,293 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Some simple examples for calling Fortran from Julia"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Author(s): Tero Frondelius"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Abstract:** Some simple examples for calling Fortran from Julia"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"f = open(\"hello.f90\",\"w\")\n",
"write(f,\"subroutine hello(x,z,y)\\n\")\n",
"write(f,\" real*8 x,y\\n\")\n",
"write(f,\"\"\" print *, \"Hello World! \", x,y, \" testing Jupyter\"\\n\"\"\")\n",
"write(f,\"end subroutine hello\\n\")\n",
"close(f)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"f = open(\"array.f90\",\"w\")\n",
"write(f, \"\"\"\n",
" subroutine array(arr,siz)\n",
" integer*8 siz\n",
" real*8, dimension(siz) :: arr\n",
" do i=1,siz\n",
" print *, \"Arr \", arr(i)\n",
" end do\n",
" end subroutine array\n",
" \"\"\")\n",
"close(f)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"f = open(\"matrix.f90\",\"w\")\n",
"write(f, \"\"\"\n",
"subroutine matrix(arr,siz)\n",
" integer*8 siz\n",
"real*8, dimension(siz,siz) :: arr\n",
" do i=1,siz\n",
" do j=1,siz\n",
" print *, \"Arr(\",i,\",\",j,\") = \", arr(i,j)\n",
" end do\n",
" end do\n",
"end subroutine matrix\n",
" \"\"\")\n",
"close(f)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"run(`gfortran -shared -fPIC -o libhello.so hello.f90 array.f90 matrix.f90`)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"tt = 23.; uu = 12.;"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" Hello World! 23.000000000000000 12.000000000000000 testing Jupyter\n"
]
},
{
"data": {
"text/plain": [
"0"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"t = ccall( (:hello_, \"./libhello\"), Int64, (Ptr{Float64},Ptr{Void},Ptr{Float64}),&tt,{},&uu)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"6"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"test = [6. 5. 4. 3. 2. 1.]\n",
"ltest = length(test)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" Arr 6.0000000000000000 \n",
" Arr 5.0000000000000000 \n",
" Arr 4.0000000000000000 \n",
" Arr 3.0000000000000000 \n",
" Arr 2.0000000000000000 \n",
" Arr 1.0000000000000000 \n"
]
},
{
"data": {
"text/plain": [
"1"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"out = ccall( (:array_, \"./libhello\"), Int64, (Ptr{Float64},Ptr{Int64}),test,&ltest)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"2x2 Array{Float64,2}:\n",
" 1.0 2.0\n",
" 3.0 4.0"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mat_test = [1. 2.; 3. 4.]"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"2"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"l_mat = size(mat_test)[1]"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" Arr( 1 , 1 ) = 1.0000000000000000 \n",
" Arr( 1 , 2 ) = 2.0000000000000000 \n",
" Arr( 2 , 1 ) = 3.0000000000000000 \n",
" Arr( 2 , 2 ) = 4.0000000000000000 \n"
]
},
{
"data": {
"text/plain": [
"1"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"out = ccall( (:matrix_, \"./libhello\"), Int64, (Ptr{Float64},Ptr{Int64}),mat_test,&l_mat)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Julia 0.3.8",
"language": "julia",
"name": "julia-0.3"
},
"language_info": {
"name": "julia",
"version": "0.3.10"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
@@ -0,0 +1,603 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Abaqus umat interface"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Author(s): Tero Frondelius"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Abstract:** making the initial version to call Abaqus umat"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"--2015-07-25 22:07:34-- http://www.eng.ox.ac.uk/NP/ICP/plasticity_imp/code_imp.f\n",
"Resolving www.eng.ox.ac.uk (www.eng.ox.ac.uk)... 163.1.223.199\n",
"Connecting to www.eng.ox.ac.uk (www.eng.ox.ac.uk)|163.1.223.199|:80... connected.\n",
"HTTP request sent, awaiting response... 200 OK\n",
"Length: 7458 (7,3K) [text/plain]\n",
"Saving to: code_imp.f.1\n",
"\n",
" 0K ....... 100% 282M=0s\n",
"\n",
"2015-07-25 22:07:34 (282 MB/s) - code_imp.f.1 saved [7458/7458]\n",
"\n"
]
}
],
"source": [
"run(`wget http://www.eng.ox.ac.uk/NP/ICP/plasticity_imp/code_imp.f`)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"***********************************************************************************\n",
"** UMAT, FOR ABAQUS/STANDARD INCORPORATING ELASTIC-PLASTIC LINEAR **\n",
"** ISOTROPIC HARDENING. LARGE DEFORMATION FORMULATION FOR PLANE STRAIN **\n",
"** AND AXI-SYMMETRIC ELEMENTS. IMPLICIT INTEGRATION WITH CONSISTENT JACOBIAN **\n",
"***********************************************************************************\n",
"***********************************************************************************\n",
"**\n",
"**\n",
"**\n",
"*USER SUBROUTINE\n",
" SUBROUTINE UMAT(STRESS,STATEV,DDSDDE,SSE,SPD,SCD,\n",
" 1 RPL,DDSDDT,DRPLDE,DRPLDT,\n",
" 2 STRAN,DSTRAN,TIME,DTIME,TEMP,DTEMP,PREDEF,DPRED,CMNAME,\n",
" 3 NDI,NSHR,NTENS,NSTATV,PROPS,NPROPS,COORDS,DROT,PNEWDT,\n",
" 4 CELENT,DFGRD0,DFGRD1,NOEL,NPT,LAYER,KSPT,KSTEP,KINC)\n",
"C\n",
" INCLUDE 'ABA_PARAM.INC'\n",
"C\n",
" CHARACTER*80 CMNAME\n",
"C\n",
"C\n",
" DIMENSION STRESS(NTENS),STATEV(NSTATV),\n",
" 1 DDSDDE(NTENS,NTENS),DDSDDT(NTENS),DRPLDE(NTENS),\n",
" 2 STRAN(NTENS),DSTRAN(NTENS),TIME(2),PREDEF(1),DPRED(1),\n",
" 3 PROPS(NPROPS),COORDS(3),DROT(3,3),DFGRD0(3,3),DFGRD1(3,3)\n",
"C\n",
"C\n",
" PARAMETER (M=3,N=3,ID=3,ZERO=0.D0,ONE=1.D0,TWO=2.D0,THREE=3.D0,\n",
" + SIX=6.D0, NINE=9.D0, TOLER=1.D-5)\n",
"C\n"
]
}
],
"source": [
"run(`head -30 code_imp.f`)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## some implicit type castings"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"f = open(\"ABA_PARAM.INC\",\"w\")\n",
"write(f,\" implicit real*8(a-h,o-z)\\n\")\n",
"write(f,\" parameter (nprecd=2)\\n\")\n",
"close(f)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Let's compile the shared library"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"run(`gfortran -shared -fPIC -o libumat.so code_imp.f`)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Some Abaqus umat interface definitions\n",
"\n",
"|variable | explanation |\n",
"|--------------------|------------------------------------------|\n",
"|DDSDDE(NTENS,NTENS) | Jacobian matrix of the constitutive model|\n",
"|STRESS(NTENS) | the stress tensor (in vector format) |\n",
"|STATEV(NSTATV) | An array containing the solution-dependent state variables. |\n",
"|SSE | Specific elastic strain energy |\n",
"|SPD | plastic dissipation |\n",
"|SCD | “creep” dissipation |\n",
"|RPL | Volumetric heat generation per unit time |\n",
"|DDSDDT(NTENS) | Variation of the stress increments with respect to the temperature. |\n",
"|DRPLDE(NTENS) | Variation of RPL with respect to the strain increments.|\n",
"|DRPLDT | Variation of RPL with respect to the temperature. |\n",
"|RPL | RPL is used to indicate whether or not a cohesive element is open to the tangential flow of pore fluid.|\n",
"|PNEWDT | Ratio of suggested new time increment to the time increment being used |\n",
"|STRAN(NTENS) | An array containing the total strains at the beginning of the increment. |\n",
"|DSTRAN(NTENS) | Array of strain increments. |\n",
"|TIME(1) | Value of step time at the beginning of the current increment. |\n",
"|TIME(2) | Value of total time at the beginning of the current increment. |\n",
"|DTIME | Time increment.|\n",
"|TEMP | Temperature at the start of the increment. |\n",
"|DTEMP | Increment of temperature. |\n",
"|PREDEF | Array of interpolated values of predefined field variables at this point at the start of the increment, based on the values read in at the nodes.|\n",
"|DPRED | Array of increments of predefined field variables. |\n",
"|CMNAME | User-defined material name, left justified. |\n",
"|NDI | Number of direct stress components at this point. |\n",
"|NSHR | Number of engineering shear stress components at this point. |\n",
"|NTENS | Size of the stress or strain component array (NDI + NSHR). |\n",
"|NSTATV | Number of solution-dependent state variables that are associated with this material type |\n",
"|PROPS(NPROPS) | User-specified array of material constants associated with this user material. |\n",
"|NPROPS | User-defined number of material constants associated with this user material. |\n",
"|COORDS | An array containing the coordinates of this point. |\n",
"|DROT(3,3) | Rotation increment matrix. |\n",
"|CELENT | Characteristic element length |\n",
"|DFGRD0(3,3) | Array containing the deformation gradient at the beginning of the increment. |\n",
"|DFGRD1(3,3) | Array containing the deformation gradient at the end of the increment. |\n",
"|NOEL | Element number. |\n",
"|NPT | Integration point number. |\n",
"|LAYER | Layer number (for composite shells and layered solids). |\n",
"|KSPT | Section point number within the current layer. |\n",
"|KSTEP | Step number. |\n",
"|KINC | Increment number. |"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"0-element Array{Any,1}"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"STRESS = [0. 0. 0. 0.]\n",
"p = 0. # EFFECTIVE PLASTIC STRAIN\n",
"r = 0. # ISOTROPIC HARDENING VARIABLE\n",
"STATEV = [p r]\n",
"NTENS = 4 \n",
"DDSDDE = zeros(NTENS,NTENS)\n",
"SSE = {} # Not used in this example\n",
"SPD = {} # Not used in this example\n",
"SCD = {} # Not used in this example\n",
"RPL = {} # Not used in this example\n",
"DDSDDT = {} # Not used in this example\n",
"DRPLDE = {} # Not used in this example\n",
"DRPLDT = {} # Not used in this example\n",
"STRAN = [0. 0. 0. 0.]\n",
"DSTRAN = [0. 0. 0. 0.]\n",
"TIME = [0. 0.1] # CHECK TIME(2)\n",
"DTIME = {} # Not used in this example\n",
"TEMP = {} # Not used in this example\n",
"DTEMP = {} # Not used in this example\n",
"PREDEF = {} # Not used in this example\n",
"DPRED = {} # Not used in this example\n",
"CMNAME = {} # Not used in this example CHARACTER*80 CMNAME\n",
"NDI = {} # Not used in this example\n",
"NSHR = {} # Not used in this example\n",
"#NTENS correct place\n",
"NSTATV = length(STATEV)\n",
"PROPS = {} # Not used in this example\n",
"NPROPS = {} # Not used in this example\n",
"COORDS = {} # Not used in this example\n",
"DROT = {} # Not used in this example\n",
"PNEWDT = {} # Not used in this example EXPLANATION MISSING\n",
"CELENT = {} # Not used in this example\n",
"DFGRD0 = {} # Not used in this example\n",
"DFGRD1 = {} # Not used in this example\n",
"NOEL = {} # Not used in this example\n",
"NPT = {} # Not used in this example\n",
"LAYER = {} # Not used in this example\n",
"KSPT = {} # Not used in this example\n",
"KSTEP = {} # Not used in this example\n",
"KINC = {} # Not used in this example"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Finally the ccall of the umat"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"0"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ccall((:umat_, \"./libumat\"), Int64, \n",
" (Ptr{Float64},Ptr{Float64},Ptr{Float64},Ptr{Void},Ptr{Void},Ptr{Void},Ptr{Void},Ptr{Void},Ptr{Void},Ptr{Void},\n",
" Ptr{Float64},Ptr{Float64},Ptr{Void},Ptr{Void},Ptr{Void},Ptr{Void},Ptr{Void},Ptr{Void},Ptr{Void},Ptr{Void},Ptr{Void},\n",
" Ptr{Int64},Ptr{Int64},Ptr{Void},Ptr{Void},Ptr{Void},Ptr{Void},Ptr{Void},Ptr{Void},Ptr{Void},Ptr{Void},\n",
" Ptr{Void},Ptr{Void},Ptr{Void},Ptr{Void},Ptr{Void},Ptr{Void}),\n",
" STRESS,STATEV,DDSDDE,SSE,SPD,SCD,RPL,DDSDDT,DRPLDE,DRPLDT,\n",
" STRAN,DSTRAN,TIME,DTIME,TEMP,DTEMP,PREDEF,DPRED,CMNAME,NDI,NSHR,\n",
" &NTENS,&NSTATV,PROPS,NPROPS,COORDS,DROT,PNEWDT,CELENT,DFGRD0,DFGRD1,\n",
" NOEL,NPT,LAYER,KSPT,KSTEP,KINC)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Something happened"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"4x4 Array{Float64,2}:\n",
" 282692.0 121154.0 121154.0 0.0\n",
" 121154.0 282692.0 121154.0 0.0\n",
" 121154.0 121154.0 282692.0 0.0\n",
" 0.0 0.0 0.0 80769.2"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"DDSDDE"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"1x2 Array{Float64,2}:\n",
" 0.0 0.0"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"STATEV"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Let's wrap this to simplified Julia function for testing"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"isotropichardening! (generic function with 2 methods)"
]
},
"execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"function isotropichardening!(stress,p,r,jacobian,strain,DSTRAN)\n",
" local STRESS = stress\n",
" local STATEV = [p r]\n",
" local DDSDDE = jacobian\n",
" local STRAN = strain\n",
" o = ccall((:umat_, \"./libumat\"), Int64, \n",
" (Ptr{Float64},Ptr{Float64},Ptr{Float64},Ptr{Void},Ptr{Void},Ptr{Void},Ptr{Void},Ptr{Void},Ptr{Void},Ptr{Void},\n",
" Ptr{Float64},Ptr{Float64},Ptr{Void},Ptr{Void},Ptr{Void},Ptr{Void},Ptr{Void},Ptr{Void},Ptr{Void},Ptr{Void},\n",
" Ptr{Void},Ptr{Int64},Ptr{Int64},Ptr{Void},Ptr{Void},Ptr{Void},Ptr{Void},Ptr{Void},Ptr{Void},Ptr{Void},Ptr{Void},\n",
" Ptr{Void},Ptr{Void},Ptr{Void},Ptr{Void},Ptr{Void},Ptr{Void}),\n",
" STRESS,STATEV,DDSDDE,SSE,SPD,SCD,RPL,DDSDDT,DRPLDE,DRPLDT,\n",
" STRAN,DSTRAN,TIME,DTIME,TEMP,DTEMP,PREDEF,DPRED,CMNAME,NDI,\n",
" NSHR,&NTENS,&NSTATV,PROPS,NPROPS,COORDS,DROT,PNEWDT,CELENT,DFGRD0,DFGRD1,\n",
" NOEL,NPT,LAYER,KSPT,KSTEP,KINC)\n",
" stress = STRESS\n",
" p = STATEV[1]\n",
" r = STATEV[2]\n",
" jacobian = DDSDDE\n",
" strain = STRAN + DSTRAN\n",
" if o != 0 \n",
" throw(\"UMAT failed. Return code is $o\")\n",
" end\n",
" return o\n",
"end"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Now somebody should know how to use this function (help needed)"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {
"collapsed": false,
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0[0.0 0.0 0.0 0.0]0.00.0[0.0 0.0 0.0 0.0]\n",
"0[28.269231713558856 12.11538570784259 12.11538570784259 0.0]0.00.0[0.0001 0.0 0.0 0.0]\n",
"0[84.80769514067657 36.34615712352777 36.34615712352777 0.0]0.00.0[0.0002 0.0 0.0 0.0]\n",
"0[169.61539028135314 72.69231424705553 72.69231424705553 0.0]0.00.0[0.00030000000000000003 0.0 0.0 0.0]\n",
"0[282.69231713558855 121.15385707842589 121.15385707842589 0.0]0.00.0[0.0004 0.0 0.0 0.0]\n"
]
},
{
"ename": "LoadError",
"evalue": "\"UMAT failed. Return code is 62421072\"\nwhile loading In[30], in expression starting on line 5",
"output_type": "error",
"traceback": [
"\"UMAT failed. Return code is 62421072\"\nwhile loading In[30], in expression starting on line 5",
"",
" in isotropichardening! at In[29]:21",
" in anonymous at no file:7"
]
}
],
"source": [
"p = 0.0\n",
"r = 0.0\n",
"S = [0. 0. 0. 0.]\n",
"strain = [0. 0. 0. 0.]\n",
"for i in range(0,0.0001,11)\n",
" DSTRAN = [i 0. 0. 0.]\n",
" out = isotropichardening!(S,p,r,DDSDDE,strain,DSTRAN)\n",
" println(out,S,p,r, DSTRAN)\n",
" #println(i)\n",
"end"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Let's find out how many different funtions & subroutines are called"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"fil = open(\"code_imp.f\")\n",
"sub_list = Set{ASCIIString}()\n",
"for line in readlines(fil)\n",
" # Fortran comment = something non whitespce at the firts character\n",
" if ismatch(r\"^[^\\s]\",line)\n",
" #println(line)\n",
" continue\n",
" end\n",
" if ismatch(r\"call\",lowercase(line))\n",
" call = split(lowercase(line))[2] #divede by white space\n",
" sub = split(call,\"(\")[1] #divide by \"(\"\n",
" #println(sub)\n",
" push!(sub_list,sub)\n",
" end\n",
"end\n",
"close(fil)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"Set{ASCIIString}({\"keffp\",\"kdevia\",\"kmlt1\"})"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sub_list"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Next let's find out how many functions and subroutines are defined"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"fil = open(\"code_imp.f\")\n",
"fun_list = Set{ASCIIString}()\n",
"for line in readlines(fil)\n",
" if ismatch(r\"^[^\\s]\",line)\n",
" #println(line)\n",
" continue\n",
" end\n",
" comp = lowercase(line)\n",
" if ismatch(r\"subroutine\",comp) || ismatch(r\"funtion\",comp) || ismatch(r\"external\",comp)\n",
" #println(line)\n",
" call = split(lowercase(line),\"(\")[1] #divede by white space\n",
" sub = split(call)[end] #divide by \"(\"\n",
" #if length(sub) > 1\n",
" # sub = sub[2]\n",
" #end\n",
" #println(sub)\n",
" push!(fun_list,sub)\n",
" end\n",
"end\n",
"close(fil)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"Set{ASCIIString}({\"keffp\",\"dyadicprod\",\"umat\",\"kdevia\",\"dotprod\",\"kmlt1\"})"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"fun_list"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## And Finally are all called subroutines defined"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"Set{ASCIIString}({})"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"setdiff(sub_list,fun_list)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Julia 0.3.8",
"language": "julia",
"name": "julia-0.3"
},
"language_info": {
"name": "julia",
"version": "0.3.10"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,207 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"WARNING: module JuliaFEM should explicitly import setindex! from Base\n"
]
}
],
"source": [
"using JuliaFEM: Material, set_material!, get_element_set, ElasticityProblem,\n",
"DirichletProblem, LoadCase, DisplacementBC, ForceBC, DirichletProblem,\n",
"add_boundary_condition!, add_loadcase!"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"INFO: Parsing nodes\n",
"INFO: Parsing elements. Type: JuliaFEM.Tet4\n",
"INFO: Parsing elements. Type: JuliaFEM.Seg3\n",
"INFO: Creating elset BC1\n",
"INFO: Creating elset BC2\n"
]
},
{
"data": {
"text/plain": [
"JuliaFEM.Material{ASCIIString,Float64}(\"steel\",Dict(\"poissons ratio\"=>0.3,\"youngs modulus\"=>210000.0,\"other values\"=>100000.0))"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"INFO: Creating elset BC3\n"
]
}
],
"source": [
"\n",
"# Reading nodes, elements and sets from input file\n",
"model = open(JuliaFEM.parse_abaqus, \"/home/olli/.julia/v0.4/JuliaFEM/geometry/piston/piston_8789_P1.inp\")\n",
"\n",
"# Creating material\n",
"# It is possible to create material data with one function\n",
"steel = Material(\"steel\",\n",
" (\"youngs modulus\" => 210.0e3,\n",
" \"poissons ratio\" => 0.3,\n",
" \"other values\" => 100e3),\n",
")\n",
"\n",
"# Or by adding row by row\n",
"steel2 = Material(\"Steel2\")\n",
"steel2[\"youngs modulus\"] = 210.0e3\n",
"steel2[\"poissons ratio\"] = 10.0\n",
"\n",
"# Setting material to element set\n",
"set_material!(model, steel, \"PISTON\")\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"JuliaFEM.NeumannBC{ASCIIString}(\"displacement traction force\",1000,\"BC1\")"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Fetchig set from model\n",
"piston = get_element_set(model, \"PISTON\")\n",
"\n",
"# Creating problems:\n",
"# Elasticity \n",
"elasticity_problem = ElasticityProblem()\n",
"\n",
"# Boundary conditions\n",
"BC1 = DisplacementBC(\"displacement u1\", 0.0, \"BC2\")\n",
"F1 = ForceBC(\"displacement traction force\", 1000, \"BC1\")\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"2-element Array{Array{Union{JuliaFEM.DirichletBC{S<:AbstractString},JuliaFEM.NeumannBC{S<:AbstractString}},1},1}:\n",
" Union{JuliaFEM.DirichletBC{S<:AbstractString},JuliaFEM.NeumannBC{S<:AbstractString}}[JuliaFEM.NeumannBC{ASCIIString}(\"displacement traction force\",1000,\"BC1\"),JuliaFEM.DirichletBC{ASCIIString}(\"displacement u1\",0.0,\"BC2\"),JuliaFEM.NeumannBC{ASCIIString}(\"displacement traction force\",1000,\"BC1\"),JuliaFEM.DirichletBC{ASCIIString}(\"displacement u1\",0.0,\"BC2\")]\n",
" Union{JuliaFEM.DirichletBC{S<:AbstractString},JuliaFEM.NeumannBC{S<:AbstractString}}[JuliaFEM.NeumannBC{ASCIIString}(\"displacement traction force\",1000,\"BC1\"),JuliaFEM.DirichletBC{ASCIIString}(\"displacement u1\",0.0,\"BC2\"),JuliaFEM.NeumannBC{ASCIIString}(\"displacement traction force\",1000,\"BC1\"),JuliaFEM.DirichletBC{ASCIIString}(\"displacement u1\",0.0,\"BC2\")]"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"\n",
"# Possible ways to create a loadcase, whihc holds all data for calculation\n",
"load4 = LoadCase(elasticity_problem)\n",
"load = LoadCase(elasticity_problem, [BC1])\n",
"load2 = LoadCase(elasticity_problem, [BC1, F1])\n",
"load3 = LoadCase(elasticity_problem, BC1)\n",
"\n",
"# Couple of ways to add boundary conditions to loadcase\n",
"add_boundary_condition!(load, BC1)\n",
"add_boundary_condition!(load2, F1)\n",
"add_boundary_condition!(load3, BC1)\n",
"add_boundary_condition!(load4, [F1, BC1])\n",
"add_boundary_condition!(load, [F1, BC1])\n",
"add_boundary_condition!(load4, [F1, BC1])\n"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"0"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"\n",
"# Adding load case to model, various ways...\n",
"add_loadcase!(model, load)\n",
"add_loadcase!(model, [load, load2, load3])\n",
"0"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# Select solver\n",
"solver = DirectSolver()\n",
"\n",
"solve!(model, solver)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Julia 0.4.1-pre",
"language": "julia",
"name": "julia-0.4"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "0.4.1"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,297 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"300"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"using JuliaFEM\n",
"\n",
"using JuliaFEM.Core: Node, Element, Seg2, Tri3, Quad4, Hex8\n",
"using JuliaFEM.Core: Problem, FieldProblem, BoundaryProblem, Dirichlet, Elasticity, Mortar\n",
"using JuliaFEM.Core: Solver, SparseMatrixCOO\n",
"using JuliaFEM.Core: get_elements, update!, calculate_normal_tangential_coordinates!,\n",
"get_connectivity, get_field_assembly, get_boundary_problems, handle_overconstraint_error!\n",
"using JuliaFEM.Preprocess: parse_aster_med_file, aster_create_elements\n",
"import JuliaFEM.Core: solve_linear_system\n",
"\n",
"using PyPlot\n",
"\n",
"ENV[\"COLUMNS\"] = 300"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"INFO: Found 6 element sets: TOP, DIE, GROUND, SLAB, DIE_TO_SLAB, SLAB_TO_DIE\n",
"INFO: normal tangential for first slave element\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Array(Float64,(3,3)) 3x3 Array{Float64,2}"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"INFO: # of master elements: 120\n",
"INFO: # of slave elements: 80\n"
]
}
],
"source": [
"function create_ironing_problem(meshfile=\"/geometry/3d_ironing/MESH_SPARSE.med\")\n",
"\n",
" mesh = parse_aster_med_file(Pkg.dir(\"JuliaFEM\")*meshfile)\n",
" \n",
" body1 = Problem(Elasticity, \"SLAB\", 3)\n",
" body1_elements = aster_create_elements(mesh, :SLAB, :HE8)\n",
" update!(body1_elements, \"youngs modulus\", 288.0)\n",
" update!(body1_elements, \"poissons ratio\", 1/3)\n",
" push!(body1, body1_elements...)\n",
"\n",
" body2 = Problem(Elasticity, \"DIE\", 3)\n",
" body2_elements = aster_create_elements(mesh, :DIE, :HE8)\n",
" update!(body2_elements, \"youngs modulus\", 288000.0)\n",
" update!(body2_elements, \"poissons ratio\", 1/3)\n",
" push!(body2, body2_elements...)\n",
"\n",
" # boundary conditions\n",
" bc1 = Problem(Dirichlet, \"bottom surface of slab\", 3, \"displacement\")\n",
" bc1_elements = aster_create_elements(mesh, :GROUND, :QU4)\n",
" update!(bc1_elements, \"displacement 1\", 0.0)\n",
" update!(bc1_elements, \"displacement 2\", 0.0)\n",
" update!(bc1_elements, \"displacement 3\", 0.0)\n",
" push!(bc1, bc1_elements...)\n",
"\n",
" bc2 = Problem(Dirichlet, \"top surface of die\", 3, \"displacement\")\n",
" bc2_elements = aster_create_elements(mesh, :TOP, :QU4)\n",
" #d = [0.0, 0.0, -1.0]\n",
" #update!(bc2_elements, \"displacement\", Vector{Float64}[d, d, d, d])\n",
" update!(bc2_elements, \"displacement 1\", 0.0)\n",
" update!(bc2_elements, \"displacement 2\", 0.0)\n",
" update!(bc2_elements, \"displacement 3\", -1.0)\n",
" push!(bc2, bc2_elements...)\n",
"\n",
" # contact\n",
" bc3 = Problem(Mortar, \"contact between slab and die\", 3, \"displacement\")\n",
" bc3_slave_elements = aster_create_elements(mesh, :SLAB_TO_DIE, :QU4)\n",
" bc3_master_elements = aster_create_elements(mesh, :DIE_TO_SLAB, :QU4)\n",
" update!(bc3_slave_elements, \"master elements\", bc3_master_elements)\n",
" info(\"normal tangential for first slave element\")\n",
" calculate_normal_tangential_coordinates!(bc3_slave_elements, 0.0)\n",
" Q = bc3_slave_elements[1](\"normal-tangential coordinates\", [0.0, 0.0], 0.0)\n",
" dump(Q)\n",
" push!(bc3, bc3_slave_elements...)\n",
" push!(bc3, bc3_master_elements...)\n",
" info(\"# of master elements: $(length(bc3_master_elements))\")\n",
" info(\"# of slave elements: $(length(bc3_slave_elements))\")\n",
"\n",
" return body1, body2, bc1, bc2, bc3\n",
"\n",
"end\n",
"\n",
"body1, body2, bc1, bc2, bc3 = create_ironing_problem();"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
":\n",
" 0.0 1.0 0.0\n",
" 0.0 0.0 1.0\n",
" 1.0 0.0 0.0\n",
"Array(Float64,(3,3)) 3x3 Array{Float64,2}:\n",
" 0.0 1.0 0.0\n",
" 0.0 0.0 1.0\n",
" 1.0 0.0 0.0\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"INFO: Found 6 element sets: TOP, DIE, GROUND, SLAB, DIE_TO_SLAB, SLAB_TO_DIE\n",
"INFO: normal tangential for first slave element\n",
"INFO: # of master elements: 120\n",
"INFO: # of slave elements: 80\n",
"INFO: solving linear system of 5 problems.\n",
"INFO: PDASS: Starting primal-dual active set strategy to determine active constraints\n",
"INFO: PDASS: contact nodes: [304,307,308,309,310,318,322,323,324,325,348,349,350,351,352,353,354,355,356,357,358,359,360,361,362,363,364,365,366,386,387,388,389,390,391,392,393,394,395,396,397,398,399,400,401,402,403,404,550,551,552,553,554,555,556,557,558,559,560,561,562,563,564,565,566,567,568,569,570,571,572,573,574,575,576,577,578,579,580,581,582,583,584,585,586,587,588,589,590,591,592,593,594,595,596,597,598,599,600,601,602,603,604,605,606]\n",
"INFO: PDASS: active nodes: Int64[]\n",
"INFO: PDASS: inactive nodes: [304,307,308,309,310,318,322,323,324,325,348,349,350,351,352,353,354,355,356,357,358,359,360,361,362,363,364,365,366,386,387,388,389,390,391,392,393,394,395,396,397,398,399,400,401,402,403,404,550,551,552,553,554,555,556,557,558,559,560,561,562,563,564,565,566,567,568,569,570,571,572,573,574,575,576,577,578,579,580,581,582,583,584,585,586,587,588,589,590,591,592,593,594,595,596,597,598,599,600,601,602,603,604,605,606]\n",
"INFO: UMFPACK: solved in 0.6064090728759766 seconds. norm = 17.32050807568924\n",
"INFO: solving linear system of 5 problems.\n",
"INFO: PDASS: Starting primal-dual active set strategy to determine active constraints\n",
"INFO: PDASS: contact nodes: [304,307,308,309,310,318,322,323,324,325,348,349,350,351,352,353,354,355,356,357,358,359,360,361,362,363,364,365,366,386,387,388,389,390,391,392,393,394,395,396,397,398,399,400,401,402,403,404,550,551,552,553,554,555,556,557,558,559,560,561,562,563,564,565,566,567,568,569,570,571,572,573,574,575,576,577,578,579,580,581,582,583,584,585,586,587,588,589,590,591,592,593,594,595,596,597,598,599,600,601,602,603,604,605,606]\n",
"INFO: PDASS: active nodes: [348,349,350,351,352,353,354,355,356,357,386,387,388,389,390,391,392,393,394,395,550,551,552,553,554,555,556,557,558,559,569,570,571,572,573,574,575,576,577,578,588,589,590,591,592,593,594,595,596,597]\n",
"INFO: PDASS: inactive nodes: [304,307,308,309,310,318,322,323,324,325,358,359,360,361,362,363,364,365,366,396,397,398,399,400,401,402,403,404,560,561,562,563,564,565,566,567,568,579,580,581,582,583,584,585,586,587,598,599,600,601,602,603,604,605,606]\n",
"INFO: UMFPACK: solved in 0.24304413795471191 seconds. norm = 18.1021717204183\n",
"INFO: solving linear system of 5 problems.\n",
"INFO: PDASS: Starting primal-dual active set strategy to determine active constraints\n",
"INFO: PDASS: contact nodes: [304,307,308,309,310,318,322,323,324,325,348,349,350,351,352,353,354,355,356,357,358,359,360,361,362,363,364,365,366,386,387,388,389,390,391,392,393,394,395,396,397,398,399,400,401,402,403,404,550,551,552,553,554,555,556,557,558,559,560,561,562,563,564,565,566,567,568,569,570,571,572,573,574,575,576,577,578,579,580,581,582,583,584,585,586,587,588,589,590,591,592,593,594,595,596,597,598,599,600,601,602,603,604,605,606]\n",
"INFO: PDASS: active nodes: [349,350,351,352,353,354,355,356,387,388,389,390,391,392,393,394,551,552,553,554,555,556,557,558,570,571,572,573,574,575,576,577,589,590,591,592,593,594,595,596]\n",
"INFO: PDASS: inactive nodes: [304,307,308,309,310,318,322,323,324,325,348,357,358,359,360,361,362,363,364,365,366,386,395,396,397,398,399,400,401,402,403,404,550,559,560,561,562,563,564,565,566,567,568,569,578,579,580,581,582,583,584,585,586,587,588,597,598,599,600,601,602,603,604,605,606]\n",
"INFO: UMFPACK: solved in 0.12660002708435059 seconds. norm = 18.174500081971626\n",
"INFO: solving linear system of 5 problems.\n",
"INFO: PDASS: Starting primal-dual active set strategy to determine active constraints\n",
"INFO: PDASS: contact nodes: [304,307,308,309,310,318,322,323,324,325,348,349,350,351,352,353,354,355,356,357,358,359,360,361,362,363,364,365,366,386,387,388,389,390,391,392,393,394,395,396,397,398,399,400,401,402,403,404,550,551,552,553,554,555,556,557,558,559,560,561,562,563,564,565,566,567,568,569,570,571,572,573,574,575,576,577,578,579,580,581,582,583,584,585,586,587,588,589,590,591,592,593,594,595,596,597,598,599,600,601,602,603,604,605,606]\n",
"INFO: PDASS: active nodes: [349,350,351,352,353,354,355,356,387,388,389,390,391,392,393,394,551,552,553,554,555,556,557,558,570,571,572,573,574,575,576,577,589,590,591,592,593,594,595,596]\n",
"INFO: PDASS: inactive nodes: [304,307,308,309,310,318,322,323,324,325,348,357,358,359,360,361,362,363,364,365,366,386,395,396,397,398,399,400,401,402,403,404,550,559,560,561,562,563,564,565,566,567,568,569,578,579,580,581,582,583,584,585,586,587,588,597,598,599,600,601,602,603,604,605,606]\n",
"INFO: UMFPACK: solved in 0.14113306999206543 seconds. norm = 18.174500081971626\n",
"INFO: Converged in 4 iterations.\n"
]
},
{
"data": {
"text/plain": [
"true"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"body1, body2, bc1, bc2, bc3 = create_ironing_problem()\n",
"bc3.properties.inequality_constraints = true\n",
"#bc3.properties.normal_condition = :Contact\n",
"#bc3.properties.tangential_condition = :Slip\n",
"#bc3.properties.minimum_distance = 1\n",
"solver = Solver(\"solve ironing problem.\")\n",
"push!(solver, body1, body2, bc1, bc2, bc3)\n",
"call(solver)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"INFO: 360 elements.\n",
"INFO: XDFM: ndim = 2160\n",
"INFO: model dumped to /tmp/ironing.xmf\n"
]
}
],
"source": [
"using JuliaFEM.Postprocess: xdmf_new_model, xdmf_new_temporal_collection, xdmf_new_grid,\n",
" xdmf_new_mesh!, xdmf_new_nodal_field!, xdmf_save_model\n",
"using JuliaFEM.Core: Element\n",
"\n",
"function xdmf_dump(all_elements, filename=\"/tmp/xdmf_result.xmf\")\n",
" info(\"$(length(all_elements)) elements.\")\n",
" xdoc, xmodel = xdmf_new_model()\n",
" coll = xdmf_new_temporal_collection(xmodel)\n",
" grid = xdmf_new_grid(coll; time=0.0)\n",
"\n",
" Xg = Dict{Int64, Vector{Float64}}()\n",
" ug = Dict{Int64, Vector{Float64}}()\n",
" nids = Dict{Int64, Int64}()\n",
" for element in all_elements\n",
" conn = get_connectivity(element)\n",
" for (i, c) in enumerate(conn)\n",
" nids[c] = c\n",
" end\n",
" X = element(\"geometry\", 0.0)\n",
" for (i, c) in enumerate(conn)\n",
" Xg[c] = X[i]\n",
" end\n",
" haskey(element, \"displacement\") || continue\n",
" u = element(\"displacement\", 0.0)\n",
" for (i, c) in enumerate(conn)\n",
" ug[c] = u[i]\n",
" end\n",
" end\n",
" perm = sort(collect(keys(Xg)))\n",
" nodes = Vector{Float64}[Xg[i] for i in perm]\n",
" disp = Vector{Float64}[ug[i] for i in perm]\n",
" nids = Int[nids[i] for i in perm]\n",
" inids = Dict{Int64, Int64}()\n",
" for (i, nid) in enumerate(nids)\n",
" inids[nid] = i\n",
" end\n",
" elements = []\n",
" for element in all_elements\n",
" isa(element, Element{Hex8}) || continue\n",
" conn = get_connectivity(element)\n",
" nconn = [inids[i] for i in conn]\n",
" push!(elements, (:Hex8, nconn))\n",
" end\n",
"\n",
" xdmf_new_mesh!(grid, nodes, elements)\n",
" xdmf_new_nodal_field!(grid, \"displacement\", disp)\n",
" xdmf_save_model(xdoc, filename)\n",
" info(\"model dumped to $filename\")\n",
"end\n",
"\n",
"xdmf_dump([body1.elements; body2.elements], \"/tmp/ironing.xmf\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Julia 0.4.3",
"language": "julia",
"name": "julia-0.4"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "0.4.3"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+12
View File
@@ -0,0 +1,12 @@
This is the area for JuliaFEM.jl notebook development
-----------------------------------------------------
We use notebooks heavily to test our ideas and develop new code. Code in these
notebooks most likely will not up to date code: *DO NOT COPYPASTE* code
from here unless you really do know what you are doing. These notebooks are not
tested automatically.
Our "official" notebooks are in verification and in tutorials:
https://github.com/JuliaFEM/JuliaFEM.jl/tree/master/verification
https://github.com/JuliaFEM/JuliaFEM.jl/tree/master/docs/tutorials