-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add two MFEM auxkernels for L2-averaged inner and cross product of two source (par)gridfucntions projected onto an MFEM AuxVariable #31613
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
Merged
GiudGiud
merged 35 commits into
idaholab:next
from
Giannis95:Giannis95/MFEMInnerCrossProductAux
Nov 6, 2025
+33,033
−1
Merged
Changes from 32 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
fcc5c55
Initial commit for the inner product aux kernel .C and .h
5953d06
Initiall structure for the Cross Product AuxKernel s(x) * (U x V) pro…
9516ee2
Update framework/include/mfem/auxkernels/MFEMCrossProductAux.h
Giannis95 5ccf432
Add the L2 fe space with map_type = INTEGRAL. refs #31612
d23ae7c
Rebased and conflict resolved L2Int addition. Refs #31613
39387c2
Add documentation and tests for the InnerProduct. Refs #31612
de7338c
Add L2 option for MFEMVectorFESpaces and cross-product auxkernel test…
d046ff2
Fix EOF. Refs #31612
d27bc9c
Remove unicode characters. Refs #31612
b5e1d6d
change test from XMLDiff to csvdiff due to large data files, fixed cl…
79cb0de
Apply suggestions from code review
Giannis95 94d0626
Move the cross product auxkernel checks before construction, add miss…
9c611d5
clang-format. Refs #31612
d6c6f5f
Fix auxkernels test file. Refs #31612
ca2b748
Add a new MFEMVectorL2InnerProductIntegralPostprocessor which allow L…
5439ac6
Typos fix. Refs #31612
757e748
Clean up dot product auxkernel. Refs #31612
2e3fcde
delete whitespaces. Refs #31612
c41ff3a
deactive joule_Q_aux block. Refs #31612
de1f3be
Fix input file type. Refs #13612
fba3115
av_magnetostatic block change. Refs #31612
b74dd79
Update the execution orders in the cross_product examples. Refs #31612
1a948f2
update the inner product test. Refs #31612
c0eb0de
Test moving everything in the constructor for the cross-product test.…
2f8091d
Simplified cross product test with runtime less than a second. Refs #…
947c539
Whitespaces fix. Refs #31612
c9b17f9
Clean up av_magnetostatic. Refs #31612
d71b22d
Test fix. Refs #31612
9e55ffd
Restructure InnerProduct auxkernel. Refs #31612.
252de90
apply patch. Refs #31612
59617c1
Tighten up the solver tolerance for the inner product test. Refs #31612
cb8343d
Rename input vector variable names for clarity to first_source_vec an…
17ab87f
Add softer XLMDiff requiriments to avoid reducing the solvers toleran…
43e62dc
Apply suggestions from code review
Giannis95 c7d5559
Adding missing docstrings, delete postprocessor, fix auxkernels/test …
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
framework/doc/content/source/mfem/auxkernels/MFEMCrossProductAux.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # MFEMCrossProductAux | ||
|
|
||
| !if! function=hasCapability('mfem') | ||
|
|
||
| ## Summary | ||
|
|
||
| !syntax description /AuxKernels/MFEMCrossProductAux | ||
|
|
||
| ## Overview | ||
|
|
||
| AuxKernel for calculating the cross product of two vector fields and projecting onto an L2 vector finite element space mfem auxvariable. | ||
|
|
||
| !equation | ||
| s(x)(u\times v), \,\,\, | ||
|
|
||
| where $u$ and $v$ are the two vector fields and $s(x)$ is an optional scaling. | ||
|
|
||
| ## Example Input File Syntax | ||
|
|
||
| !listing mfem/auxkernels/crossproduct.i block=/AuxKernels | ||
|
|
||
| !syntax parameters /AuxKernels/MFEMCrossProductAux | ||
|
|
||
| !syntax inputs /AuxKernels/MFEMCrossProductAux | ||
|
|
||
| !syntax children /AuxKernels/MFEMCrossProductAux | ||
|
|
||
| !if-end! | ||
|
|
||
| !else | ||
| !include mfem/mfem_warning.md |
31 changes: 31 additions & 0 deletions
31
framework/doc/content/source/mfem/auxkernels/MFEMDotProductAux.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # MFEMDotProductAux | ||
|
|
||
| !if! function=hasCapability('mfem') | ||
|
|
||
| ## Summary | ||
|
|
||
| !syntax description /AuxKernels/MFEMDotProductAux | ||
|
|
||
| ## Overview | ||
|
|
||
| AuxKernel for calculating the inner product of two vector fields and projecting onto an L2 finite element space mfem auxvariable. | ||
|
|
||
| !equation | ||
| s u\cdot v, \,\,\, | ||
|
|
||
| where $u$ and $v$ are the two fields and $s(x)$ is an optional scaling. | ||
|
|
||
| ## Example Input File Syntax | ||
|
|
||
| !listing mfem/kernels/curlcurl.i block=/AuxKernels | ||
|
|
||
| !syntax parameters /AuxKernels/MFEMDotProductAux | ||
|
|
||
| !syntax inputs /AuxKernels/MFEMDotProductAux | ||
|
|
||
| !syntax children /AuxKernels/MFEMDotProductAux | ||
|
|
||
| !if-end! | ||
|
|
||
| !else | ||
| !include mfem/mfem_warning.md |
33 changes: 33 additions & 0 deletions
33
...ent/source/mfem/postprocessors/MFEMVectorL2InnerProductIntegralPostprocessor.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| # MFEMVectorL2InnerProductIntegralPostprocessor | ||
|
|
||
| !if! function=hasCapability('mfem') | ||
|
|
||
| ## Summary | ||
|
|
||
| !syntax description /Postprocessors/MFEMVectorL2InnerProductIntegralPostprocessor | ||
|
|
||
| ## Overview | ||
|
|
||
| Postprocessor for calculating the integral of the dot product between two L2 vector variables over a | ||
| user-specified subdomain of the mesh: | ||
|
|
||
| !equation | ||
| (k \vec u, \vec v)_\Omega | ||
|
|
||
| where $\vec u$, $\vec v \in \mathrm{L2}$, $k$ is an optional scalar coefficient, | ||
| and $\Omega$ is the user-specified mesh subdomain. | ||
|
|
||
| ## Example Input File Syntax | ||
|
|
||
| !listing mfem/submeshes/av_magnetostatic.i block=Postprocessors | ||
|
|
||
| !syntax parameters /Postprocessors/MFEMVectorL2InnerProductIntegralPostprocessor | ||
|
|
||
| !syntax inputs /Postprocessors/MFEMVectorL2InnerProductIntegralPostprocessor | ||
|
|
||
| !syntax children /Postprocessors/MFEMVectorL2InnerProductIntegralPostprocessor | ||
|
|
||
| !if-end! | ||
|
|
||
| !else | ||
| !include mfem/mfem_warning.md |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| //* This file is part of the MOOSE framework | ||
| //* https://mooseframework.inl.gov | ||
| //* | ||
| //* All rights reserved, see COPYRIGHT for full restrictions | ||
| //* https://github.com/idaholab/moose/blob/master/COPYRIGHT | ||
| //* | ||
| //* Licensed under LGPL 2.1, please see LICENSE for details | ||
| //* https://www.gnu.org/licenses/lgpl-2.1.html | ||
|
|
||
| #ifdef MOOSE_MFEM_ENABLED | ||
| #pragma once | ||
|
|
||
| #include "MFEMAuxKernel.h" | ||
| #include "mfem.hpp" | ||
|
|
||
| /** | ||
| * Project s(x) * (U x V) onto a vector MFEM auxvariable. | ||
| * | ||
| * Parameters: | ||
| * - variable (AuxVariableName, required): AuxVariable name (inherited) | ||
| * - first_source_vec (VariableName, required): vector MFEM variable U (vdim = 3) | ||
| * - second_source_vec (VariableName, required): vector MFEM variable V (vdim = 3) | ||
| * - scale_factor (mfem::real_t, default=1.0): constant multiplier s(x)=scale_factor | ||
Giannis95 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * | ||
| * Notes: | ||
| * - Default L2_FECollection with map_type = VALUE and optional map_type = INTEGRAL . | ||
| * - Currently supports only interior DOFs (no shared/constrained DOFs). | ||
| * - Enforces 3D: mesh dimension and all involved vdim must be 3. | ||
| */ | ||
| class MFEMCrossProductAux : public MFEMAuxKernel | ||
| { | ||
| public: | ||
| static InputParameters validParams(); | ||
|
|
||
| MFEMCrossProductAux(const InputParameters & parameters); | ||
| ~MFEMCrossProductAux() override = default; | ||
|
|
||
| void execute() override; | ||
|
|
||
| protected: | ||
| // Names of vector sources | ||
Giannis95 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const VariableName _u_var_name; | ||
| const VariableName _v_var_name; | ||
|
|
||
| // References to the vector ParGridFunctions | ||
Giannis95 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const mfem::ParGridFunction & _u_var; | ||
| const mfem::ParGridFunction & _v_var; | ||
| const mfem::real_t _scale_factor; | ||
Giannis95 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| mfem::VectorGridFunctionCoefficient _u_coef; | ||
GiudGiud marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| mfem::VectorGridFunctionCoefficient _v_coef; | ||
| mfem::VectorCrossProductCoefficient _cross_uv; | ||
| mfem::ConstantCoefficient _scale_c; | ||
| mfem::ScalarVectorProductCoefficient _final_coef; // coef suffix !! | ||
|
|
||
| // Constant multiplier | ||
| // const mfem::real_t _scale_factor; | ||
Giannis95 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }; | ||
|
|
||
| #endif // MOOSE_MFEM_ENABLED | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| //* This file is part of the MOOSE framework | ||
| //* https://mooseframework.inl.gov | ||
| //* | ||
| //* All rights reserved, see COPYRIGHT for full restrictions | ||
| //* https://github.com/idaholab/moose/blob/master/COPYRIGHT | ||
| //* | ||
| //* Licensed under LGPL 2.1, please see LICENSE for details | ||
| //* https://www.gnu.org/licenses/lgpl-2.1.html | ||
|
|
||
| #ifdef MOOSE_MFEM_ENABLED | ||
| #pragma once | ||
|
|
||
| #include "MFEMAuxKernel.h" | ||
| #include "mfem.hpp" | ||
|
|
||
| /** | ||
| * Project s(x) * (U . V) onto a scalar MFEM auxvariable. | ||
| * | ||
| * Parameters: | ||
| * - first_source_vec (VariableName): vector MFEM variable U | ||
| * - second_source_vec (VariableName): vector MFEM variable V | ||
| * - scale_factor (mfem::real_t, default=1.0): constant multiplier | ||
| * - scale_variable (VariableName, optional): scalar MFEM variable s(x) | ||
| */ | ||
| class MFEMDotProductAux : public MFEMAuxKernel | ||
| { | ||
| public: | ||
| static InputParameters validParams(); | ||
|
|
||
| MFEMDotProductAux(const InputParameters & parameters); | ||
| ~MFEMDotProductAux() override = default; | ||
|
|
||
| void execute() override; | ||
|
|
||
| protected: | ||
| // Names of vector sources | ||
GiudGiud marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const VariableName _u_var_name; | ||
| const VariableName _v_var_name; | ||
|
|
||
| // References to the vector ParGridFunctions | ||
| const mfem::ParGridFunction & _u_var; | ||
| const mfem::ParGridFunction & _v_var; | ||
| const mfem::real_t _scale_factor; | ||
|
|
||
| mfem::VectorGridFunctionCoefficient _u_coef; | ||
| mfem::VectorGridFunctionCoefficient _v_coef; | ||
| mfem::InnerProductCoefficient _dot_uv; | ||
| mfem::ConstantCoefficient _scale_c; | ||
|
|
||
| mfem::ProductCoefficient _final_coef; | ||
| }; | ||
|
|
||
| #endif // MOOSE_MFEM_ENABLED | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
framework/include/mfem/postprocessors/MFEMVectorL2InnerProductIntegralPostprocessor.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| //* This file is part of the MOOSE framework | ||
| //* https://mooseframework.inl.gov | ||
| //* | ||
| //* All rights reserved, see COPYRIGHT for full restrictions | ||
| //* https://github.com/idaholab/moose/blob/master/COPYRIGHT | ||
| //* | ||
| //* Licensed under LGPL 2.1, please see LICENSE for details | ||
| //* https://www.gnu.org/licenses/lgpl-2.1.html | ||
|
|
||
| #ifdef MOOSE_MFEM_ENABLED | ||
|
|
||
| #pragma once | ||
| #include "MFEMPostprocessor.h" | ||
| #include "MFEMBlockRestrictable.h" | ||
|
|
||
| /** | ||
| * Compute the integral of the innter product between two MFEM vector FE variables, scaled by an | ||
Giannis95 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * optional scalar coefficient. | ||
| */ | ||
| class MFEMVectorL2InnerProductIntegralPostprocessor : public MFEMPostprocessor, | ||
| public MFEMBlockRestrictable | ||
| { | ||
| public: | ||
| static InputParameters validParams(); | ||
|
|
||
| MFEMVectorL2InnerProductIntegralPostprocessor(const InputParameters & parameters); | ||
|
|
||
| /** | ||
| * Evaluate integral. | ||
| */ | ||
| virtual void execute() override; | ||
|
|
||
| /** | ||
| * Return the last evaluated integral value. | ||
| */ | ||
| virtual PostprocessorValue getValue() const override final; | ||
|
|
||
| private: | ||
| mfem::real_t _integral; | ||
| mfem::ParGridFunction & _primal_var; | ||
| mfem::ParGridFunction & _dual_var; | ||
GiudGiud marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| mfem::Coefficient & _scalar_coef; | ||
| mfem::VectorGridFunctionCoefficient _dual_var_coef; | ||
| mfem::ScalarVectorProductCoefficient _scaled_dual_var_coef; | ||
| mfem::ParLinearForm _subdomain_integrator; | ||
Giannis95 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }; | ||
|
|
||
| #endif | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| //* This file is part of the MOOSE framework | ||
| //* https://mooseframework.inl.gov | ||
| //* | ||
| //* All rights reserved, see COPYRIGHT for full restrictions | ||
| //* https://github.com/idaholab/moose/blob/master/COPYRIGHT | ||
| //* | ||
| //* Licensed under LGPL 2.1, please see LICENSE for details | ||
| //* https://www.gnu.org/licenses/lgpl-2.1.html | ||
|
|
||
| #ifdef MOOSE_MFEM_ENABLED | ||
Giannis95 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| #include "MFEMCrossProductAux.h" | ||
| #include "MFEMProblem.h" | ||
| #include "mfem.hpp" | ||
|
|
||
| registerMooseObject("MooseApp", MFEMCrossProductAux); | ||
|
|
||
| InputParameters | ||
| MFEMCrossProductAux::validParams() | ||
| { | ||
| InputParameters params = MFEMAuxKernel::validParams(); | ||
| params.addClassDescription("Projects s(x) * (U x V) onto a vector MFEM auxvariable"); | ||
| params.addRequiredParam<VariableName>("first_source_vec", "Vector MFEMVariable U (vdim=3)"); | ||
| params.addRequiredParam<VariableName>("second_source_vec", "Vector MFEMVariable V (vdim=3)"); | ||
| params.addParam<mfem::real_t>( | ||
| "scale_factor", 1.0, "Constant multiplier applied to the cross product"); | ||
| return params; | ||
| } | ||
|
|
||
| MFEMCrossProductAux::MFEMCrossProductAux(const InputParameters & parameters) | ||
| : MFEMAuxKernel(parameters), | ||
| _u_var_name(getParam<VariableName>("first_source_vec")), | ||
| _v_var_name(getParam<VariableName>("second_source_vec")), | ||
| _u_var(*getMFEMProblem().getProblemData().gridfunctions.Get(_u_var_name)), | ||
| _v_var(*getMFEMProblem().getProblemData().gridfunctions.Get(_v_var_name)), | ||
| _scale_factor(getParam<mfem::real_t>("scale_factor")), | ||
| _u_coef(&_u_var), | ||
| _v_coef(&_v_var), | ||
| _cross_uv(_u_coef, _v_coef), | ||
| _scale_c(_scale_factor), | ||
| _final_coef(_scale_c, _cross_uv) | ||
| { | ||
| // // Must be vector L2 with interior DOFs | ||
Giannis95 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| mfem::ParFiniteElementSpace * fes = _result_var.ParFESpace(); | ||
| const int mesh_dim = fes->GetMesh()->Dimension(); | ||
|
|
||
| // Enforce 3D cross product | ||
| if (mesh_dim != 3) | ||
GiudGiud marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| mooseError("MFEMCrossProductAux requires a 3D mesh (Dimension == 3)."); | ||
|
|
||
| if (fes->GetVDim() != 3) | ||
| mooseError("MFEMCrossProductAux requires AuxVariable to have vdim == 3."); | ||
|
|
||
| // // Must be L2 | ||
Giannis95 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (!dynamic_cast<const mfem::L2_FECollection *>(fes->FEColl())) | ||
| mooseError("MFEMCrossProductAux requires the target variable to use L2_FECollection."); | ||
|
|
||
| // // Must have no shared/constrained DOFs (pure interior DOFs) | ||
| if (fes->GetTrueVSize() != fes->GetVSize()) | ||
| mooseError("MFEMCrossProductAux currently supports only L2 spaces with interior DOFs " | ||
| "(no shared/constrained DOFs)."); | ||
GiudGiud marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| void | ||
| MFEMCrossProductAux::execute() | ||
| { | ||
| // // Build vector coefficient: s(x) * (U x V) | ||
| // mfem::VectorGridFunctionCoefficient Ucoef(&_u_var); | ||
| // mfem::VectorGridFunctionCoefficient Vcoef(&_v_var); | ||
| // mfem::VectorCrossProductCoefficient cross_uv(Ucoef, Vcoef); // vector-valued | ||
|
|
||
| // // s(x) = constant scale factor for now | ||
| // mfem::ConstantCoefficient scoef(_scale_factor); | ||
| // mfem::ScalarVectorProductCoefficient final_vec(scoef, cross_uv); // vector-valued | ||
Giannis95 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // MFEM element projection for L2 | ||
| _result_var = 0.0; | ||
| _result_var.ProjectCoefficient(_final_coef); | ||
| } | ||
|
|
||
| #endif // MOOSE_MFEM_ENABLED | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.