Files
JuliaFEM.jl/docs/tutorials/2016-02-04-3d-frictionless-contact.ipynb
Jukka Aho 0f0c49da62 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.
2017-08-05 12:08:46 +03:00

298 lines
13 KiB
Plaintext

{
"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
}