Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement inverse map #552

Merged
merged 3 commits into from
Mar 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/CellData/CellFields.jl
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ function change_domain(a::CellField,::ReferenceDomain,::PhysicalDomain)
trian = get_triangulation(a)
cell_map = get_cell_map(trian)
cell_invmap = lazy_map(inverse_map,cell_map)
cell_field_ref = get_data(cell_field)
cell_field_ref = get_data(a)
cell_field_phys = lazy_map(Broadcasting(∘),cell_field_ref,cell_invmap)
GenericCellField(cell_field_phys,trian,PhysicalDomain())
end
Expand Down
8 changes: 8 additions & 0 deletions src/Fields/AffineMaps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,11 @@ function lazy_map(
cell_∇∇bt = lazy_map(transpose,cell_∇∇b)
cell_∇∇bt
end

function inverse_map(f::AffineMap)
Jt = f.gradient
y0 = f.origin
invJt = inv(Jt)
x0 = -y0⋅invJt
AffineMap(invJt,x0)
end
8 changes: 8 additions & 0 deletions test/CellDataTests/CellFieldsTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ trian_D =BoundaryTriangulation(model,tags="tag_8")
trian_S =SkeletonTriangulation(model)
trian_0 =Triangulation(trian_D,Int[])

ϕ = GenericCellField(get_cell_map(trian),trian,ReferenceDomain())
ϕinv = GenericCellField(lazy_map(inverse_map,get_cell_map(trian)),trian,PhysicalDomain())
xref = get_cell_points(trian)
xphy = CellPoint(get_array(xref),trian,PhysicalDomain())
test_array(ϕ(xref),collect1d(ϕ(xphy)),(i,j)->all(map(≈,i,j)))
test_array(ϕinv(xref),collect1d(ϕinv(xphy)),(i,j)->all(map(≈,i,j)))

x = get_cell_points(trian)
@test DomainStyle(x) == ReferenceDomain()
@test get_array(x) == get_cell_coordinates(trian)
Expand Down Expand Up @@ -147,6 +154,7 @@ test_array(hx_N,collect(hx_N))




#np = 3
#ndofs = 4
#
Expand Down
3 changes: 3 additions & 0 deletions test/FieldsTests/AffineMapsTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ h = AffineMap(g,origin)
@test isa(∇(h),ConstantField)
@test isa(Broadcasting(∇)(h),ConstantField)

hinv = inverse_map(h)

x1 = Point(0,0)
x2 = Point(1,1)
x3 = Point(2,1)
Expand All @@ -24,6 +26,7 @@ r = Point{2,Int}[(1, 1), (3, 3), (5, 3)]
∇r = TensorValue{2,2,Int,4}[(2, 0, 0, 2), (2, 0, 0, 2), (2, 0, 0, 2)]
test_field(h,x,r,grad=∇r)
test_field(h,x1,x1⋅g+origin,grad=g)
test_field(hinv,r,x,grad=inv.(∇r))

ncells = 10
cell_to_h = fill(h,ncells)
Expand Down