Skip to content

Instantly share code, notes, and snippets.

@fredrikekre
Created October 2, 2016 22:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fredrikekre/7f8195f7413573fcc69c9a9bceb06b31 to your computer and use it in GitHub Desktop.
Save fredrikekre/7f8195f7413573fcc69c9a9bceb06b31 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"include(\"src/JuAFEM.jl\")\n",
"using JuAFEM\n",
"using Base.Test"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Set up FEValues and FEFaceValues"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"JuAFEM.Lagrange{2,JuAFEM.RefCube,1}()"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"fs = Lagrange{2,RefCube,1}()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"JuAFEM.QuadratureRule{2,Float64}([0.308642,0.493827,0.308642,0.493827,0.790123,0.493827,0.308642,0.493827,0.308642],ContMechTensors.Tensor{1,2,Float64,2}[[-0.774597,-0.774597],[0.0,-0.774597],[0.774597,-0.774597],[-0.774597,0.0],[0.0,0.0],[0.774597,0.0],[-0.774597,0.774597],[0.0,0.774597],[0.774597,0.774597]])"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"QR = QuadratureRule(Dim{1},RefCube(),3)\n",
"QR2 = QuadratureRule(Dim{2},RefCube(),3)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"feface = JuAFEM.FEFaceValues(QR,fs)\n",
"feval = FEValues(QR2,fs);"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"4-element Array{ContMechTensors.Tensor{1,2,Float64,2},1}:\n",
" [0.0,0.0] \n",
" [5.0,3.0] \n",
" [6.0,10.0]\n",
" [1.0,9.0] "
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"x = [0.0 0.0;\n",
" 5.0 3.0;\n",
" 6.0 10.0;\n",
" 1.0 9.0]';\n",
"X = reinterpret(Vec{2,Float64},x,(4,))"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Reinit for all sides for luls\n",
"reinit!(feface,X,1)\n",
"reinit!(feface,X,2)\n",
"reinit!(feface,X,3)\n",
"reinit!(feface,X,4)\n",
"reinit!(feval,X)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"4-element Array{Array{Float64,1},1}:\n",
" [1.61971,2.59153,1.61971]\n",
" [1.96419,3.1427,1.96419] \n",
" [1.41639,2.26623,1.41639]\n",
" [2.51538,4.02462,2.51538]"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"feface.detJdS"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Test sum of the detJdS"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Test Summary: | Pass Total\n",
" sum of weights | 4 4\n"
]
}
],
"source": [
"@testset \"sum of weights\" begin\n",
" @test norm(X[1]-X[2]) == sum(feface.detJdS[1])\n",
" @test norm(X[2]-X[3]) == sum(feface.detJdS[2])\n",
" @test norm(X[3]-X[4]) == sum(feface.detJdS[3])\n",
" @test norm(X[4]-X[1]) == sum(feface.detJdS[4])\n",
"end;"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Utilities just as for FEValues"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"JuAFEM.QuadratureRule{2,Float64}([0.308642,0.493827,0.308642,0.493827,0.790123,0.493827,0.308642,0.493827,0.308642],ContMechTensors.Tensor{1,2,Float64,2}[[-0.774597,-0.774597],[0.0,-0.774597],[0.774597,-0.774597],[-0.774597,0.0],[0.0,0.0],[0.774597,0.0],[-0.774597,0.774597],[0.0,0.774597],[0.774597,0.774597]])"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"get_quadrule(feval)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"JuAFEM.QuadratureRule{2,Float64}([0.555556,0.888889,0.555556],ContMechTensors.Tensor{1,2,Float64,2}[[-1.0,-0.774597],[-1.0,0.0],[-1.0,0.774597]])"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"get_quadrule(feface)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"JuAFEM.Lagrange{2,JuAFEM.RefCube,1}()"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"get_functionspace(feval)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"JuAFEM.Lagrange{2,JuAFEM.RefCube,1}()"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"get_functionspace(feface)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"JuAFEM.Lagrange{2,JuAFEM.RefCube,1}()"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"JuAFEM.get_geometricspace(feval)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"JuAFEM.Lagrange{2,JuAFEM.RefCube,1}()"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"JuAFEM.get_geometricspace(feface)"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"3.1711718114942853"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"detJdV(feval,1)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"2.515384760593727"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"JuAFEM.detJdS(feface,1)"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"0.7872983346207417"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"shape_value(feval,1)\n",
"shape_value(feval,1,1)"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"0.8872983346207417"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"shape_value(feface,1)\n",
"shape_value(feface,1,1)"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"2-element ContMechTensors.Tensor{1,2,Float64,2}:\n",
" -0.129538 \n",
" -0.0863585"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"shape_gradient(feval,1)\n",
"shape_gradient(feval,1,1)"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"2-element ContMechTensors.Tensor{1,2,Float64,2}:\n",
" -0.123411 \n",
" -0.0973988"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"shape_gradient(feface,1)\n",
"shape_gradient(feface,1,1)"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"-0.21589614735851378"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"shape_divergence(feval,1,1)"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"-0.22080996917163048"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"shape_divergence(feface,1,1)"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"4-element Array{Float64,1}:\n",
" 0.594664\n",
" 0.948973\n",
" 0.861089\n",
" 0.937698"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"u = rand(4)"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"0.6677821588390144"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"function_scalar_value(feval,1,u)"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"0.6333242997314001"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"function_scalar_value(feface,1,u)"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"2-element ContMechTensors.Tensor{1,2,Float64,2}:\n",
" 0.0453971\n",
" 0.0283856"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"function_scalar_gradient(feval,1,u)"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"2-element ContMechTensors.Tensor{1,2,Float64,2}:\n",
" 0.0426263\n",
" 0.0333787"
]
},
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"function_scalar_gradient(feface,1,u)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Julia 0.5.0",
"language": "julia",
"name": "julia-0.5"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "0.5.0"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment