Average a CellField
over a dimension
#1032
-
Hello, Is there an efficient way to average a I suppose one way to do this is by using Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
There is no easy way of doing this. I think slicing up domains is something we could expand on. However, and as always, it is involved but not impossible. The basic structure should go like this: using Gridap
using Gridap.Geometry
model = CartesianDiscreteModel((0,1,0,1,0,1),(4,4,4))
order = 1
reffe = ReferenceFE(lagrangian,Float64,order)
V = TestFESpace(model,reffe);
function create_face_mask(model::DiscreteModel{Dc,Dp},mask) where {Dc,Dp}
topo = get_grid_topology(model)
node_coords = Geometry.get_vertex_coordinates(topo)
face_to_node = Geometry.get_faces(topo,Dc-1,0)
face_coords = lazy_map(Broadcasting(Reindex(node_coords)),face_to_node)
bgface_to_mask = map(mask,face_coords)
return bgface_to_mask
end
function my_mean(z,f)
mask(p::Point{3}) = abs(p[3]-z) < 10*eps(z)
mask(nodes::AbstractVector) = all(mask,nodes)
bgface_to_mask = create_face_mask(model,mask)
Γ = BoundaryTriangulation(model,bgface_to_mask)
dΓ = Measure(Γ,order)
return sum(∫(f)dΓ)/sum(∫(1)dΓ)
end
uh = interpolate(x -> x[3],V)
my_mean(0.0,uh) # 0.0
my_mean(1.0,uh) # 1.0
|
Beta Was this translation helpful? Give feedback.
There is no easy way of doing this. I think slicing up domains is something we could expand on. However, and as always, it is involved but not impossible.
The basic structure should go like this: