diff --git a/src/CellData/CellFields.jl b/src/CellData/CellFields.jl index 394aeee7b..c33805ce0 100644 --- a/src/CellData/CellFields.jl +++ b/src/CellData/CellFields.jl @@ -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 diff --git a/src/Fields/AffineMaps.jl b/src/Fields/AffineMaps.jl index b1233d74d..6f156be19 100644 --- a/src/Fields/AffineMaps.jl +++ b/src/Fields/AffineMaps.jl @@ -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 diff --git a/test/CellDataTests/CellFieldsTests.jl b/test/CellDataTests/CellFieldsTests.jl index f5a35ec1d..d843092e9 100644 --- a/test/CellDataTests/CellFieldsTests.jl +++ b/test/CellDataTests/CellFieldsTests.jl @@ -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) @@ -147,6 +154,7 @@ test_array(hx_N,collect(hx_N)) + #np = 3 #ndofs = 4 # diff --git a/test/FieldsTests/AffineMapsTests.jl b/test/FieldsTests/AffineMapsTests.jl index c9d3160a5..bd205296a 100644 --- a/test/FieldsTests/AffineMapsTests.jl +++ b/test/FieldsTests/AffineMapsTests.jl @@ -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) @@ -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)