data structures iteration #3

This commit is contained in:
Jukka Aho
2015-10-30 12:40:56 +02:00
parent c28d21b4a1
commit cd1023cf08
16 changed files with 1995 additions and 926 deletions
File diff suppressed because it is too large Load Diff
@@ -89,13 +89,13 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 69,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"using JuliaFEM: Element, Field, FieldSet, Basis, Quad4"
"using JuliaFEM: Element, Field, FieldSet, Basis"
]
},
{
@@ -1724,6 +1724,109 @@
"source": [
"In this notebook the basic instructions how to develop JuliaFEM has been given. The most imporant concepts has been considered; how to develop own element with own basis, several ways how to define own equation, and how to finally assemble and calculate the problem using solver. Any comments and/or discussion about technical details, theory, programming, or from life in general is very desirable; our issue log is in address https://github.com/JuliaFEM/JuliaFEM.jl/issues"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Advanced stuff\n",
"\n",
"In last section of this tutorial we consider some of the more advanced things which may araise when developing own models.\n",
"\n",
"### Boundary element access to parent element + overriding equations in problems\n",
"\n",
"This kind of situation might happen when one is almost happy for some problem setting, but would like to change just one or two equations from it. For example boundary equation is not satisfying all the requirements and one would like to test something new. \n",
"\n",
"### Accessing integration points\n",
"\n",
"### Fields as a function of something.\n",
"- statistical variables\n",
"- field dependent from another field\n",
"- field dependent from time or spatial domain etc.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"using JuliaFEM: get_default_integration_points\n",
"\"\"\" 2-node radiation boundary element. \"\"\"\n",
"type DC2D2RAD <: Heat\n",
" element :: Seg2\n",
" integration_points :: Array{IntegrationPoint, 1}\n",
"end\n",
"function DC2D2RAD(element::Seg2)\n",
" integration_points = [\n",
" IntegrationPoint([0.0], 2.0)]\n",
" if !haskey(element, \"temperature\")\n",
" element[\"temperature\"] = FieldSet()\n",
" push!(element[\"temperature\"], Field([0.0, 0.0]))\n",
" end\n",
" DC2D2RAD(element, integration_points)\n",
"end\n",
"Base.size(equation::DC2D2RAD) = (1, 2)\n",
"\n",
"\"\"\" Calculate potential energy caused by radiation.\n",
"https://en.wikipedia.org/wiki/Stefan%E2%80%93Boltzmann_constant\n",
"\"\"\"\n",
"function JuliaFEM.get_potential_energy(equation::DC2D2RAD, ip, time; variation=nothing)\n",
" element = get_element(equation)\n",
" basis = get_basis(element)\n",
" eps = basis(\"emissivity\", ip, time)\n",
" #sig = basis(\"stefan-boltzmann constant\", ip, time)\n",
" sig = 5.670367e-8 # i guess stefan-boltzmann constant is constant ;)\n",
" T = basis(\"temperature\", ip, time, variation)\n",
" T_ext = basis(\"temperature external\", ip, time)\n",
" q = eps*sig*((T_ext+273.15)^4 - (T+273.15)^4)\n",
" println(ForwardDiff.value(q*T))\n",
" return q\n",
"end\n",
"JuliaFEM.has_potential_energy(equation::DC2D2RAD) = true\n",
"\n",
"Defining new equation mapping to old problem is one line command. Here we replace `DC2D2` $\\rightarrow$ `DC2DCRAD`\n",
"\n",
"function run_radiation_model()\n",
" # this is the same as before\n",
" element = Quad4([1, 2, 3, 4])\n",
" fieldset1 = FieldSet(\"geometry\", [Field(Vector[[0.0, 0.0], [1.0, 0.0], [1.0, 1.0], [0.0, 1.0]])])\n",
" fieldset2 = FieldSet(\"temperature thermal conductivity\", [Field(6.0)])\n",
" fieldset3 = FieldSet(\"temperature load\", [Field([12.0, 12.0, 12.0, 12.0])])\n",
" fieldset4 = FieldSet(\"density\", [Field(36.0)])\n",
" push!(element, fieldset1)\n",
" push!(element, fieldset2)\n",
" push!(element, fieldset3)\n",
" push!(element, fieldset4)\n",
"\n",
" # create boundary element\n",
" boundary_element = Seg2([1, 2])\n",
" push!(boundary_element, FieldSet(\"geometry\", [Field(Vector[[0.0, 0.0], [1.0, 0.0]])]))\n",
" push!(boundary_element, FieldSet(\"emissivity\", [Field(0.5)]))\n",
" push!(boundary_element, FieldSet(\"temperature external\", [Field(20.0)]))\n",
"\n",
" # set initial conditions\n",
" push!(element, FieldSet(\"temperature\", [Field([0.0, 0.0, 0.0, 0.0])]))\n",
" push!(boundary_element, FieldSet(\"temperature\", [Field([0.0, 1.0])]))\n",
" \n",
" # create problem, change element mapping\n",
" problem = PlaneHeatProblem()\n",
" problem[Seg2] = DC2D2RAD # Seg2 was previous DC2D2\n",
" push!(problem, element)\n",
" push!(problem, boundary_element)\n",
"\n",
" # run our \"unit test solver\"\n",
" free_dofs = [3, 4]\n",
" solve!(problem, free_dofs; max_iterations=4, dump_matrices=true)\n",
" basis = get_basis(boundary_element)\n",
" T = basis(\"temperature\", [0.0])\n",
" println(\"Temperature at the midpoint of element: $T\")\n",
"end\n",
"\n",
"run_radiation_model()"
]
}
],
"metadata": {