diff --git a/src/ComputationalModels/ComputationalModels.jl b/src/ComputationalModels/ComputationalModels.jl index b27f582..c2188ee 100644 --- a/src/ComputationalModels/ComputationalModels.jl +++ b/src/ComputationalModels/ComputationalModels.jl @@ -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 diff --git a/src/ComputationalModels/PostProcessors.jl b/src/ComputationalModels/PostProcessors.jl index 986b606..5a9b5e5 100644 --- a/src/ComputationalModels/PostProcessors.jl +++ b/src/ComputationalModels/PostProcessors.jl @@ -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 diff --git a/src/Exports.jl b/src/Exports.jl index ad033c4..0417462 100644 --- a/src/Exports.jl +++ b/src/Exports.jl @@ -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