From acfaf582cb0bf57518f69b3d3bdaf9c2ed8a50b7 Mon Sep 17 00:00:00 2001 From: Jukka Aho Date: Sun, 28 Jun 2015 20:27:15 +0300 Subject: [PATCH] updated for quadratic tetras --- ...2015-06-25-elasticity-solver-example.ipynb | 967 ++++++++++++++++-- 1 file changed, 876 insertions(+), 91 deletions(-) diff --git a/notebooks/2015-06-25-elasticity-solver-example.ipynb b/notebooks/2015-06-25-elasticity-solver-example.ipynb index 9c43834..dd8e6f5 100644 --- a/notebooks/2015-06-25-elasticity-solver-example.ipynb +++ b/notebooks/2015-06-25-elasticity-solver-example.ipynb @@ -21,7 +21,10 @@ "output_type": "stream", "text": [ "\n", - "WARNING: deprecated syntax \"{a=>b, ...}\" at /Users/jukka/.julia/v0.4/JuliaFEM/src/abaqus_reader.jl:29.\n", + "WARNING: deprecated syntax \"{a=>b, ...}\" at /Users/jukka/.julia/v0.4/JuliaFEM/src/abaqus_reader.jl:11.\n", + "Use \"Dict{Any,Any}(a=>b, ...)\" instead.\n", + "\n", + "WARNING: deprecated syntax \"{a=>b, ...}\" at /Users/jukka/.julia/v0.4/JuliaFEM/src/abaqus_reader.jl:32.\n", "Use \"Dict{Any,Any}(a=>b, ...)\" instead.\n" ] }, @@ -45,6 +48,17 @@ "Logging.configure(level=DEBUG)" ] }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "using LightXML" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -261,7 +275,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 4, "metadata": { "collapsed": false }, @@ -270,47 +284,47 @@ "name": "stderr", "output_type": "stream", "text": [ - "25-Jun 20:00:29:INFO:root:Registered handlers: Any[\"ELEMENT\",\"NODE\",\"NSET\"]\n", + "27-Jun 23:44:05:INFO:root:Registered handlers: Any[\"ELEMENT\",\"NODE\",\"NSET\"]\n", "WARNING: beginswith is deprecated, use startswith instead.\n", " in depwarn at /Applications/Julia-0.4.0-dev-539c818c4e.app/Contents/Resources/julia/lib/julia/sys.dylib\n", " in beginswith at deprecated.jl:30\n", - " in parse_abaqus at /Users/jukka/.julia/v0.4/JuliaFEM/src/abaqus_reader.jl:110\n", + " in parse_abaqus at /Users/jukka/.julia/v0.4/JuliaFEM/src/abaqus_reader.jl:113\n", " in include_string at loading.jl:99\n", " in execute_request_0x535c5df2 at /Users/jukka/.julia/v0.4/IJulia/src/execute_request.jl:157\n", " in eventloop at /Users/jukka/.julia/v0.4/IJulia/src/IJulia.jl:123\n", " in anonymous at task.jl:365\n", - "while loading In[5], in expression starting on line 2\n", + "while loading In[4], in expression starting on line 2\n", "WARNING: beginswith is deprecated, use startswith instead.\n", " in depwarn at /Applications/Julia-0.4.0-dev-539c818c4e.app/Contents/Resources/julia/lib/julia/sys.dylib\n", " in beginswith at deprecated.jl:30\n", - " in parse_abaqus at /Users/jukka/.julia/v0.4/JuliaFEM/src/abaqus_reader.jl:110\n", + " in parse_abaqus at /Users/jukka/.julia/v0.4/JuliaFEM/src/abaqus_reader.jl:113\n", " in include_string at loading.jl:99\n", " in execute_request_0x535c5df2 at /Users/jukka/.julia/v0.4/IJulia/src/execute_request.jl:157\n", " in eventloop at /Users/jukka/.julia/v0.4/IJulia/src/IJulia.jl:123\n", " in anonymous at task.jl:365\n", - "while loading In[5], in expression starting on line 2\n", - "25-Jun 20:00:30:DEBUG:root:Found NODE section\n", - "25-Jun 20:00:30:DEBUG:root:Found ELEMENT section\n", + "while loading In[4], in expression starting on line 2\n", + "27-Jun 23:44:06:DEBUG:root:Found NODE section\n", + "27-Jun 23:44:07:DEBUG:root:Found ELEMENT section\n", "WARNING: integer(s::AbstractString) is deprecated, use parse(Int,s) instead.\n", " in depwarn at /Applications/Julia-0.4.0-dev-539c818c4e.app/Contents/Resources/julia/lib/julia/sys.dylib\n", " in integer at deprecated.jl:49\n", " in map at abstractarray.jl:1251\n", - " in parse_element_section at /Users/jukka/.julia/v0.4/JuliaFEM/src/abaqus_reader.jl:56\n", - " in process_section at /Users/jukka/.julia/v0.4/JuliaFEM/src/abaqus_reader.jl:105\n", - " in parse_abaqus at /Users/jukka/.julia/v0.4/JuliaFEM/src/abaqus_reader.jl:114\n", + " in parse_element_section at /Users/jukka/.julia/v0.4/JuliaFEM/src/abaqus_reader.jl:59\n", + " in process_section at /Users/jukka/.julia/v0.4/JuliaFEM/src/abaqus_reader.jl:108\n", + " in parse_abaqus at /Users/jukka/.julia/v0.4/JuliaFEM/src/abaqus_reader.jl:117\n", " in include_string at loading.jl:99\n", " in execute_request_0x535c5df2 at /Users/jukka/.julia/v0.4/IJulia/src/execute_request.jl:157\n", " in eventloop at /Users/jukka/.julia/v0.4/IJulia/src/IJulia.jl:123\n", " in anonymous at task.jl:365\n", - "while loading In[5], in expression starting on line 2\n", - "25-Jun 20:00:31:DEBUG:root:120 elements found\n", - "25-Jun 20:00:31:INFO:root:Creating ELSET Body1\n", - "25-Jun 20:00:31:DEBUG:root:Found NSET section\n", - "25-Jun 20:00:31:DEBUG:root:Creating node set SUPPORT\n", - "25-Jun 20:00:31:DEBUG:root:Found NSET section\n", - "25-Jun 20:00:31:DEBUG:root:Creating node set LOAD\n", - "25-Jun 20:00:31:DEBUG:root:Found NSET section\n", - "25-Jun 20:00:31:DEBUG:root:Creating node set TOP\n" + "while loading In[4], in expression starting on line 2\n", + "27-Jun 23:44:08:DEBUG:root:120 elements found\n", + "27-Jun 23:44:08:INFO:root:Creating ELSET Body1\n", + "27-Jun 23:44:08:DEBUG:root:Found NSET section\n", + "27-Jun 23:44:08:DEBUG:root:Creating node set SUPPORT\n", + "27-Jun 23:44:08:DEBUG:root:Found NSET section\n", + "27-Jun 23:44:08:DEBUG:root:Creating node set LOAD\n", + "27-Jun 23:44:08:DEBUG:root:Found NSET section\n", + "27-Jun 23:44:08:DEBUG:root:Creating node set TOP\n" ] }, { @@ -323,7 +337,7 @@ " \"nsets\" => Dict{Any,Any}(\"LOAD\"=>[82,84,87,179,197,246,249,256,257],\"SUPPO…" ] }, - "execution_count": 5, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -337,7 +351,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 5, "metadata": { "collapsed": false }, @@ -346,19 +360,19 @@ "data": { "text/plain": [ "10x120 Array{Int64,2}:\n", - " 47 56 91 87 72 72 176 290 … 260 165 101 18 271 72 24\n", - " 173 236 176 45 97 253 173 22 236 181 261 201 211 146 166\n", - " 76 97 139 49 253 158 76 252 202 87 19 71 18 289 196\n", - " 202 111 242 290 289 289 47 49 254 290 254 255 277 29 133\n", - " 156 10 120 53 74 169 144 127 114 95 75 2 100 67 135\n", - " 88 214 266 291 270 118 88 70 … 14 185 104 235 257 180 198\n", - " 16 89 179 40 169 209 44 17 103 68 215 12 212 200 65\n", - " 134 278 199 4 200 200 34 177 147 163 145 121 170 167 92\n", - " 32 187 221 243 210 37 156 240 195 7 117 80 9 48 52\n", - " 132 15 265 177 37 233 16 268 79 4 263 168 208 57 150" + " 243 204 259 145 96 96 236 285 … 217 69 154 179 203 96 259\n", + " 240 199 70 175 88 101 88 179 216 144 114 91 204 267 199\n", + " 191 175 69 199 236 164 285 178 278 78 278 178 259 95 204\n", + " 117 130 130 130 178 97 178 83 155 71 218 83 199 97 130\n", + " 245 207 265 177 141 102 290 12 219 146 20 181 206 268 39\n", + " 242 208 72 208 290 171 289 182 … 282 152 280 180 263 272 207\n", + " 244 209 5 202 291 9 287 11 33 79 32 182 262 98 263\n", + " 1 3 6 174 7 99 237 13 224 74 223 14 205 99 6\n", + " 2 4 132 176 8 103 8 14 225 51 284 93 207 24 4\n", + " 196 176 134 4 237 10 11 15 17 80 283 15 39 100 3" ] }, - "execution_count": 30, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } @@ -388,14 +402,16 @@ "end\n", "\n", "for j=1:nnodes\n", - " X[:,j] = model[\"nodes\"][perm[j]]\n", + " #X[:,j] = model[\"nodes\"][perm[j]]\n", + " X[:,j] = model[\"nodes\"][j]\n", "end\n", "\n", "for (j, k) in enumerate(keys(model[\"elements\"]))\n", - " node_ids = model[\"elements\"][k]\n", - " for l=1:10\n", - " elmap[l, j] = perm[node_ids[l]]\n", - " end\n", + " #node_ids = model[\"elements\"][j]\n", + " elmap[:,j] = model[\"elements\"][j]\n", + " #for l=1:10\n", + " # elmap[l, j] = perm[node_ids[l]]\n", + " #end\n", "end\n", "\n", "elmap" @@ -403,7 +419,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 6, "metadata": { "collapsed": false }, @@ -417,7 +433,7 @@ " NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN" ] }, - "execution_count": 18, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } @@ -425,7 +441,8 @@ "source": [ "# Handle dirichlet boundaries on SUPPORT\n", "for j in model[\"nsets\"][\"SUPPORT\"]\n", - " dirichletbc[perm[j]] = 0.0\n", + " #dirichletbc[perm[j]] = 0.0\n", + " dirichletbc[j] = 0.0\n", "end\n", "dirichletbc" ] @@ -439,7 +456,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 7, "metadata": { "collapsed": false }, @@ -450,39 +467,39 @@ "dNtet (generic function with 1 method)" ] }, - "execution_count": 21, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "Ntet(xi) = [ -xi[1] - xi[2] - xi[3] + 1\n", - " xi[1]\n", - " xi[2]\n", - " xi[3]\n", - " 4*xi[1]*(-xi[1] - xi[2] - xi[3] + 1)\n", - " 4*xi[1]*xi[2]\n", - " 4*xi[2]*(-xi[1] - xi[2] - xi[3] + 1)\n", - " 4*xi[3]*(-xi[1] - xi[2] - xi[3] + 1)\n", - " 4*xi[1]*xi[3]\n", - " 4*xi[2]*xi[3]]\n", + "Ntet(xi) = [(xi[1] + xi[2] + xi[3] - 1)*(2*xi[1] + 2*xi[2] + 2*xi[3] - 1)\n", + " -xi[1]*(-2*xi[1] + 1)\n", + " -xi[2]*(-2*xi[2] + 1)\n", + " -xi[3]*(-2*xi[3] + 1)\n", + " 4*xi[1]*(-xi[1] - xi[2] - xi[3] + 1)\n", + " 4*xi[1]*xi[2]\n", + " 4*xi[2]*(-xi[1] - xi[2] - xi[3] + 1)\n", + " 4*xi[1]*xi[3]\n", + " 4*xi[2]*xi[3]\n", + " 4*xi[3]*(-xi[1] - xi[2] - xi[3] + 1)]\n", "\n", "dNtet(xi) = [\n", - " -1 -1 -1\n", - " 1 0 0\n", - " 0 1 0\n", - " 0 0 1\n", + " 4*xi[1] + 4*xi[2] + 4*xi[3] - 3 4*xi[1] + 4*xi[2] + 4*xi[3] - 3 4*xi[1] + 4*xi[2] + 4*xi[3] - 3\n", + " 4*xi[1] - 1 0 0\n", + " 0 4*xi[2] - 1 0\n", + " 0 0 4*xi[3] - 1\n", "-8*xi[1] - 4*xi[2] - 4*xi[3] + 4 -4*xi[1] -4*xi[1]\n", " 4*xi[2] 4*xi[1] 0\n", - " -4*xi[2] -4*xi[1] - 8*xi[2] - 4*xi[3] + 4 -4*xi[2]\n", - " -4*xi[3] -4*xi[3] -4*xi[1] - 4*xi[2] - 8*xi[3] + 4\n", + " -4*xi[2] -4*xi[1] - 8*xi[2] - 4*xi[3] + 4 -4*xi[2]\n", " 4*xi[3] 0 4*xi[1]\n", - " 0 4*xi[3] 4*xi[2]]" + " 0 4*xi[3] 4*xi[2]\n", + " -4*xi[3] -4*xi[3] -4*xi[1] - 4*xi[2] - 8*xi[3] + 4]" ] }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 8, "metadata": { "collapsed": false }, @@ -490,31 +507,21 @@ { "data": { "text/plain": [ - "10x3 Array{Int64,2}:\n", - " -1 -1 -1\n", - " 1 0 0\n", - " 0 1 0\n", - " 0 0 1\n", - " -4 0 0\n", - " 4 0 0\n", - " -4 -8 -4\n", - " -4 -4 -8\n", - " 4 0 0\n", - " 0 4 4" + "1" ] }, - "execution_count": 24, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "dNtet([0, 1, 1])" + "sum(Ntet([0, 1, 1]))" ] }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 9, "metadata": { "collapsed": false }, @@ -526,7 +533,7 @@ " 0.0416667 0.0416667 0.0416667 0.0416667" ] }, - "execution_count": 25, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } @@ -548,7 +555,7 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 10, "metadata": { "collapsed": false }, @@ -568,7 +575,7 @@ " 257" ] }, - "execution_count": 33, + "execution_count": 10, "metadata": {}, "output_type": "execute_result" } @@ -579,7 +586,7 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 11, "metadata": { "collapsed": false }, @@ -588,34 +595,56 @@ "name": "stdout", "output_type": "stream", "text": [ - "[95.0,10.0,5.0]\n" + "[100.0,10.0,0.0]\n" ] } ], "source": [ - "nodalloads[3, perm[82]] = -0.0001\n", - "println(model[\"nodes\"][83])" + "#nodalloads[3, perm[82]] = -0.06\n", + "nodalloads[3, 82] = -50.0\n", + "println(model[\"nodes\"][82])" ] }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 12, "metadata": { "collapsed": false }, "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "iteration 1, norm = 93.13879357262775\n", + "iteration 2, norm = 14.241640589907869\n", + "iteration 3, norm = 2.3999534862146534\n", + "iteration 4, norm = 0.8191634532858331\n", + "iteration 5, norm = 0.08574651168344295\n", + "iteration 6, norm = 0.00032306479346201524\n", + "iteration 7, norm = 8.052462405199464e-9\n", + "iteration 8, norm = 3.0878906643174355e-14\n" + ] + }, { "data": { "text/plain": [ "3x298 Array{Float64,2}:\n", - " -76167.8 -73.0493 … 5.19615e7 -43075.8 \n", - " -7.72988e5 6.45188e5 8.51808e7 559158.0 \n", - " 1.26765e6 -74404.1 -2.43735e7 6.01587e5" + " -0.0479657 -0.0483971 -0.0497284 … -0.0155295 -0.0150513 -0.0462958\n", + " -0.474054 -0.418817 -0.254176 -0.229641 -0.283098 -0.694379 \n", + " 0.232677 0.198051 0.0948355 0.128246 0.162511 0.371043 " ] }, - "execution_count": 39, + "execution_count": 12, "metadata": {}, "output_type": "execute_result" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Converged\n" + ] } ], "source": [ @@ -626,6 +655,7 @@ " JuliaFEM.elasticity_solver.solve_elasticity_increment!(X, u, du, elmap, nodalloads, dirichletbc,\n", " la, mu, Ntet, dNtet, ipoints, iweights)\n", " u += du\n", + " println(\"iteration $i, norm = $(norm(du))\")\n", " if norm(du) < 1.0e-9\n", " println(\"Converged\")\n", " break\n", @@ -635,10 +665,765 @@ ] }, { - "cell_type": "markdown", - "metadata": {}, + "cell_type": "code", + "execution_count": 13, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "15.449170689704438" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "Not converging." + "maximum(abs(u))" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "(10,120)" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "size(elmap)" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "120" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "nelements" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "11x120 Array{Int64,2}:\n", + " 38 38 38 38 38 38 38 38 … 38 38 38 38 38 38 38\n", + " 243 204 259 145 96 96 236 285 217 69 154 179 203 96 259\n", + " 240 199 70 175 88 101 88 179 216 144 114 91 204 267 199\n", + " 191 175 69 199 236 164 285 178 278 78 278 178 259 95 204\n", + " 117 130 130 130 178 97 178 83 155 71 218 83 199 97 130\n", + " 245 207 265 177 141 102 290 12 … 219 146 20 181 206 268 39\n", + " 242 208 72 208 290 171 289 182 282 152 280 180 263 272 207\n", + " 244 209 5 202 291 9 287 11 33 79 32 182 262 98 263\n", + " 1 3 6 174 7 99 237 13 224 74 223 14 205 99 6\n", + " 2 4 132 176 8 103 8 14 225 51 284 93 207 24 4\n", + " 196 176 134 4 237 10 11 15 … 17 80 283 15 39 100 3" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "elcodes = 0x0026*ones(Int, nelements)\n", + "elmap2 = [elcodes'\n", + " elmap]" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "WARNING: int(x) is deprecated, use Int(x) instead.\n" + ] + }, + { + "data": { + "text/plain": [ + "9568" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + " in depwarn at /Applications/Julia-0.4.0-dev-539c818c4e.app/Contents/Resources/julia/lib/julia/sys.dylib\n", + " in int at deprecated.jl:49\n", + " in save_file at /Users/jukka/.julia/v0.4/LightXML/src/document.jl:108\n", + " in xdmf_save_model at /Users/jukka/.julia/v0.4/JuliaFEM/src/xdmf.jl:140\n", + " in include_string at loading.jl:99\n", + " in execute_request_0x535c5df2 at /Users/jukka/.julia/v0.4/IJulia/src/execute_request.jl:157\n", + " in eventloop at /Users/jukka/.julia/v0.4/IJulia/src/IJulia.jl:123\n", + " in anonymous at task.jl:365\n", + "while loading In[17], in expression starting on line 7\n" + ] + } + ], + "source": [ + "xdoc, xmodel = JuliaFEM.xdmf.xdmf_new_model()\n", + "temporal_collection = JuliaFEM.xdmf.xdmf_new_temporal_collection(xmodel)\n", + "grid = JuliaFEM.xdmf.xdmf_new_grid(temporal_collection; time=0)\n", + "JuliaFEM.xdmf.xdmf_new_mesh(grid, X, elmap2)\n", + "#JuliaFEM.xdmf.xdmf_new_field(grid, \"Displacement\", \"nodes\", u)\n", + "#print(xdoc)\n", + "JuliaFEM.xdmf.xdmf_save_model(xdoc, \"/tmp/foo3d2.xmf\")" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "10x2 Array{Int64,2}:\n", + " 243 145\n", + " 240 199\n", + " 191 69\n", + " 117 130\n", + " 245 202\n", + " 242 47\n", + " 244 148\n", + " 1 174\n", + " 2 4\n", + " 196 134" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "elmap[:,[1, 101]]" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "3x10 Array{Float64,2}:\n", + " 20.0 30.0 20.0 20.0 25.0 25.0 20.0 20.0 25.0 20.0\n", + " 0.0 0.0 0.0 10.0 0.0 0.0 0.0 5.0 5.0 5.0\n", + " 10.0 10.0 0.0 0.0 10.0 5.0 5.0 5.0 5.0 0.0" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "tmp = elmap[:,[1]]\n", + "tmp = reshape(tmp, length(tmp))\n", + "X[:, tmp]" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "11x1 Array{Int64,2}:\n", + " 38\n", + " 1\n", + " 2\n", + " 3\n", + " 4\n", + " 5\n", + " 6\n", + " 7\n", + " 8\n", + " 9\n", + " 10" + ] + }, + "execution_count": 26, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#tmpelmap = [38 1 2 3 4 5 6 7 8 9 10; 38 11 12 13 14 15 16 17 18 19 20]'\n", + "tmpelmap = [38 1 2 3 4 5 6 7 8 9 10]'" + ] + }, + { + "cell_type": "code", + "execution_count": 48, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "\n", + "\n" + ] + }, + { + "data": { + "text/plain": [ + "28476" + ] + }, + "execution_count": 48, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "using LightXML\n", + "\n", + "function xdmf_new_mesh(grid, X, elmap)\n", + " dim, nnodes = size(X)\n", + " geometry = new_child(grid, \"Geometry\")\n", + " set_attribute(geometry, \"Type\", \"XYZ\")\n", + " dataitem = new_child(geometry, \"DataItem\")\n", + " set_attribute(dataitem, \"DataType\", \"Float\")\n", + " set_attribute(dataitem, \"Dimensions\", \"$nnodes $dim\")\n", + " set_attribute(dataitem, \"Format\", \"XML\")\n", + " set_attribute(dataitem, \"Precision\", 8)\n", + " #add_text(dataitem, join(X, \" \"))\n", + " s = \"\\n\"\n", + " \n", + " for i=1:nnodes\n", + " s *= \"\\t\\t\" * join(X[:,i], \" \") * \"\\n\"\n", + " end\n", + " s *= \" \"\n", + " add_text(dataitem, s)\n", + "\n", + " elmap2 = copy(elmap)\n", + " elmap2[2:end,:] -= 1\n", + " dim, nelements = size(elmap2)\n", + "\n", + " topology = new_child(grid, \"Topology\")\n", + " #set_attribute(topology, \"Dimensions\", \"1\")\n", + " set_attribute(topology, \"TopologyType\", \"Mixed\")\n", + " set_attribute(topology, \"NumberOfElements\", nelements)\n", + " dataitem = new_child(topology, \"DataItem\")\n", + " set_attribute(dataitem, \"DataType\", \"Int\")\n", + " set_attribute(dataitem, \"Dimensions\", \"$nelements $dim\")\n", + " set_attribute(dataitem, \"Format\", \"XML\")\n", + " set_attribute(dataitem, \"Precision\", 8)\n", + " s = \"\\n\"\n", + " for i=1:nelements\n", + " s *= \"\\t\\t\" * join(elmap2[:,i], \" \") * \"\\n\"\n", + " end\n", + " add_text(dataitem, s)\n", + " #add_text(dataitem, join(elmap2, \" \"))\n", + " \n", + "end\n", + "\n", + "xdoc, xmodel = JuliaFEM.xdmf.xdmf_new_model()\n", + "temporal_collection = JuliaFEM.xdmf.xdmf_new_temporal_collection(xmodel)\n", + "grid = JuliaFEM.xdmf.xdmf_new_grid(temporal_collection; time=0)\n", + "xdmf_new_mesh(grid, X, elmap2)\n", + "JuliaFEM.xdmf.xdmf_new_field(grid, \"Displacement\", \"nodes\", u)\n", + "print(xdoc)\n", + "JuliaFEM.xdmf.xdmf_save_model(xdoc, \"/tmp/foo3d.xmf\")" ] } ],