Skip to content
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
3 changes: 3 additions & 0 deletions src/ComputationalModels/ComputationalModels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,8 @@ export reset!
export interpolate_L2_tensor
export interpolate_L2_vector
export interpolate_L2_scalar
export interpolate_L2_field
export L2_projection
export L2_Projection

end
29 changes: 28 additions & 1 deletion src/ComputationalModels/PostProcessors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,36 @@ function interpolate_L2_scalar(x, Ω, dΩ, Γ=Ω)
end


function L2_Projection(u, dΩ, V)
function get_cell_field_type(f::CellField, dΩ::Measure)
pts = get_cell_points(dΩ)
f_x = f(pts)
T = eltype(Gridap.Arrays.testitem(f_x))
return T
end


"""
Interpolate an L2 field into an H1 field.
The type of the field is inferred from the cell field `x` and the measure `dΩ`.
"""
function interpolate_L2_field(x, Ω, dΩ, T::Type=get_cell_field_type(x, dΩ))
refL2 = ReferenceFE(lagrangian, T, 0)
reffe = ReferenceFE(lagrangian, T, 1)
VL2 = FESpace(Ω, refL2, conformity=:L2)
VH1 = FESpace(Ω, reffe, conformity=:H1)
interpolate_everywhere(L2_projection(x, dΩ, VL2), VH1)
end


"""
Perform an L2 projection of a function `u` onto a finite element
space `V` defined over the domain `Ω` with measure `dΩ`.
"""
function L2_projection(u, dΩ, V)
a(w, v) = ∫(w ⊙ v) * dΩ
l(v) = ∫(v ⊙ u) * dΩ
op = AffineFEOperator(a, l, V, V)
solve(op)
end

L2_Projection = L2_projection
2 changes: 2 additions & 0 deletions src/Exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ end
@publish ComputationalModels InterpolableBC
@publish ComputationalModels InterpolableBC!
@publish ComputationalModels TrialFESpace! # Exporting internal function of Gridap
@publish ComputationalModels interpolate_L2_field
@publish ComputationalModels L2_projection
@publish ComputationalModels L2_Projection

@publish DiscreteModeling CartesianTags
Expand Down
Loading