annotate SbpOperators/src/laplace/laplace.jl @ 311:f2d6ec89dfc5

Make apply dispatch on Index instead of Tuples of Index
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Wed, 09 Sep 2020 21:16:13 +0200
parents 6fa2ba769ae3
children c1fcc35e19cb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
286
7247e85dc1e8 Start separating ConstantStencilOp into multiple 1D tensor mappings, e.g. ConstantLaplaceOp. Sketch an implementation of the multi-D laplace tensor operator as a tuple of 1D laplace tensor operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 285
diff changeset
1 """
7247e85dc1e8 Start separating ConstantStencilOp into multiple 1D tensor mappings, e.g. ConstantLaplaceOp. Sketch an implementation of the multi-D laplace tensor operator as a tuple of 1D laplace tensor operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 285
diff changeset
2 Laplace{Dim,T<:Real,N,M,K} <: TensorOperator{T,Dim}
7247e85dc1e8 Start separating ConstantStencilOp into multiple 1D tensor mappings, e.g. ConstantLaplaceOp. Sketch an implementation of the multi-D laplace tensor operator as a tuple of 1D laplace tensor operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 285
diff changeset
3
7247e85dc1e8 Start separating ConstantStencilOp into multiple 1D tensor mappings, e.g. ConstantLaplaceOp. Sketch an implementation of the multi-D laplace tensor operator as a tuple of 1D laplace tensor operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 285
diff changeset
4 Implements the Laplace operator `L` in Dim dimensions as a tensor operator
300
b00eea62c78e Create 1D tensor mapping for diagonal norm quadratures, and make the multi-dimensional quadrature use those. Move Qudrature from laplace.jl into Quadrature.jl
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 293
diff changeset
5 The multi-dimensional tensor operator consists of a tuple of 1D SecondDerivative
b00eea62c78e Create 1D tensor mapping for diagonal norm quadratures, and make the multi-dimensional quadrature use those. Move Qudrature from laplace.jl into Quadrature.jl
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 293
diff changeset
6 tensor operators.
286
7247e85dc1e8 Start separating ConstantStencilOp into multiple 1D tensor mappings, e.g. ConstantLaplaceOp. Sketch an implementation of the multi-D laplace tensor operator as a tuple of 1D laplace tensor operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 285
diff changeset
7 """
282
ce6a2f3f732a Make Laplace a TensorOperator and add tests. NOTE: Two of the tests for Laplace2D are currently failing.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 281
diff changeset
8 struct Laplace{Dim,T<:Real,N,M,K} <: TensorOperator{T,Dim}
293
f63232aeb1c6 Move laplace.jl from DiffOps to SbpOperators. Rename constandlaplace to secondderivative
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 286
diff changeset
9 D2::NTuple(Dim,SecondDerivative{T,N,M,K})
286
7247e85dc1e8 Start separating ConstantStencilOp into multiple 1D tensor mappings, e.g. ConstantLaplaceOp. Sketch an implementation of the multi-D laplace tensor operator as a tuple of 1D laplace tensor operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 285
diff changeset
10 #TODO: Write a good constructor
228
5acef2d5db2e Move Laplace operator and related structs/functions to separate file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
11 end
282
ce6a2f3f732a Make Laplace a TensorOperator and add tests. NOTE: Two of the tests for Laplace2D are currently failing.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 281
diff changeset
12 export Laplace
228
5acef2d5db2e Move Laplace operator and related structs/functions to separate file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
13
286
7247e85dc1e8 Start separating ConstantStencilOp into multiple 1D tensor mappings, e.g. ConstantLaplaceOp. Sketch an implementation of the multi-D laplace tensor operator as a tuple of 1D laplace tensor operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 285
diff changeset
14 LazyTensors.domain_size(H::Laplace{Dim}, range_size::NTuple{Dim,Integer}) = range_size
282
ce6a2f3f732a Make Laplace a TensorOperator and add tests. NOTE: Two of the tests for Laplace2D are currently failing.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 281
diff changeset
15
ce6a2f3f732a Make Laplace a TensorOperator and add tests. NOTE: Two of the tests for Laplace2D are currently failing.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 281
diff changeset
16 function LazyTensors.apply(L::Laplace{Dim,T}, v::AbstractArray{T,Dim}, I::NTuple{Dim,Index}) where {T,Dim}
228
5acef2d5db2e Move Laplace operator and related structs/functions to separate file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
17 error("not implemented")
5acef2d5db2e Move Laplace operator and related structs/functions to separate file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
18 end
5acef2d5db2e Move Laplace operator and related structs/functions to separate file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
19
300
b00eea62c78e Create 1D tensor mapping for diagonal norm quadratures, and make the multi-dimensional quadrature use those. Move Qudrature from laplace.jl into Quadrature.jl
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 293
diff changeset
20 function LazyTensors.apply_transpose(L::Laplace{Dim,T}, v::AbstractArray{T,Dim}, I::NTuple{Dim,Index}) where {T,Dim} = LazyTensors.apply(L, v, I)
b00eea62c78e Create 1D tensor mapping for diagonal norm quadratures, and make the multi-dimensional quadrature use those. Move Qudrature from laplace.jl into Quadrature.jl
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 293
diff changeset
21
228
5acef2d5db2e Move Laplace operator and related structs/functions to separate file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
22 # u = L*v
282
ce6a2f3f732a Make Laplace a TensorOperator and add tests. NOTE: Two of the tests for Laplace2D are currently failing.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 281
diff changeset
23 function LazyTensors.apply(L::Laplace{1,T}, v::AbstractVector{T}, I::NTuple{1,Index}) where T
300
b00eea62c78e Create 1D tensor mapping for diagonal norm quadratures, and make the multi-dimensional quadrature use those. Move Qudrature from laplace.jl into Quadrature.jl
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 293
diff changeset
24 @inbounds u = apply(L.D2[1],v,I)
b00eea62c78e Create 1D tensor mapping for diagonal norm quadratures, and make the multi-dimensional quadrature use those. Move Qudrature from laplace.jl into Quadrature.jl
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 293
diff changeset
25 return u
228
5acef2d5db2e Move Laplace operator and related structs/functions to separate file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
26 end
5acef2d5db2e Move Laplace operator and related structs/functions to separate file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
27
282
ce6a2f3f732a Make Laplace a TensorOperator and add tests. NOTE: Two of the tests for Laplace2D are currently failing.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 281
diff changeset
28
ce6a2f3f732a Make Laplace a TensorOperator and add tests. NOTE: Two of the tests for Laplace2D are currently failing.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 281
diff changeset
29 @inline function LazyTensors.apply(L::Laplace{2,T}, v::AbstractArray{T,2}, I::NTuple{2,Index}) where T
228
5acef2d5db2e Move Laplace operator and related structs/functions to separate file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
30 # 2nd x-derivative
5acef2d5db2e Move Laplace operator and related structs/functions to separate file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
31 @inbounds vx = view(v, :, Int(I[2]))
300
b00eea62c78e Create 1D tensor mapping for diagonal norm quadratures, and make the multi-dimensional quadrature use those. Move Qudrature from laplace.jl into Quadrature.jl
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 293
diff changeset
32 @inbounds uᵢ = apply(L.D2[1], vx , I[1])
286
7247e85dc1e8 Start separating ConstantStencilOp into multiple 1D tensor mappings, e.g. ConstantLaplaceOp. Sketch an implementation of the multi-D laplace tensor operator as a tuple of 1D laplace tensor operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 285
diff changeset
33
228
5acef2d5db2e Move Laplace operator and related structs/functions to separate file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
34 # 2nd y-derivative
5acef2d5db2e Move Laplace operator and related structs/functions to separate file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
35 @inbounds vy = view(v, Int(I[1]), :)
300
b00eea62c78e Create 1D tensor mapping for diagonal norm quadratures, and make the multi-dimensional quadrature use those. Move Qudrature from laplace.jl into Quadrature.jl
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 293
diff changeset
36 @inbounds uᵢ += apply(L.D2[2], vy , I[2])
286
7247e85dc1e8 Start separating ConstantStencilOp into multiple 1D tensor mappings, e.g. ConstantLaplaceOp. Sketch an implementation of the multi-D laplace tensor operator as a tuple of 1D laplace tensor operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 285
diff changeset
37
228
5acef2d5db2e Move Laplace operator and related structs/functions to separate file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
38 return uᵢ
5acef2d5db2e Move Laplace operator and related structs/functions to separate file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
39 end
5acef2d5db2e Move Laplace operator and related structs/functions to separate file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
40
262
f1e90a92ad74 Add Quadrature and InverseQuadrature for Laplace as TensorMappings. Implement and test the 2D case. Fix implementation of apply_transpose for BoundaryQuadrature and add tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 259
diff changeset
41 quadrature(L::Laplace) = Quadrature(L.op, L.grid)
f1e90a92ad74 Add Quadrature and InverseQuadrature for Laplace as TensorMappings. Implement and test the 2D case. Fix implementation of apply_transpose for BoundaryQuadrature and add tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 259
diff changeset
42 inverse_quadrature(L::Laplace) = InverseQuadrature(L.op, L.grid)
252
9405c19b76bc Move boundary_value and similar methods of laplce
Jonatan Werpers <jonatan@werpers.com>
parents: 251
diff changeset
43 boundary_value(L::Laplace, bId::CartesianBoundary) = BoundaryValue(L.op, L.grid, bId)
9405c19b76bc Move boundary_value and similar methods of laplce
Jonatan Werpers <jonatan@werpers.com>
parents: 251
diff changeset
44 normal_derivative(L::Laplace, bId::CartesianBoundary) = NormalDerivative(L.op, L.grid, bId)
259
5571d2c5bf0f Implement BaoundaryQuadrature for Laplace
Jonatan Werpers <jonatan@werpers.com>
parents: 258
diff changeset
45 boundary_quadrature(L::Laplace, bId::CartesianBoundary) = BoundaryQuadrature(L.op, L.grid, bId)
283
12a12a5cd973 Fix tests for Laplace2D.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 282
diff changeset
46 export quadrature
228
5acef2d5db2e Move Laplace operator and related structs/functions to separate file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
47
235
a5fdc00d5070 Fix a bunch of compilation errors
Jonatan Werpers <jonatan@werpers.com>
parents: 228
diff changeset
48 """
a5fdc00d5070 Fix a bunch of compilation errors
Jonatan Werpers <jonatan@werpers.com>
parents: 228
diff changeset
49 BoundaryValue{T,N,M,K} <: TensorMapping{T,2,1}
a5fdc00d5070 Fix a bunch of compilation errors
Jonatan Werpers <jonatan@werpers.com>
parents: 228
diff changeset
50
258
3ea8c60ccef3 Fix a few typos in documentation and add a few TODOs
Jonatan Werpers <jonatan@werpers.com>
parents: 255
diff changeset
51 Implements the boundary operator `e` as a TensorMapping
235
a5fdc00d5070 Fix a bunch of compilation errors
Jonatan Werpers <jonatan@werpers.com>
parents: 228
diff changeset
52 """
a5fdc00d5070 Fix a bunch of compilation errors
Jonatan Werpers <jonatan@werpers.com>
parents: 228
diff changeset
53 struct BoundaryValue{T,N,M,K} <: TensorMapping{T,2,1}
248
05e7bbe0af97 Merge refactoring of laplace
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 247 245
diff changeset
54 op::D2{T,N,M,K}
255
e960b877e07e Be more precise about grid dimension in BoundaryValue and NormalDerivative
Jonatan Werpers <jonatan@werpers.com>
parents: 252
diff changeset
55 grid::EquidistantGrid{2}
248
05e7bbe0af97 Merge refactoring of laplace
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 247 245
diff changeset
56 bId::CartesianBoundary
228
5acef2d5db2e Move Laplace operator and related structs/functions to separate file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
57 end
235
a5fdc00d5070 Fix a bunch of compilation errors
Jonatan Werpers <jonatan@werpers.com>
parents: 228
diff changeset
58 export BoundaryValue
228
5acef2d5db2e Move Laplace operator and related structs/functions to separate file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
59
235
a5fdc00d5070 Fix a bunch of compilation errors
Jonatan Werpers <jonatan@werpers.com>
parents: 228
diff changeset
60 # TODO: This is obviouly strange. Is domain_size just discarded? Is there a way to avoid storing grid in BoundaryValue?
a5fdc00d5070 Fix a bunch of compilation errors
Jonatan Werpers <jonatan@werpers.com>
parents: 228
diff changeset
61 # Can we give special treatment to TensorMappings that go to a higher dim?
284
0b8e041a1873 Change how range_size and domain_size work with BoundaryValues and NormalDerivative
Jonatan Werpers <jonatan@werpers.com>
parents: 283
diff changeset
62 function LazyTensors.range_size(e::BoundaryValue{T}, domain_size::NTuple{1,Integer}) where T
0b8e041a1873 Change how range_size and domain_size work with BoundaryValues and NormalDerivative
Jonatan Werpers <jonatan@werpers.com>
parents: 283
diff changeset
63 if dim(e.bId) == 1
285
e21dcda55163 Add type representing an unknown dimension in the domain of tensormappings
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 284
diff changeset
64 return (UnknownDim, domain_size[1])
284
0b8e041a1873 Change how range_size and domain_size work with BoundaryValues and NormalDerivative
Jonatan Werpers <jonatan@werpers.com>
parents: 283
diff changeset
65 elseif dim(e.bId) == 2
285
e21dcda55163 Add type representing an unknown dimension in the domain of tensormappings
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 284
diff changeset
66 return (domain_size[1], UnknownDim)
284
0b8e041a1873 Change how range_size and domain_size work with BoundaryValues and NormalDerivative
Jonatan Werpers <jonatan@werpers.com>
parents: 283
diff changeset
67 end
0b8e041a1873 Change how range_size and domain_size work with BoundaryValues and NormalDerivative
Jonatan Werpers <jonatan@werpers.com>
parents: 283
diff changeset
68 end
244
a827568fc251 Fix NormalDerivative and add tests
Jonatan Werpers <jonatan@werpers.com>
parents: 242
diff changeset
69 LazyTensors.domain_size(e::BoundaryValue{T}, range_size::NTuple{2,Integer}) where T = (range_size[3-dim(e.bId)],)
284
0b8e041a1873 Change how range_size and domain_size work with BoundaryValues and NormalDerivative
Jonatan Werpers <jonatan@werpers.com>
parents: 283
diff changeset
70 # TODO: Make a nicer solution for 3-dim(e.bId)
235
a5fdc00d5070 Fix a bunch of compilation errors
Jonatan Werpers <jonatan@werpers.com>
parents: 228
diff changeset
71
258
3ea8c60ccef3 Fix a few typos in documentation and add a few TODOs
Jonatan Werpers <jonatan@werpers.com>
parents: 255
diff changeset
72 # TODO: Make this independent of dimension
281
1eefaefdd0c7 Add missing type parametrization
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 280
diff changeset
73 function LazyTensors.apply(e::BoundaryValue{T}, v::AbstractArray{T}, I::NTuple{2,Index}) where T
248
05e7bbe0af97 Merge refactoring of laplace
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 247 245
diff changeset
74 i = I[dim(e.bId)]
05e7bbe0af97 Merge refactoring of laplace
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 247 245
diff changeset
75 j = I[3-dim(e.bId)]
05e7bbe0af97 Merge refactoring of laplace
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 247 245
diff changeset
76 N_i = size(e.grid)[dim(e.bId)]
280
fe9e8737ddfa Change to using region indices in apply of BoundaryValue, NormalDerivative and BoundaryQuadrature
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 273
diff changeset
77 return apply_boundary_value(e.op, v[j], i, N_i, region(e.bId))
228
5acef2d5db2e Move Laplace operator and related structs/functions to separate file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
78 end
5acef2d5db2e Move Laplace operator and related structs/functions to separate file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
79
281
1eefaefdd0c7 Add missing type parametrization
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 280
diff changeset
80 function LazyTensors.apply_transpose(e::BoundaryValue{T}, v::AbstractArray{T}, I::NTuple{1,Index}) where T
280
fe9e8737ddfa Change to using region indices in apply of BoundaryValue, NormalDerivative and BoundaryQuadrature
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 273
diff changeset
81 u = selectdim(v,3-dim(e.bId),Int(I[1]))
269
ccef055233a2 Move general methods for D2 to ConstantStencilOperator and increase verbosity of method names for clarity
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 268
diff changeset
82 return apply_boundary_value_transpose(e.op, u, region(e.bId))
228
5acef2d5db2e Move Laplace operator and related structs/functions to separate file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
83 end
5acef2d5db2e Move Laplace operator and related structs/functions to separate file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
84
247
ed29ee13e92e Restructure laplace.jl
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 244
diff changeset
85 """
ed29ee13e92e Restructure laplace.jl
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 244
diff changeset
86 NormalDerivative{T,N,M,K} <: TensorMapping{T,2,1}
ed29ee13e92e Restructure laplace.jl
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 244
diff changeset
87
258
3ea8c60ccef3 Fix a few typos in documentation and add a few TODOs
Jonatan Werpers <jonatan@werpers.com>
parents: 255
diff changeset
88 Implements the boundary operator `d` as a TensorMapping
247
ed29ee13e92e Restructure laplace.jl
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 244
diff changeset
89 """
ed29ee13e92e Restructure laplace.jl
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 244
diff changeset
90 struct NormalDerivative{T,N,M,K} <: TensorMapping{T,2,1}
248
05e7bbe0af97 Merge refactoring of laplace
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 247 245
diff changeset
91 op::D2{T,N,M,K}
255
e960b877e07e Be more precise about grid dimension in BoundaryValue and NormalDerivative
Jonatan Werpers <jonatan@werpers.com>
parents: 252
diff changeset
92 grid::EquidistantGrid{2}
248
05e7bbe0af97 Merge refactoring of laplace
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 247 245
diff changeset
93 bId::CartesianBoundary
228
5acef2d5db2e Move Laplace operator and related structs/functions to separate file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
94 end
247
ed29ee13e92e Restructure laplace.jl
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 244
diff changeset
95 export NormalDerivative
228
5acef2d5db2e Move Laplace operator and related structs/functions to separate file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
96
247
ed29ee13e92e Restructure laplace.jl
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 244
diff changeset
97 # TODO: This is obviouly strange. Is domain_size just discarded? Is there a way to avoid storing grid in BoundaryValue?
ed29ee13e92e Restructure laplace.jl
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 244
diff changeset
98 # Can we give special treatment to TensorMappings that go to a higher dim?
284
0b8e041a1873 Change how range_size and domain_size work with BoundaryValues and NormalDerivative
Jonatan Werpers <jonatan@werpers.com>
parents: 283
diff changeset
99 function LazyTensors.range_size(e::NormalDerivative, domain_size::NTuple{1,Integer})
0b8e041a1873 Change how range_size and domain_size work with BoundaryValues and NormalDerivative
Jonatan Werpers <jonatan@werpers.com>
parents: 283
diff changeset
100 if dim(e.bId) == 1
285
e21dcda55163 Add type representing an unknown dimension in the domain of tensormappings
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 284
diff changeset
101 return (UnknownDim, domain_size[1])
284
0b8e041a1873 Change how range_size and domain_size work with BoundaryValues and NormalDerivative
Jonatan Werpers <jonatan@werpers.com>
parents: 283
diff changeset
102 elseif dim(e.bId) == 2
285
e21dcda55163 Add type representing an unknown dimension in the domain of tensormappings
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 284
diff changeset
103 return (domain_size[1], UnknownDim)
284
0b8e041a1873 Change how range_size and domain_size work with BoundaryValues and NormalDerivative
Jonatan Werpers <jonatan@werpers.com>
parents: 283
diff changeset
104 end
0b8e041a1873 Change how range_size and domain_size work with BoundaryValues and NormalDerivative
Jonatan Werpers <jonatan@werpers.com>
parents: 283
diff changeset
105 end
281
1eefaefdd0c7 Add missing type parametrization
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 280
diff changeset
106 LazyTensors.domain_size(e::NormalDerivative, range_size::NTuple{2,Integer}) = (range_size[3-dim(e.bId)],)
247
ed29ee13e92e Restructure laplace.jl
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 244
diff changeset
107
ed29ee13e92e Restructure laplace.jl
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 244
diff changeset
108 # TODO: Not type stable D:<
258
3ea8c60ccef3 Fix a few typos in documentation and add a few TODOs
Jonatan Werpers <jonatan@werpers.com>
parents: 255
diff changeset
109 # TODO: Make this independent of dimension
281
1eefaefdd0c7 Add missing type parametrization
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 280
diff changeset
110 function LazyTensors.apply(d::NormalDerivative{T}, v::AbstractArray{T}, I::NTuple{2,Index}) where T
248
05e7bbe0af97 Merge refactoring of laplace
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 247 245
diff changeset
111 i = I[dim(d.bId)]
05e7bbe0af97 Merge refactoring of laplace
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 247 245
diff changeset
112 j = I[3-dim(d.bId)]
05e7bbe0af97 Merge refactoring of laplace
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 247 245
diff changeset
113 N_i = size(d.grid)[dim(d.bId)]
268
f67ce2eb6019 Remove property spacing in EquidistantGrid, due to redundancy.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 266
diff changeset
114 h_inv = inverse_spacing(d.grid)[dim(d.bId)]
280
fe9e8737ddfa Change to using region indices in apply of BoundaryValue, NormalDerivative and BoundaryQuadrature
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 273
diff changeset
115 return apply_normal_derivative(d.op, h_inv, v[j], i, N_i, region(d.bId))
228
5acef2d5db2e Move Laplace operator and related structs/functions to separate file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
116 end
5acef2d5db2e Move Laplace operator and related structs/functions to separate file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
117
281
1eefaefdd0c7 Add missing type parametrization
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 280
diff changeset
118 function LazyTensors.apply_transpose(d::NormalDerivative{T}, v::AbstractArray{T}, I::NTuple{1,Index}) where T
280
fe9e8737ddfa Change to using region indices in apply of BoundaryValue, NormalDerivative and BoundaryQuadrature
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 273
diff changeset
119 u = selectdim(v,3-dim(d.bId),Int(I[1]))
269
ccef055233a2 Move general methods for D2 to ConstantStencilOperator and increase verbosity of method names for clarity
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 268
diff changeset
120 return apply_normal_derivative_transpose(d.op, inverse_spacing(d.grid)[dim(d.bId)], u, region(d.bId))
228
5acef2d5db2e Move Laplace operator and related structs/functions to separate file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
121 end
5acef2d5db2e Move Laplace operator and related structs/functions to separate file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
122
259
5571d2c5bf0f Implement BaoundaryQuadrature for Laplace
Jonatan Werpers <jonatan@werpers.com>
parents: 258
diff changeset
123 """
5571d2c5bf0f Implement BaoundaryQuadrature for Laplace
Jonatan Werpers <jonatan@werpers.com>
parents: 258
diff changeset
124 BoundaryQuadrature{T,N,M,K} <: TensorOperator{T,1}
5571d2c5bf0f Implement BaoundaryQuadrature for Laplace
Jonatan Werpers <jonatan@werpers.com>
parents: 258
diff changeset
125
5571d2c5bf0f Implement BaoundaryQuadrature for Laplace
Jonatan Werpers <jonatan@werpers.com>
parents: 258
diff changeset
126 Implements the boundary operator `q` as a TensorOperator
5571d2c5bf0f Implement BaoundaryQuadrature for Laplace
Jonatan Werpers <jonatan@werpers.com>
parents: 258
diff changeset
127 """
5571d2c5bf0f Implement BaoundaryQuadrature for Laplace
Jonatan Werpers <jonatan@werpers.com>
parents: 258
diff changeset
128 struct BoundaryQuadrature{T,N,M,K} <: TensorOperator{T,1}
5571d2c5bf0f Implement BaoundaryQuadrature for Laplace
Jonatan Werpers <jonatan@werpers.com>
parents: 258
diff changeset
129 op::D2{T,N,M,K}
5571d2c5bf0f Implement BaoundaryQuadrature for Laplace
Jonatan Werpers <jonatan@werpers.com>
parents: 258
diff changeset
130 grid::EquidistantGrid{2}
5571d2c5bf0f Implement BaoundaryQuadrature for Laplace
Jonatan Werpers <jonatan@werpers.com>
parents: 258
diff changeset
131 bId::CartesianBoundary
5571d2c5bf0f Implement BaoundaryQuadrature for Laplace
Jonatan Werpers <jonatan@werpers.com>
parents: 258
diff changeset
132 end
5571d2c5bf0f Implement BaoundaryQuadrature for Laplace
Jonatan Werpers <jonatan@werpers.com>
parents: 258
diff changeset
133 export BoundaryQuadrature
5571d2c5bf0f Implement BaoundaryQuadrature for Laplace
Jonatan Werpers <jonatan@werpers.com>
parents: 258
diff changeset
134
5571d2c5bf0f Implement BaoundaryQuadrature for Laplace
Jonatan Werpers <jonatan@werpers.com>
parents: 258
diff changeset
135 # TODO: Make this independent of dimension
281
1eefaefdd0c7 Add missing type parametrization
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 280
diff changeset
136 function LazyTensors.apply(q::BoundaryQuadrature{T}, v::AbstractArray{T,1}, I::NTuple{1,Index}) where T
268
f67ce2eb6019 Remove property spacing in EquidistantGrid, due to redundancy.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 266
diff changeset
137 h = spacing(q.grid)[3-dim(q.bId)]
259
5571d2c5bf0f Implement BaoundaryQuadrature for Laplace
Jonatan Werpers <jonatan@werpers.com>
parents: 258
diff changeset
138 N = size(v)
5571d2c5bf0f Implement BaoundaryQuadrature for Laplace
Jonatan Werpers <jonatan@werpers.com>
parents: 258
diff changeset
139 return apply_quadrature(q.op, h, v[I[1]], I[1], N[1])
5571d2c5bf0f Implement BaoundaryQuadrature for Laplace
Jonatan Werpers <jonatan@werpers.com>
parents: 258
diff changeset
140 end
5571d2c5bf0f Implement BaoundaryQuadrature for Laplace
Jonatan Werpers <jonatan@werpers.com>
parents: 258
diff changeset
141
281
1eefaefdd0c7 Add missing type parametrization
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 280
diff changeset
142 LazyTensors.apply_transpose(q::BoundaryQuadrature{T}, v::AbstractArray{T,1}, I::NTuple{1,Index}) where T = LazyTensors.apply(q,v,I)
259
5571d2c5bf0f Implement BaoundaryQuadrature for Laplace
Jonatan Werpers <jonatan@werpers.com>
parents: 258
diff changeset
143
5571d2c5bf0f Implement BaoundaryQuadrature for Laplace
Jonatan Werpers <jonatan@werpers.com>
parents: 258
diff changeset
144
228
5acef2d5db2e Move Laplace operator and related structs/functions to separate file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
145
5acef2d5db2e Move Laplace operator and related structs/functions to separate file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
146
5acef2d5db2e Move Laplace operator and related structs/functions to separate file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
147 struct Neumann{Bid<:BoundaryIdentifier} <: BoundaryCondition end
5acef2d5db2e Move Laplace operator and related structs/functions to separate file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
148
5acef2d5db2e Move Laplace operator and related structs/functions to separate file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
149 function sat(L::Laplace{2,T}, bc::Neumann{Bid}, v::AbstractArray{T,2}, g::AbstractVector{T}, I::CartesianIndex{2}) where {T,Bid}
266
9ad447176ba1 Minor work on implementation of SATs for laplace
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 262
diff changeset
150 e = boundary_value(L, Bid())
9ad447176ba1 Minor work on implementation of SATs for laplace
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 262
diff changeset
151 d = normal_derivative(L, Bid())
9ad447176ba1 Minor work on implementation of SATs for laplace
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 262
diff changeset
152 Hᵧ = boundary_quadrature(L, Bid())
9ad447176ba1 Minor work on implementation of SATs for laplace
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 262
diff changeset
153 H⁻¹ = inverse_quadrature(L)
9ad447176ba1 Minor work on implementation of SATs for laplace
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 262
diff changeset
154 return (-H⁻¹*e*Hᵧ*(d'*v - g))[I]
228
5acef2d5db2e Move Laplace operator and related structs/functions to separate file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
155 end
5acef2d5db2e Move Laplace operator and related structs/functions to separate file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
156
5acef2d5db2e Move Laplace operator and related structs/functions to separate file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
157 struct Dirichlet{Bid<:BoundaryIdentifier} <: BoundaryCondition
5acef2d5db2e Move Laplace operator and related structs/functions to separate file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
158 tau::Float64
5acef2d5db2e Move Laplace operator and related structs/functions to separate file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
159 end
5acef2d5db2e Move Laplace operator and related structs/functions to separate file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
160
5acef2d5db2e Move Laplace operator and related structs/functions to separate file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
161 function sat(L::Laplace{2,T}, bc::Dirichlet{Bid}, v::AbstractArray{T,2}, g::AbstractVector{T}, i::CartesianIndex{2}) where {T,Bid}
266
9ad447176ba1 Minor work on implementation of SATs for laplace
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 262
diff changeset
162 e = boundary_value(L, Bid())
9ad447176ba1 Minor work on implementation of SATs for laplace
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 262
diff changeset
163 d = normal_derivative(L, Bid())
9ad447176ba1 Minor work on implementation of SATs for laplace
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 262
diff changeset
164 Hᵧ = boundary_quadrature(L, Bid())
9ad447176ba1 Minor work on implementation of SATs for laplace
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 262
diff changeset
165 H⁻¹ = inverse_quadrature(L)
9ad447176ba1 Minor work on implementation of SATs for laplace
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 262
diff changeset
166 return (-H⁻¹*(tau/h*e + d)*Hᵧ*(e'*v - g))[I]
228
5acef2d5db2e Move Laplace operator and related structs/functions to separate file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
167 # Need to handle scalar multiplication and addition of TensorMapping
5acef2d5db2e Move Laplace operator and related structs/functions to separate file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
168 end
5acef2d5db2e Move Laplace operator and related structs/functions to separate file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
169
5acef2d5db2e Move Laplace operator and related structs/functions to separate file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
170 # function apply(s::MyWaveEq{D}, v::AbstractArray{T,D}, i::CartesianIndex{D}) where D
248
05e7bbe0af97 Merge refactoring of laplace
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 247 245
diff changeset
171 # return apply(s.L, v, i) +
228
5acef2d5db2e Move Laplace operator and related structs/functions to separate file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
172 # sat(s.L, Dirichlet{CartesianBoundary{1,Lower}}(s.tau), v, s.g_w, i) +
5acef2d5db2e Move Laplace operator and related structs/functions to separate file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
173 # sat(s.L, Dirichlet{CartesianBoundary{1,Upper}}(s.tau), v, s.g_e, i) +
5acef2d5db2e Move Laplace operator and related structs/functions to separate file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
174 # sat(s.L, Dirichlet{CartesianBoundary{2,Lower}}(s.tau), v, s.g_s, i) +
5acef2d5db2e Move Laplace operator and related structs/functions to separate file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
175 # sat(s.L, Dirichlet{CartesianBoundary{2,Upper}}(s.tau), v, s.g_n, i)
5acef2d5db2e Move Laplace operator and related structs/functions to separate file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
176 # end