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

Introduce Flux Error Estimation #85

Merged
merged 11 commits into from
Oct 11, 2023
Merged

Conversation

hughcars
Copy link
Collaborator

Introduce flux error estimation based on a global ZZ solve.

  • Introduces the FluxProjector class, which is used for computing a "coarse flux" in
    a vector L2 space, then performing a global mass matrix inversion to compute a
    "smooth" flux that better represents the underlying physical quantity. This is achieved
    through a multigrid hierarchy.
  • Introduces the CurlFluxErrorEstimator and GradFluxErrorEstimator classes, which utilize the
    FluxProjector class to compute elemental error estimates comparing the coarse numerical flux
    from the solution against a smoothed flux from a global mass matrix inversion.
  • Introduces the CurlFluxErrorEstimator class which utilizes a flux projector to compute a
    smooth flux in an ND space. Provides methods for real valued vectors, and complex vectors.
    The flux is assumed to take the form μ⁻¹∇ × V, where V is either A or E depending on the solver mode.
  • Introduces the GradFluxErrorEstimator class which utilizes a flux projector to compute a
    smooth flux in an H1^d space. The flux is assumed to be of the form ϵ ∇ ϕ
  • Introduce the CurlFluxCoefficient and GradFluxCoefficient classes which compute the numerical Curl
    and Grad fluxes given a solution.

Issue #, if available:
#2

@hughcars hughcars force-pushed the hughcars/amr-nonconformal-mesh-partition-dev branch 3 times, most recently from 5e11633 to 53b3185 Compare August 21, 2023 20:57
@hughcars hughcars force-pushed the hughcars/flux-error-estimation-dev branch from 9bd4ef9 to 47bea57 Compare August 22, 2023 21:47
@hughcars hughcars force-pushed the hughcars/amr-nonconformal-mesh-partition-dev branch from 53b3185 to 3ea2806 Compare August 23, 2023 13:44
@hughcars hughcars force-pushed the hughcars/flux-error-estimation-dev branch from 47bea57 to 695259b Compare August 23, 2023 13:44
@hughcars hughcars force-pushed the hughcars/amr-nonconformal-mesh-partition-dev branch from 3ea2806 to e3d0d39 Compare August 23, 2023 19:50
@hughcars hughcars force-pushed the hughcars/flux-error-estimation-dev branch 2 times, most recently from 2f8772b to fafcd1e Compare August 23, 2023 21:44
@hughcars hughcars force-pushed the hughcars/amr-nonconformal-mesh-partition-dev branch from e3d0d39 to 16c91e4 Compare August 24, 2023 16:53
@hughcars hughcars force-pushed the hughcars/flux-error-estimation-dev branch from fafcd1e to fcfa7e2 Compare August 24, 2023 16:53
@hughcars hughcars force-pushed the hughcars/amr-nonconformal-mesh-partition-dev branch from 16c91e4 to 9e8b615 Compare August 30, 2023 16:11
@hughcars hughcars force-pushed the hughcars/flux-error-estimation-dev branch 2 times, most recently from 5cd41c2 to cb2f758 Compare August 30, 2023 16:52
@hughcars hughcars changed the base branch from hughcars/amr-nonconformal-mesh-partition-dev to main August 30, 2023 17:19
@hughcars hughcars force-pushed the hughcars/flux-error-estimation-dev branch from cb2f758 to 165e150 Compare August 30, 2023 17:24
- Some of these are necessary in the AMR branch
- Some of these are minor cleanup/rationalization
- Some are aesthetics
@hughcars hughcars force-pushed the hughcars/flux-error-estimation-dev branch from 165e150 to 22022a3 Compare October 3, 2023 14:41
- Introduces the FluxProjector class, which is used for computing a "coarse flux" in
a vector L2 space, then performing a global mass matrix inversion to compute a
"smooth" flux that better represents the underlying physical quantity. This is achieved
through a multigrid hierarchy.
- Introduces the CurlFluxErrorEstimator and GradFluxErrorEstimator classes, which utilize the
FluxProjector class to compute elemental error estimates comparing the coarse numerical flux
from the solution against a smoothed flux from a global mass matrix inversion.
- Introduces the CurlFluxErrorEstimator class which utilizes a flux projector to compute a
smooth flux in an ND space. Provides methods for real valued vectors, and complex vectors.
The flux is assumed to take the form μ⁻¹∇ × V, where V is either A or E depending on the solver mode.
- Introduces the GradFluxErrorEstimator class which utilizes a flux projector to compute a
smooth flux in an H1^d space. The flux is assumed to be of the form ϵ ∇ ϕ
- Introduce the CurlFluxCoefficient and GradFluxCoefficient classes which compute the numerical Curl
and Grad fluxes given a solution.
@hughcars hughcars force-pushed the hughcars/flux-error-estimation-dev branch from 22022a3 to 97372d7 Compare October 3, 2023 15:41
@hughcars hughcars added the enhancement New feature or request label Oct 3, 2023
@hughcars hughcars marked this pull request as ready for review October 3, 2023 19:46
@hughcars hughcars changed the title [Draft] Introduce Flux Error Estimation Introduce Flux Error Estimation Oct 3, 2023
Copy link
Contributor

@sebastiangrimberg sebastiangrimberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good @hughcars, I went ahead and made an initial pass as the tests are passing now.

Several style and organizational comments, but one large issue which came up towards the end in the linalg/errorestimator.cpp classes. I see you are allocating a FiniteElementSpace (L2) for the discontinuous flux, and constructing these scalar_mass_matrices and smooth_to_coarse_embed objects to perform the estimation. For reasons noted above, this is something to avoid and I think the loops over elements once the smooth flux GridFunction is computed needs to be reworked. This can be done fully matrix-free, as mfem::GridFunction::ComputeElementLpErrors. There may be good reason you have decided to go your current route vs. the other implementation, but maybe this was done prematurely. I would imagine it looking something like:

... compute mfem::ParGridFunction smooth_flux, and using CurlFluxCoefficient flux_coef ...

for e in 0, ... , NE-1:
    T = mesh.GetElementTransformation(e);
    ir = mfem::IntRules.Get(T.GetGeometryType(), q_order);
    for ip in ir.GetNPoints():
        T.SetIntPoint(ip);
        U = smooth_flux.GetVectorValue(T, ip);
        V = flux_coef.Eval(T, ip);

        // Integrate over the element: \int_e (U-V)^T (U-V) dV = \sum_i w_i ||U_i - V_i||_2^2
        // (w_i = ip.weight * T->Weight(), see GridFunction::ComputeLpError)

        // For the normalization, use \int_e ||U||_2^2 dV = sum_i w_i ||U_i||^2

    end
end

The loop over integration points can use dense matrix arithmetic using the overrides to GetVectorValue and Eval which return a DenseMatrix where each column is the vector at an integration point. I am fairly certain this approach is an improvement in the long run over what you have there, as you avoid the big memory allocations associated with the dense element matrices.

test/testcase.jl Outdated Show resolved Hide resolved
palace/utils/timer.hpp Outdated Show resolved Hide resolved
palace/fem/integrator.hpp Outdated Show resolved Hide resolved
palace/fem/coefficient.hpp Outdated Show resolved Hide resolved
palace/fem/coefficient.hpp Outdated Show resolved Hide resolved
palace/linalg/errorestimator.cpp Outdated Show resolved Hide resolved
palace/linalg/errorestimator.cpp Outdated Show resolved Hide resolved
palace/linalg/errorestimator.cpp Outdated Show resolved Hide resolved
palace/linalg/errorestimator.cpp Outdated Show resolved Hide resolved
palace/linalg/errorestimator.cpp Outdated Show resolved Hide resolved
palace/drivers/basesolver.hpp Outdated Show resolved Hide resolved
palace/utils/errorindicators.hpp Outdated Show resolved Hide resolved
palace/utils/errorindicators.hpp Outdated Show resolved Hide resolved
palace/utils/errorindicators.hpp Outdated Show resolved Hide resolved
@hughcars hughcars force-pushed the hughcars/flux-error-estimation-dev branch 2 times, most recently from 3f3f79b to cf6a2b0 Compare October 5, 2023 19:44
Copy link
Contributor

@sebastiangrimberg sebastiangrimberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm working my way up from the bottom, so have added some (final) comments on ErrorEstimator and ErrorIndicator. I think there is something to be rethought with the ErrorIndicator class which will clarify the normalization and make this class more useful.

I haven't looked at anything inside of drivers/ since I think this changes should be finalized first before I look at the "user" code.

palace/utils/errorindicators.hpp Outdated Show resolved Hide resolved
palace/utils/errorindicators.hpp Outdated Show resolved Hide resolved
palace/utils/errorindicators.hpp Outdated Show resolved Hide resolved
palace/fem/coefficient.hpp Outdated Show resolved Hide resolved
palace/utils/errorindicators.hpp Outdated Show resolved Hide resolved
palace/linalg/errorestimator.cpp Outdated Show resolved Hide resolved
palace/linalg/errorestimator.cpp Outdated Show resolved Hide resolved
palace/linalg/errorestimator.cpp Outdated Show resolved Hide resolved
palace/linalg/errorestimator.cpp Outdated Show resolved Hide resolved
palace/main.cpp Outdated Show resolved Hide resolved
@hughcars hughcars force-pushed the hughcars/flux-error-estimation-dev branch from eca57eb to f536eec Compare October 6, 2023 20:43
docs/src/config/solver.md Show resolved Hide resolved
test/testcase.jl Outdated Show resolved Hide resolved
palace/drivers/basesolver.cpp Outdated Show resolved Hide resolved
palace/utils/configfile.hpp Outdated Show resolved Hide resolved
palace/utils/configfile.cpp Show resolved Hide resolved
palace/utils/configfile.cpp Show resolved Hide resolved
palace/linalg/vector.hpp Outdated Show resolved Hide resolved
palace/fem/errorindicators.hpp Outdated Show resolved Hide resolved
palace/drivers/eigensolver.hpp Outdated Show resolved Hide resolved
@hughcars hughcars force-pushed the hughcars/flux-error-estimation-dev branch from 68dfe76 to 4d0dc70 Compare October 9, 2023 19:21
@sebastiangrimberg
Copy link
Contributor

I think we should squash these commits before merging #103 in, and then merging to main. What do you think? If that sounds good feel free to go ahead and do so and rebase and merge #103 here.

hughcars and others added 6 commits October 11, 2023 09:52
…erator now that only one field is written per Solve()

Also some corresponding simplification of ErrorIndicator class some remaining style fixes/remove std::transform over mfem::Vector.
…ding legacy LinearForm assembly and simplify, removing need for custom Coefficients and improving ComplexVector organization
@hughcars hughcars force-pushed the hughcars/flux-error-estimation-dev branch from 4d0dc70 to 565d90c Compare October 11, 2023 14:05
@hughcars hughcars merged commit ab5550b into main Oct 11, 2023
17 checks passed
@hughcars hughcars deleted the hughcars/flux-error-estimation-dev branch October 11, 2023 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants