Wed, 22 Dec 2021 11:13:38 +0200
Planar finite elements, simple linear solvers for fixed dimensions
37
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
1 | """ |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
2 | Simple planar (2D) finite element discretisation on a box. |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
3 | """ |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
4 | module PlanarFE |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
5 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
6 | import ..Loops: Box |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
7 | import ..LinSolve: linsolve |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
8 | using ..Metaprogramming |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
9 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
10 | export FEModel, |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
11 | FEUniform, |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
12 | UniformP0, |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
13 | PlanarP0, |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
14 | LineP0, |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
15 | UniformP1, |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
16 | PlanarP1, |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
17 | LineP1, |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
18 | UniformP2, |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
19 | PlanarP2, |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
20 | LineP2, |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
21 | simplices, |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
22 | nodes, |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
23 | interpolate, |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
24 | differential, |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
25 | minimise |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
26 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
27 | const Location{N} = NTuple{N, Float64} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
28 | abstract type FEModel{N} end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
29 | abstract type FEUniform{N} <: FEModel{N} end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
30 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
31 | const Index = Int |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
32 | const CaseIndex = Int |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
33 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
34 | const NodeId{N} = NTuple{N, Index} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
35 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
36 | struct Node{N} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
37 | id :: NodeId{N} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
38 | x :: Location{N} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
39 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
40 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
41 | @inline function Base.getindex(a :: Array{T,N}, n :: Node{N}) where {T,N} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
42 | return getindex(a, n.id...) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
43 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
44 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
45 | @inline function Base.setindex!(a :: Array{T,N}, x :: T, n :: Node{N}) where {T,N} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
46 | return setindex!(a, x, n.id...) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
47 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
48 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
49 | ############################################## |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
50 | # Simplices |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
51 | ############################################## |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
52 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
53 | # (D-1)-dimensional simplex in ℝ^N. D is the node count. |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
54 | struct Simplex{N,D,Id} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
55 | id :: Id |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
56 | nodes :: NTuple{D, Node{N}} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
57 | @inline Simplex{Id}(id :: Id, nodes :: Vararg{Node{N}, D}) where {N,D,Id} = new{N,D,Id}(id, nodes) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
58 | @inline Simplex{N,D,Id}(id :: Id, nodes :: Vararg{Node{N}, D}) where {N,D,Id} = new{N,D,Id}(id, nodes) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
59 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
60 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
61 | # Uniformly indexed simplices |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
62 | const UCubeId{N} = NTuple{N, Int} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
63 | const USimplexId{N} = Tuple{UCubeId{N}, CaseIndex} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
64 | const USimplex{N,D} = Simplex{N,D,USimplexId{N}} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
65 | const PlanarSimplex = USimplex{2,3} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
66 | const RealInterval = USimplex{1,2} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
67 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
68 | @inline function Base.getindex(a :: Array{T,Nplus1}, s :: USimplex{N,D}) where {T,Nplus1,D,N} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
69 | idx = (s.id[1]..., s.id[2]) :: NTuple{Nplus1,Int} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
70 | return getindex(a, idx...) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
71 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
72 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
73 | @inline function Base.setindex!(a :: Array{T,Nplus1}, x :: T, s :: USimplex{N,D}) where {T,Nplus1,D,N} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
74 | idx = (s.id[1]..., s.id[2]) :: NTuple{Nplus1,Int} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
75 | return setindex!(a, x, idx...) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
76 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
77 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
78 | # We do this by invididual cases to allow typing return values |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
79 | # (N+1 is not calculable at compile time) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
80 | @inline function nodes(s :: Simplex{N,D,Id}) where {N,D,Id} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
81 | return s.nodes |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
82 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
83 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
84 | @inline @generated function dot(x :: Location{N}, y :: Location{N}) where N |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
85 | return foldl_exprs( :( + ), :( x[$i]*y[$i] ) for i=1:N) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
86 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
87 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
88 | @inline function orthog((x, y) :: Location{2}) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
89 | return (y, -x) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
90 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
91 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
92 | @inline function in_simplex(t :: RealInterval, x :: Location{1}) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
93 | (x₀, x₁) = nodes(t) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
94 | return ((x .- x₀)*(x₁ .- x₀) ≥ 0 && |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
95 | (x .- x₁)*(x₀ .- x₁) ≥ 0) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
96 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
97 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
98 | @inline function in_simplex(t :: PlanarSimplex, x :: Location{2}) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
99 | (x₀, x₁, x₁) = nodes(t) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
100 | return (dot(x .- x₀, orthog(x₁ .- x₀)) ≥ 0 && |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
101 | dot(x .- x₁, orthog(x₂ .- x₁)) ≥ 0 && |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
102 | dot(x .- x₂, orthog(x₀ .- x₂)) ≥ 0) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
103 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
104 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
105 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
106 | ############################################## |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
107 | # Simple planar grid and triangulation |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
108 | ############################################## |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
109 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
110 | @inline function cellwidth(box :: Box{N, Float64}, gridsize :: Dims{N}) where N |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
111 | return (((box[i][2]-box[i][1])/(gridsize[i]-1) for i=1:N)...,) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
112 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
113 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
114 | # Cannot calculate N+1 compile-time |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
115 | struct UniformGrid{N,Nplus1} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
116 | box :: Box{N, Float64} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
117 | size :: Dims{N} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
118 | cellwidth :: NTuple{N, Float64} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
119 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
120 | function UniformGrid{N,Nplus1}(box :: Box{N, Float64}, gridsize :: Dims{N}) where {N,Nplus1} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
121 | # TODO: Nested tuple access is inefficient |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
122 | @assert(N+1 == Nplus1) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
123 | @assert(all(box[i][2]>box[i][1] for i=1:N)) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
124 | @assert(all(gridsize .≥ 2)) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
125 | return new{N,Nplus1}(box, gridsize, cellwidth(box, gridsize)) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
126 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
127 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
128 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
129 | const LineGrid = UniformGrid{1,2} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
130 | const PlanarGrid = UniformGrid{2,3} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
131 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
132 | # Number of simplices in a cube of dimension N. |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
133 | n_simplex_cases( :: LineGrid) = 1 :: CaseIndex |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
134 | n_simplex_cases( :: PlanarGrid) = 2 :: CaseIndex |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
135 | max_cube_id(grid :: UniformGrid{N, Nplus1}) where {N, Nplus1} = grid.size .- 1 |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
136 | max_simplex_id(grid :: UniformGrid{N, Nplus1}) where {N, Nplus1} = |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
137 | (max_cube_id(grid)..., n_simplex_cases(grid)) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
138 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
139 | ∈(x :: Location{N}, b :: Box{N}) where N = all(b[i][1] ≤ x[i] ≤ b[i][2] for i=1:N) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
140 | ∉(x :: Location{N}, b :: Box{N}) where N = !(x ∈ b) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
141 | ∈(x :: Location{N}, grid :: UniformGrid{N,Nplus1}) where {N,Nplus1} = x ∈ grid.box |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
142 | ∉(x :: Location{N}, grid :: UniformGrid{N,Nplus1}) where {N,Nplus1} = x ∉ grid.box |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
143 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
144 | @inline function width(grid :: UniformGrid{N,Nplus1}) where {N,Nplus1} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
145 | return ((grid.box[i][2]-grid.box[i][1] for i=1:N)...,) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
146 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
147 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
148 | @inline function shift(grid :: UniformGrid{N,Nplus1}) where {N,Nplus1} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
149 | return ((grid.box[i][1] for i=1:N)...,) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
150 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
151 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
152 | function construct_node(grid :: UniformGrid{N,Nplus1}, idx :: NodeId{N}) :: Node{N} where {N,Nplus1} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
153 | loc = grid.cellwidth.*(idx.-1).+shift(grid) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
154 | return Node{N}(idx, loc) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
155 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
156 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
157 | @inline function construct_simplex(grid :: LineGrid, id :: USimplexId{1}) :: RealInterval |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
158 | # TODO: optimise case away |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
159 | (idx, _) = id |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
160 | return RealInterval(construct_node(grid, idx), construct_node(grid, idx.+(1,))) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
161 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
162 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
163 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
164 | # In 2D we alternate ⧄ and ⧅. The “base” 90° corner is always listed first. |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
165 | # It has importance for P0 elements. Otherwise arbitrary we proceed clockwise. |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
166 | # Julia is real GARBAGE. It does tons of memory alloc trying to access this in |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
167 | # any form, as Array or Tuple. Therefore things are in code below. |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
168 | # offset₂ = [[ |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
169 | # [(1, 0), (0, 0), (1, 1)], # ◪ |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
170 | # [(0, 1), (1, 1), (0, 0)], # ◩ |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
171 | # ],[ |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
172 | # [(0, 0), (1, 0), (0, 1)], # ⬕ |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
173 | # [(1, 1), (1, 0), (0, 1)], # ⬔ |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
174 | # ]] :: Array{Array{Array{Tuple{Int,Int},1},1},1} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
175 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
176 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
177 | @inline function sqform₂(idx :: UCubeId{2}) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
178 | return 1+(idx[1]+idx[2])%2 |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
179 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
180 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
181 | # 2D simplices are identified by their “leading” node, i.e., the lower-left corner of the grid square |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
182 | # that contains them, and the “case” number 1 or 2. |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
183 | function construct_simplex(grid :: PlanarGrid, simplexid :: USimplexId{2}, form :: Index) :: PlanarSimplex |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
184 | (idx, case) = simplexid |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
185 | @assert(all(idx .< grid.size)) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
186 | @assert(form==1 || form==2) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
187 | @assert(case==1 || case==2) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
188 | (off1 :: NodeId{2}, off2 :: NodeId{2}, off3 :: NodeId{2}) = (form==1 ? |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
189 | (case==1 ? |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
190 | ((1, 0), (0, 0), (1, 1)) # ◪ |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
191 | : |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
192 | ((0, 1), (1, 1), (0, 0)) # ◩ |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
193 | ) : (case==1 ? |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
194 | ((0, 0), (1, 0), (0, 1)) # ⬕ |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
195 | : |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
196 | ((1, 1), (1, 0), (0, 1)) # ⬔ |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
197 | )) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
198 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
199 | return PlanarSimplex(simplexid, |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
200 | construct_node(grid, idx .+ off1), |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
201 | construct_node(grid, idx .+ off2), |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
202 | construct_node(grid, idx .+ off3)) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
203 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
204 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
205 | function construct_simplex(grid :: PlanarGrid, simplexid :: USimplexId{2}) :: PlanarSimplex |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
206 | (idx, _) = simplexid |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
207 | return construct_simplex(grid, simplexid, sqform₂(idx)) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
208 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
209 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
210 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
211 | @inline function get_cubeid(grid :: UniformGrid{N,Nplus1}, x :: Location{N}) :: UCubeId{N} where {N,Nplus1} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
212 | (( |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
213 | # Without the :: Int typeassert this generates lots of memory allocs, although a typeof() |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
214 | # check here confirms that the type is Int. Julia is just as garbage as everything. |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
215 | max(min(ceil(Index, (x[i]-grid.box[i][1])/grid.cellwidth[i]), grid.size[i] - 1), 1) :: Int |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
216 | for i=1:N)...,) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
217 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
218 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
219 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
220 | @inline function get_offset(grid :: UniformGrid{N,Nplus1}, cubeid :: UCubeId{N}, x :: Location{N}) :: Location{N} where {N,Nplus1} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
221 | (( |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
222 | (x[i] - (cubeid[i] - 1) * grid.cellwidth[i]) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
223 | for i=1:N)...,) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
224 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
225 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
226 | @inline function simplex_at(grid :: LineGrid, x :: Location{1}) :: RealInterval |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
227 | if x ∉ grid.box |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
228 | throw("Coordinate $x out of domain $(grid.box)") |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
229 | else |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
230 | return construct_simplex(grid, get_cubeid(grid, x)) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
231 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
232 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
233 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
234 | @inline function simplex_at(grid :: PlanarGrid, x :: Location{2}) :: PlanarSimplex |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
235 | if x ∉ grid.box |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
236 | throw("Coordinate $x out of domain $(grid.box)") |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
237 | else |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
238 | # Lower left node is is cube id. Therefore maximum cubeid is grid size - 1 |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
239 | # in each dimension. |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
240 | cubeid = get_cubeid(grid, x) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
241 | off = get_offset(grid, cubeid, x) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
242 | form = sqform₂(cubeid) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
243 | if form==0 |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
244 | # ⧄ → ◪ or ◩ |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
245 | case = (off[1]>off[2] ? 1 : 2 ) :: CaseIndex |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
246 | else |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
247 | # ⧅ → ⬕ or ⬔ |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
248 | case = (off[1]+off[2]<1 ? 1 : 2) :: CaseIndex |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
249 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
250 | return construct_simplex(grid, (cubeid, case), form) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
251 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
252 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
253 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
254 | ############################################## |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
255 | # Edges for P2 elements |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
256 | ############################################## |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
257 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
258 | const Edge{N,Id} = Simplex{N,2,Id} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
259 | const UEdgeId{N} = USimplexId{N} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
260 | const UEdge{N} = Edge{N,UEdgeId{N}} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
261 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
262 | @inline midpoint(e :: Edge{N,Id}) where {N,Id} = (e.nodes[1].x .+ e.nodes[2].x) ./ 2.0 |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
263 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
264 | # For our purposes, an edge is something useful for putting an interpolation midpoint on. |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
265 | # This in 1D there's one “edge”, which is just the original simplex. |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
266 | n_cube_edges( :: LineGrid) = 1 |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
267 | n_cube_edges( :: PlanarGrid) = 3 |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
268 | max_edge_id(grid :: UniformGrid{N, Nplus1}) where {N, Nplus1} = (grid.size..., n_cube_edges(grid)) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
269 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
270 | @inline function edge_id(node₁ :: NodeId{1}, node₂ :: NodeId{1}) :: UEdgeId{1} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
271 | return (min(node₁[1], node₂[1]),) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
272 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
273 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
274 | # Edges are identified by the lower left node of the “least-numbered” cube that |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
275 | # contains them, along with 1=horizontal, 2=vertical, 3=diagonal. |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
276 | # Both of the alternating cases of diagonal edges have the same number. |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
277 | # Since the least-numbered cube identifies edges, only both diagonal the left and |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
278 | # bottom border of the cube are counted for that cube, so there are 3 possible |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
279 | # edges counted towards a cube. |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
280 | function edge_id(idx₁ :: NodeId{2}, idx₂ :: NodeId{2}) :: UEdgeId{2} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
281 | # For performance this does not verify that idx₁ and idx₂ are in the |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
282 | # same simplex, it only uses their ordering! |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
283 | if idx₂[1] > idx₁[1] # one of ↗︎, →, ↘︎ |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
284 | if idx₂[2] > idx₁[2] |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
285 | return (idx₁, 3) # diagonal ↗︎ in cube(idx₁) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
286 | elseif idx₂[2] == idx₁[2] |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
287 | return (idx₁, 1) # lower side → in cube(idx₁) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
288 | else # idx₂[2] < idx₁[2] |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
289 | return ((idx₁[1], idx₂[2]), 3) # ↘︎ in cube(prev(idx₁,idx₂)) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
290 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
291 | elseif idx₂[1] == idx₁[1] # one of ↑, ↓ |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
292 | if idx₂[2] > idx₁[2] |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
293 | return (idx₁, 2) # ↑ in cube(idx₁) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
294 | elseif idx₂[2] == idx₁[2] |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
295 | throw("Edge cannot end in starting idx.") |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
296 | else # idx₂[2] < idx₁[2] |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
297 | return (idx₂, 2) # ↓ cube(idx₂) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
298 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
299 | else # idx₂[1] < idx₁[1] # one of ↙︎, ←, ↖︎ |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
300 | if idx₂[2] > idx₁[2] |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
301 | return ((idx₁[1], idx₂[2]), 3) # diagonal ↖︎ in cube(prev(idx₁,idx₂)) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
302 | elseif idx₂[2] == idx₁[2] |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
303 | return (idx₂, 1) # lower side ← in cube(idx₂) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
304 | else # idx₂[2] < idx₁[2] |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
305 | return (idx₂, 3) # ↙︎ in cube(idx₂) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
306 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
307 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
308 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
309 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
310 | function construct_edge(n₁ :: Node{N}, n₂ :: Node{N}) where N |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
311 | return UEdge{N}(edge_id(n₁.id, n₂.id), n₁, n₂) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
312 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
313 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
314 | ############################################## |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
315 | # Iteration over simplices and nodes |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
316 | ############################################## |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
317 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
318 | struct Iter{G,W} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
319 | grid :: G |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
320 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
321 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
322 | # @inline function nodes(s :: PlanarSimplex{N}) where N |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
323 | # return Iter{PlanarSimplex{N}, :nodes}(s) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
324 | # end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
325 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
326 | # @inline function Base.iterate(sn :: Iter{PlanarSimplex{N}, :nodes}) where N |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
327 | # return (sn.p.base, Index(0)) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
328 | # end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
329 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
330 | # @inline function Base.iterate(sn :: Iter{PlanarSimplex{N}, :nodes}, idx :: Index) where N |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
331 | # if idx==length(sn.p.tips) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
332 | # return nothing |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
333 | # else |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
334 | # idx=idx+1 |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
335 | # return (sn.p.tips[idx], idx) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
336 | # end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
337 | # end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
338 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
339 | @inline function nodes(p :: M) where {N, M <: FEUniform{N}} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
340 | return nodes(p.grid) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
341 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
342 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
343 | @inline function nodes(grid :: UniformGrid{N,Nplus1}) where {N,Nplus1} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
344 | return Iter{UniformGrid{N,Nplus1}, Node{N}}(grid) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
345 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
346 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
347 | @inline function first_nodeid( :: UniformGrid{N,Nplus1}) :: NodeId{N} where {N,Nplus1} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
348 | return (( 1 :: Int for i=1:N)...,) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
349 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
350 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
351 | # Need to hard-code this for each N to avoid Julia munching memory. |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
352 | # Neither @generated nor plain code works. |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
353 | @inline function next_nodeid(grid :: LineGrid, idx :: NodeId{1}) :: Union{Nothing, NodeId{1}} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
354 | if idx[1] < grid.size[1] |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
355 | return (idx[1]+1,) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
356 | else |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
357 | return nothing |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
358 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
359 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
360 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
361 | @inline function next_nodeid(grid :: PlanarGrid, idx :: NodeId{2}) :: Union{Nothing, NodeId{2}} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
362 | if idx[1] < grid.size[1] |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
363 | return (idx[1]+1, idx[2]) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
364 | elseif idx[2] < grid.size[2] |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
365 | return (1 :: Int, idx[2]+1) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
366 | else |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
367 | return nothing |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
368 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
369 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
370 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
371 | function Base.iterate(iter :: Iter{UniformGrid{N,Nplus1}, Node{N}}) :: |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
372 | Union{Nothing, Tuple{Node{N}, NodeId{N}}} where {N,Nplus1} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
373 | idx = first_nodeid(iter.grid) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
374 | return construct_node(iter.grid, idx), idx |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
375 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
376 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
377 | function Base.iterate(iter :: Iter{UniformGrid{N,Nplus1}, Node{N}}, idx :: NodeId{N}) :: |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
378 | Union{Nothing, Tuple{Node{N}, NodeId{N}}} where {N,Nplus1} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
379 | nidx = next_nodeid(iter.grid, idx) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
380 | if isnothing(nidx) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
381 | return nothing |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
382 | else |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
383 | return construct_node(iter.grid, nidx), nidx |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
384 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
385 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
386 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
387 | # @generated function Base.iterate(iter :: Iter{N, Node{N}}, idx :: NodeId{N}) where N |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
388 | # # This generation reduces memory allocations |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
389 | # do_coord(i) = :( |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
390 | # if idx[$i] < iter.grid.size[$i] |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
391 | # nidx = $(lift_exprs(( (:( 1 :: Int ) for _=1:i-1)..., :( idx[$i]+1 ), ( :( idx[$j] ) for j=i+1:N)...,))) :: NTuple{N, Int} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
392 | # return construct_node(iter.grid, nidx), nidx |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
393 | # end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
394 | # ) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
395 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
396 | # return quote |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
397 | # $(sequence_exprs( do_coord(i) for i=1:N )) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
398 | # return nothing |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
399 | # end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
400 | # end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
401 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
402 | # function Base.iterate(iter :: Iter{N, Node{N}}, idx :: NodeId{N}) where N |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
403 | # for i=1:N |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
404 | # if idx[i]<iter.grid.size[i] |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
405 | # nidx = (( 1 :: Int for _=1:i-1)..., idx[i]+1, idx[i+1:N]...) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
406 | # return construct_node(iter.grid, nidx), nidx |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
407 | # end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
408 | # end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
409 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
410 | # return nothing |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
411 | # end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
412 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
413 | @inline function simplices(p :: M) where {N, M <: FEUniform{N}} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
414 | return simplices(p.grid) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
415 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
416 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
417 | @inline function simplices(grid :: UniformGrid{N,Nplus1}) where {N,Nplus1} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
418 | return Iter{UniformGrid{N,Nplus1}, USimplex{N,D}}(grid) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
419 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
420 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
421 | @inline function Base.iterate(iter :: Iter{UniformGrid{N,Nplus1}, Simplex{N,Nplus1}}) :: |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
422 | Union{Nothing, Tuple{USimplex{N,Nplus1}, USimplexId{N}}} where {N,Nplus1} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
423 | cubeid = ((Index(1) for i=1:N)...,) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
424 | simplexid = (cubeid, Index(1)) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
425 | return (construct_simplex(iter.grid, simplexid), simplexid) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
426 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
427 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
428 | @inline function Base.iterate(iter :: Iter{UniformGrid{N,Nplus1}, Simplex{N,Nplus1}}, |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
429 | (cubeid, case) :: USimplexId{N}) :: |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
430 | Union{Nothing, Tuple{USimplex{N,Nplus1}, USimplexId{N}}} where {N,Nplus1} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
431 | if case < n_simplex_cases(iter.grid) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
432 | simplexid = (cubeid, case+1) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
433 | return (construct_simplex(iter.grid, simplexid), simplexid) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
434 | else |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
435 | for i=1:N |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
436 | if cubeid[i]+1<iter.grid.size[i] |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
437 | new_cubeid=((Index(1) for _=1:i-1)..., cubeid[i]+1, cubeid[i+1:N]...) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
438 | simplexid = (new_cubeid, Index(1)) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
439 | return (construct_simplex(iter.grid, simplexid), simplexid) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
440 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
441 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
442 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
443 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
444 | return nothing |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
445 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
446 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
447 | # TODO: wrong for far-side boundary? Need to do by cumbe numbers |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
448 | @inline function edges(s :: RealInterval) :: Tuple{UEdge{1}} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
449 | return (construct_edge(s.nodes...),) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
450 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
451 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
452 | # TODO: Edge -> Simplex |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
453 | @inline function edges(s :: PlanarSimplex) :: NTuple{3,UEdge{2}} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
454 | return (construct_edge(s.nodes[1], s.nodes[2]), |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
455 | construct_edge(s.nodes[1], s.nodes[3]), |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
456 | construct_edge(s.nodes[2], s.nodes[3])) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
457 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
458 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
459 | @inline function edges(p :: M) where {N, M <: FEUniform{N}} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
460 | return edges(p.grid) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
461 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
462 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
463 | @inline function edges(grid :: LineGrid) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
464 | return Iter{LineGrid, UEdge{1}}(grid) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
465 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
466 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
467 | @inline function edges(grid :: PlanarGrid) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
468 | return Iter{PlanarGrid, UEdge{2}}(grid) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
469 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
470 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
471 | @inline function UEdge(grid :: LineGrid, edgeid :: UEdgeId{1}) :: UEdge{1} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
472 | (cubeid, case) = edgeid |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
473 | @assert(case==1) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
474 | return UEdge(edgeid, construct_node(grid, cubeid), construct_node(grid, cubeid.+(1,))) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
475 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
476 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
477 | @inline function next_edge_case(grid :: LineGrid, (cubeid, case) :: UEdgeId{1}) :: CaseIndex |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
478 | return -1 |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
479 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
480 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
481 | @inline function first_edge_case(grid :: LineGrid, cubeid :: UCubeId{1}) :: CaseIndex |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
482 | return cubeid[1] < grid.size[1] ? 1 : -1 |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
483 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
484 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
485 | @inline function UEdge(grid :: PlanarGrid, edgeid :: UEdgeId{2}) :: UEdge{2} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
486 | (cubeid, case) = edgeid |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
487 | e(idx1, idx2) = UEdge{2}(edgeid, construct_node(grid, idx1), construct_node(grid, idx2)) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
488 | if case==1 |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
489 | return e(cubeid, cubeid.+(1,0)) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
490 | elseif case==2 |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
491 | return e(cubeid, cubeid.+(0,1)) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
492 | elseif case==3 |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
493 | if sqform₂(cubeid)==1 |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
494 | return e(cubeid, cubeid.+(1,1)) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
495 | else |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
496 | return e(cubeid.+(1,0), cubeid.+(0,1)) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
497 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
498 | else |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
499 | throw("Invalid edge") |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
500 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
501 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
502 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
503 | @inline function first_edge_case(grid :: PlanarGrid, cubeid :: UCubeId{2}) :: CaseIndex |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
504 | if cubeid[1]<grid.size[1] |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
505 | return 1 |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
506 | elseif cubeid[2]<grid.size[2] |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
507 | return 2 |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
508 | else |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
509 | return -1 |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
510 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
511 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
512 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
513 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
514 | @inline function next_edge_case(grid :: PlanarGrid, (cubeid, case) :: UEdgeId{2}) :: CaseIndex |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
515 | if case<3 && cubeid[1]<grid.size[1] && cubeid[2]<grid.size[2] |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
516 | return case + 1 |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
517 | else |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
518 | return -1 |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
519 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
520 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
521 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
522 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
523 | @inline function Base.iterate(iter :: Iter{UniformGrid{N,Nplus1}, UEdge{N}}) :: |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
524 | Union{Nothing, Tuple{UEdge{N}, UEdgeId{N}}} where {N,Nplus1} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
525 | cubeid = first_nodeid(iter.grid) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
526 | case = first_edge_case(iter.grid, cubeid) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
527 | @assert(case ≥ 1) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
528 | edgeid = (cubeid, case) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
529 | return (UEdge(iter.grid, edgeid), edgeid) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
530 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
531 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
532 | @inline function Base.iterate(iter :: Iter{UniformGrid{N,Nplus1}, UEdge{N}}, (cubeid, case) :: UEdgeId{N}) :: |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
533 | Union{Nothing, Tuple{UEdge{N}, UEdgeId{N}}} where {N,Nplus1} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
534 | case = next_edge_case(iter.grid, (cubeid, case)) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
535 | if case ≥ 1 |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
536 | edgeid = (cubeid, case) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
537 | return (UEdge(iter.grid, edgeid), edgeid) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
538 | else |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
539 | while true |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
540 | cubeid = next_nodeid(iter.grid, cubeid) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
541 | if isnothing(cubeid) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
542 | return nothing |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
543 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
544 | case = first_edge_case(iter.grid, cubeid) :: Index |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
545 | if case ≥ 1 |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
546 | edgeid = (cubeid, case) :: UEdgeId{N} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
547 | return (UEdge(iter.grid, edgeid), edgeid) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
548 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
549 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
550 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
551 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
552 | return nothing |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
553 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
554 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
555 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
556 | ############################################## |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
557 | # Evaluation, differentiation, minimisation |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
558 | ############################################## |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
559 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
560 | function interpolate(p :: M, x :: Location{N}) where {N, M <: FEModel{N}} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
561 | return interpolate(p, simplex_at(p.grid, x), x) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
562 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
563 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
564 | # Apparent Julia bug / incomplete implementation: |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
565 | # https://stackoverflow.com/questions/46063872/parametric-functors-in-julia |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
566 | # How to do individually. |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
567 | # function (p :: M)(x :: Location{N}) where {N, M <: FEModel{N}} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
568 | # return interpolate(p, x) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
569 | # end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
570 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
571 | function differential(p :: M, x :: Location{N}) where {N, M <: FEModel{N}} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
572 | differential(p, simplex_at(p.grid, x), x) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
573 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
574 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
575 | function minimise(p :: M) where {N, M <: FEModel{N}} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
576 | minloc = nothing |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
577 | minv = nothing |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
578 | for simplex ∈ simplices(p) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
579 | thisminloc, thisminv = minimise(p, simplex) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
580 | if isnothing(minv) || minv < thisminv |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
581 | minv=thisminv |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
582 | minloc=thisminloc |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
583 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
584 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
585 | return minv, minloc |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
586 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
587 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
588 | ############################################## |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
589 | # P0 elements |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
590 | ############################################## |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
591 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
592 | struct UniformP0{N,Nplus1} <: FEUniform{N} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
593 | simplex_values :: Array{Float64, Nplus1} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
594 | grid :: UniformGrid{N,Nplus1} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
595 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
596 | function UniformP0{N,Nplus1}(simplex_values :: Array{Float64, Nplus1}, |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
597 | box :: Box{N, Float64}, gridsize :: Dims{N}) where {N,Nplus1} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
598 | grid = UniformGrid{N,Nplus1}(box, gridsize) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
599 | return new{N,Nplus1}(simplex_values, grid) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
600 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
601 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
602 | function UniformP0{N,Nplus1}(box :: Box{N, Float64}, gridsize :: Dims{N}) where {N,Nplus1} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
603 | grid = UniformGrid{N,Nplus1}(box, gridsize) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
604 | a = Array{Float64, Nplus1}(undef, max_simplex_id(grid)) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
605 | return new{N,Nplus1}(simplex_values, grid) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
606 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
607 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
608 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
609 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
610 | const LineP0 = UniformP0{1,1} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
611 | const PlanarP0 = UniformP0{2,3} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
612 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
613 | # f is not specified a type to allow callable objects and functions |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
614 | function UniformP0{N,Nplus1}(f, box :: Box{N, Float64}, gridsize :: Dims{N}) where {N,Nplus1} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
615 | p = UniformP0{N,Nplus1}(box, gridsize) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
616 | discretise!(f, p) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
617 | return p |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
618 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
619 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
620 | function (p :: UniformP0{N,Nplus1})(x :: Location{N}) where {N,Nplus1} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
621 | return interpolate(p, x) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
622 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
623 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
624 | @inline function interpolate(p :: UniformP0{N,Nplus1}, s :: Simplex{N,Nplus1}, x :: Location{N}) where {N,Nplus1} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
625 | return p.simplex_values[s] |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
626 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
627 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
628 | function differential(p :: UniformP0{N,Nplus1}, s :: Simplex{N,Nplus1}, x :: Location{N}) where {N,Nplus1} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
629 | return ((0.0 for i=1:N)...,) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
630 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
631 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
632 | @inline function minimise(p :: UniformP0{N,Nplus1}, s :: Simplex{N,Nplus1}) where {N,Nplus1} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
633 | return s.nodes[1].x, p.simplex_values[s] |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
634 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
635 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
636 | function discretise!(f, p :: UniformP0{N,Nplus1}) where {N,Nplus1} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
637 | for s ∈ simplices(p) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
638 | p.simplex_values[s]=f(s.nodes[1].x) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
639 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
640 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
641 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
642 | ############################################## |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
643 | # P1 elements |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
644 | ############################################## |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
645 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
646 | struct UniformP1{N,Nplus1} <: FEUniform{N} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
647 | node_values :: Array{Float64, N} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
648 | grid :: UniformGrid{N,Nplus1} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
649 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
650 | function UniformP1{N,Nplus1}(node_values :: Array{Float64, N}, |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
651 | box :: Box{N, Float64}, gridsize :: Dims{N}) where {N,Nplus1} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
652 | grid = UniformGrid{N,Nplus1}(box, gridsize) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
653 | return new{N,Nplus1}(node_values, grid) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
654 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
655 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
656 | function UniformP1{N,Nplus1}(box :: Box{N, Float64}, gridsize :: Dims{N}) where {N,Nplus1} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
657 | return UniformP1{N,Nplus1}(Array{Float64, N}(undef, gridsize), box, gridsize) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
658 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
659 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
660 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
661 | const LineP1 = UniformP1{1,1} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
662 | const PlanarP1 = UniformP1{2,3} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
663 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
664 | # f is not specified a type to allow callable objects and functions |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
665 | function UniformP1{N,Nplus1}(f, box :: Box{N, Float64}, gridsize :: Dims{N}) where {N,Nplus1} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
666 | p = UniformP1{N,Nplus1}(box, gridsize) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
667 | discretise!(f, p) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
668 | return p |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
669 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
670 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
671 | const P1NodalData{N} = Tuple{Location{N}, Float64} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
672 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
673 | # 1D model functions |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
674 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
675 | @inline function p1_simplicialf(((x₀,), v₀) :: P1NodalData{1}, |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
676 | ((x₁,), v₁) :: P1NodalData{1}) :: NTuple{2,Float64} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
677 | a₁ = (v₁-v₀)/(x₁-x₀) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
678 | a₀ = v₀ - a₁*x₀ |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
679 | return a₀, a₁ |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
680 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
681 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
682 | function p1_modelf(p :: UniformP1{1}, s :: RealInterval) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
683 | n₀, n₁ = nodes(s) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
684 | return p1_simplicialf((n₀.x, p.node_values[n₀]), |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
685 | (n₁.x, p.node_values[n₁])) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
686 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
687 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
688 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
689 | # 2D model functions |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
690 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
691 | @inline function p1_simplicialf((x₀, v₀) :: P1NodalData{2}, |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
692 | (x₁, v₁) :: P1NodalData{2}, |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
693 | (x₂, v₂) :: P1NodalData{2}) :: NTuple{3,Float64} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
694 | d = x₁ .- x₀ |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
695 | q = x₂ .- x₀ |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
696 | r = q[1]*d[2] - d[1]*q[2] |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
697 | a₁ = ((v₂-v₀)*d[2] - (v₁-v₀)*q[2])/r |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
698 | a₂ = ((v₁-v₀)*q[1] - (v₂-v₀)*d[1])/r |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
699 | a₀ = v₀-a₁*x₀[1]-a₂*x₀[2] |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
700 | return a₀, a₁, a₂ |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
701 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
702 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
703 | @inline function p1_modelf(p :: UniformP1{N,Nplus1}, s :: Simplex{N,Nplus1}) where {N,Nplus1} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
704 | return p1_simplicialf(((n.x, p.node_values[n]) for n ∈ nodes(s))...) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
705 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
706 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
707 | # @generated function p1_modelf(p :: UniformP1{N}, s :: PlanarSimplex{N}) where N |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
708 | # return quote |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
709 | # ns = nodes(s) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
710 | # p1_simplicialf($(lift_exprs( :((ns[$i].x, p.node_values[ns[$i].id...])) for i=1:3 ))...) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
711 | # end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
712 | # end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
713 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
714 | #@inline function g(a, (i,)) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
715 | # return a[i] |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
716 | #end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
717 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
718 | # @inline function g(a, (i, j)) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
719 | # return a[i,j] |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
720 | # end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
721 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
722 | # function p1_modelf(p :: UniformP1{2}, s :: PlanarSimplex{2}) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
723 | # n₀, n₁, n₂ = nodes(s) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
724 | # a, b = n₀.id[1], n₀.id[2] |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
725 | # v₀ = p.node_values[a, b] |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
726 | # a, b = n₁.id[1], n₁.id[2] |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
727 | # v₁ = p.node_values[a, b] |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
728 | # a, b = n₂.id[1], n₂.id[2] |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
729 | # v₂ = p.node_values[a, b] |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
730 | # return p1_simplicialf(n₀.x, v₀, |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
731 | # n₁.x, v₁, |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
732 | # n₂.x, v₂) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
733 | # end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
734 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
735 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
736 | # Common |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
737 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
738 | function (p :: UniformP1{N,Nplus1})(x :: Location{N}) where {N,Nplus1} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
739 | return interpolate(p, x) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
740 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
741 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
742 | function interpolate(p :: UniformP1{N,Nplus1}, s :: Simplex{N,Nplus1}, x :: Location{N}) where {N,Nplus1} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
743 | a = p1_modelf(p, s) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
744 | return +((a.*(1, x...))...) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
745 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
746 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
747 | @inline function differential(p :: UniformP1{N,Nplus1}, s :: Simplex{N,Nplus1}, :: Location{N}) :: Gradient{N} where {N,Nplus1} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
748 | a = p1_modelf(p, s) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
749 | return a[2:end] |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
750 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
751 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
752 | @inline function minimise(p :: UniformP1{N,Nplus1}, t :: Simplex{N,Nplus1}) where {N,Nplus1} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
753 | bestnode = s.nodes[1] |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
754 | bestvalue = p.node_values[bestnode] |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
755 | # The minima is found at a node, so only need to go through them |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
756 | for node ∈ s.nodes[2:end] |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
757 | value = p.node_values[node] |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
758 | if value < bestvalue |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
759 | bestvalue = value |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
760 | bestnode = node |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
761 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
762 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
763 | return bestnode.x, bestvalue |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
764 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
765 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
766 | function discretise!(f, p :: UniformP1{N,Nplus1}) where {N,Nplus1} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
767 | for n ∈ nodes(p) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
768 | p.node_values[n]=f(n.x) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
769 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
770 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
771 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
772 | ############################################## |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
773 | # P2 elements |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
774 | ############################################## |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
775 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
776 | const Gradient{N} = NTuple{N, Float64} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
777 | const P2NodalData{N} = Tuple{Location{N}, Float64, Gradient{N}} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
778 | const LocationAndGradient{N} = Tuple{Location{N}, Gradient{N}} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
779 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
780 | struct UniformP2{N,Nplus1} <: FEUniform{N} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
781 | node_values :: Array{Float64, N} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
782 | edge_values :: Array{Float64, Nplus1} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
783 | grid :: UniformGrid{N,Nplus1} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
784 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
785 | function UniformP2{N,Nplus1}( |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
786 | (node_values, edge_values) :: Tuple{Array{Float64, N}, Array{Float64, Nplus1}}, |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
787 | box :: Box{N, Float64}, gridsize :: Dims{N}) where {N, Nplus1} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
788 | return new{N,Nplus1}(node_values, edge_values, UniformGrid{N,Nplus1}(box, gridsize)) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
789 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
790 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
791 | function UniformP2{N,Nplus1}(box :: Box{N, Float64}, gridsize :: Dims{N}) where {N,Nplus1} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
792 | grid = UniformGrid{N,Nplus1}(box, gridsize) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
793 | na = Array{Float64, N}(undef, gridsize) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
794 | ne = Array{Float64, Nplus1}(undef, max_edge_id(grid)) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
795 | return new{N,Nplus1}(na, ne, grid) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
796 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
797 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
798 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
799 | const LineP2 = UniformP2{1,2} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
800 | const PlanarP2 = UniformP2{2,3} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
801 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
802 | # f is not specified a type to allow callable objects and functions |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
803 | function UniformP2{N,Nplus1}(f, box :: Box{N, Float64}, gridsize :: Dims{N}) where {N,Nplus1} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
804 | p = UniformP2{N,Nplus1}(box, gridsize) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
805 | discretise!(f, p) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
806 | return p |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
807 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
808 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
809 | # 1D model function |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
810 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
811 | @inline function p2powers(x :: Location{1}) :: NTuple{3, Float64} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
812 | return (1, x[1], x[1]*x[1]) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
813 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
814 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
815 | @inline function p2powers_diff(x :: Location{1}) :: NTuple{3, Float64} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
816 | return ((0, 1, 2*x[1]),) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
817 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
818 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
819 | @inline function p2_simplicialf(xv :: Vararg{P1NodalData{1},3}) :: NTuple{3, Float64} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
820 | Ab = (((p2powers(xv[i][1])..., xv[i][2]) for i = 1:3)...,) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
821 | return linsolve(Ab) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
822 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
823 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
824 | # 2D model function |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
825 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
826 | @inline function p2powers(x :: Location{2}) #:: NTuple{6, Float64} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
827 | return (1.0, x[1], x[2], x[1]*x[1], x[1]*x[2], x[2]*x[2]) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
828 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
829 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
830 | function p2powers_diff(x :: Location{2}) :: NTuple{6, Float64} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
831 | return ((0.0, 1.0, 0.0, 2*x[1], 2*x[2], 0.0), |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
832 | (0.0, 0.0, 1.0, 0.0, 2*x[1], 2*x[2])) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
833 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
834 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
835 | function p2_simplicialf(xv :: Vararg{P1NodalData{2},6}) :: NTuple{6, Float64} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
836 | Ab = (((p2powers(xv[i][1])..., xv[i][2]) for i = 1:6)...,) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
837 | return linsolve(Ab) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
838 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
839 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
840 | # Common |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
841 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
842 | @noinline function p2_modelf(p :: UniformP2{N,Nplus1}, s :: Simplex{N,Nplus1}) where {N,Nplus1} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
843 | a = (((n.x, p.node_values[n]) for n ∈ nodes(s))...,) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
844 | b = (((midpoint(e), p.edge_values[e]) for e ∈ edges(s))...,) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
845 | return p2_simplicialf(a..., |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
846 | b...) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
847 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
848 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
849 | @inline function interpolate(p :: UniformP2{N,Nplus1}, s :: Simplex{N,Nplus1}, x :: Location{N}) where {N,Nplus1} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
850 | a = p2_modelf(p, s) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
851 | p = p2powers(x) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
852 | return +((a.*p)...) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
853 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
854 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
855 | function (p :: UniformP2{N,Nplus1})(x :: Location{N}) where {N,Nplus1} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
856 | return interpolate(p, x) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
857 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
858 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
859 | @inline function differential(p :: UniformP2{N,Nplus1}, s :: Simplex{N,Nplus1}, |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
860 | x :: Location{N}) :: Gradient{N} where {N,Nplus1} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
861 | a = p2_modelf(p, s) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
862 | d = p2powers_diff(x) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
863 | return (+((a.*di)...) for di ∈ d) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
864 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
865 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
866 | @inline function minimise_p2_1d(a, (x₀, x₁)) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
867 | (_, a₁, a₁₁) = a |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
868 | # We do this in cases, first trying for an interior solution, then edges. |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
869 | # For interior solution, first check determinant; no point trying if non-positive |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
870 | if a₁₁ > 0 |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
871 | # An interior solution x[1] has to satisfy |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
872 | # 2a₁₁*x[1] + a₁ =0 |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
873 | # This gives |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
874 | x = (-a₁/(2*a₁₁),) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
875 | if in_simplex(t, x) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
876 | return x, +(a.*p2powers(x)) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
877 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
878 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
879 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
880 | (x₀, x₁) = nodes(t) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
881 | v₀ = +((a.*p2powers(x₀))...) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
882 | v₁ = +((a.*p2powers(x₁))...) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
883 | return v₀ > v₁ ? (x₀, v₀) : (x₁, v₁) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
884 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
885 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
886 | function minimise(p :: LineP2, t :: RealInterval) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
887 | minimise_p2_1d(p2_modelf(p, s), nodes(t)) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
888 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
889 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
890 | @inline function minimise_p2_edge((a₀, a₁, a₂, a₁₁, a₁₂, a₂₂), x₀, x₁) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
891 | # Minimise the 2D model on the edge {x₀ + t(x₁ - x₀) | t ∈ [0, 1] } |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
892 | d = x₁ .- x₀ |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
893 | b₀ = a₀ + a₁*x₀[1] + a₂*x₀[2] + a₁₁*x₀[1]*x₀[1] + a₁₂*x₀[1]*x₀[2] + a₂₂*x₀[2]*x₀[2] |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
894 | b₁ = a₁*d[1] + a₂*d[2] + 2*a₁₁*d[1]*x₀[1] + a₁₂*(d[1]*x₀[2] + d[2]*x₀[1]) + 2*a₂₂*d[2]*x₀[2] |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
895 | b₁₁ = a₁₁*d[1]*d[1] + a₁₂*d[1]*d[2] + a₂₂*d[2]*d[2] |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
896 | t, v = minimise_p2_1d((b₀, b₁, b₁₁), (0, 1)) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
897 | return @.(x₀ + t*d), v |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
898 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
899 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
900 | @inline function minimise(p :: PlanarP2, t :: PlanarSimplex) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
901 | a = (_, a₁, a₂, a₁₁, a₁₂, a₂₂) = p2_modelf(p, s) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
902 | # We do this in cases, first trying for an interior solution, then edges. |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
903 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
904 | # For interior solution, first check determinant; no point trying if non-positive |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
905 | r = 2*(a₁₁*a₂₂-a₁₂*a₁₂) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
906 | if r > 0 |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
907 | # An interior solution (x[1], x[2]) has to satisfy |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
908 | # 2a₁₁*x[1] + 2a₁₂*x[2]+a₁ =0 and 2a₂₂*x[1] + 2a₁₂*x[1]+a₂=0 |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
909 | # This gives |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
910 | x = ((a₂₂*a₁-a₁₂*a₂)/r, (a₁₂*a₁-a₁₁*a₂)/r) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
911 | if in_simplex(t, x) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
912 | return x, +(a.*p2powers(x)) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
913 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
914 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
915 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
916 | (x₀, x₁, x₁) = nodes(t) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
917 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
918 | x₀₁, v₀₁ = minimise_p2_edge(a, x₀, x₁) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
919 | x₁₂, v₁₂ = minimise_p2_edge(a, x₁, x₂) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
920 | x₂₀, v₂₀ = minimise_p2_edge(a, x₂, x₀) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
921 | if v₀₁ > v₁₂ |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
922 | return v₀₁ > v₂₀ ? (x₀₁, v₀₁) : (x₂₀, v₂₀) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
923 | else |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
924 | return v₁₂ > v₂₀ ? (x₁₂, v₁₂) : (x₂₀, v₂₀) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
925 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
926 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
927 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
928 | function discretise!(f, p :: UniformP2{N,Nplus1}) where {N,Nplus1} |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
929 | for n ∈ nodes(p) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
930 | p.node_values[n] = f(n.x) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
931 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
932 | for e ∈ edges(p) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
933 | p.edge_values[e] = f(midpoint(e)) |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
934 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
935 | end |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
936 | |
f8be66557e0f
Planar finite elements, simple linear solvers for fixed dimensions
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
937 | end # module |