-
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 all 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 |
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,54 @@ | ||
| //* 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. | ||
| * | ||
| * Notes: | ||
| * - 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 | ||
| 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; | ||
| /// Scaling factor applied on the resulting field | ||
| const mfem::real_t _scale_factor; | ||
Giannis95 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /// Coefficient wrappers | ||
| 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; | ||
|
|
||
| ///Final coefficient that applies the scale factor to the crossproduct | ||
| mfem::ScalarVectorProductCoefficient _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
| 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. | ||
| * | ||
| * Notes: | ||
| * - Currently supports only interior DOFs (no shared/constrained DOFs). | ||
| * - The target variable's FE Space must be L2. | ||
| */ | ||
| class MFEMDotProductAux : public MFEMAuxKernel | ||
| { | ||
| public: | ||
| static InputParameters validParams(); | ||
|
|
||
| MFEMDotProductAux(const InputParameters & parameters); | ||
| ~MFEMDotProductAux() override = default; | ||
|
|
||
| void execute() override; | ||
|
|
||
| protected: | ||
| /// Names of vector sources | ||
| 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; | ||
|
|
||
| /// Coefficient wrappers | ||
| mfem::VectorGridFunctionCoefficient _u_coef; | ||
| mfem::VectorGridFunctionCoefficient _v_coef; | ||
| mfem::InnerProductCoefficient _dot_uv; | ||
| mfem::ConstantCoefficient _scale_c; | ||
|
|
||
| ///Final coefficient that applies the scale factor to the inner product | ||
| 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
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,73 @@ | ||
| //* 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) | ||
| { | ||
| // Check the target variable type and dimensions | ||
| 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 | ||
| 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() | ||
| { | ||
|
|
||
| // MFEM element projection for L2 | ||
| _result_var = 0.0; | ||
| _result_var.ProjectCoefficient(_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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| //* 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 | ||
|
|
||
| #include "MFEMDotProductAux.h" | ||
| #include "MFEMProblem.h" | ||
|
|
||
| registerMooseObject("MooseApp", MFEMDotProductAux); | ||
|
|
||
| InputParameters | ||
| MFEMDotProductAux::validParams() | ||
| { | ||
| InputParameters params = MFEMAuxKernel::validParams(); | ||
| params.addClassDescription("Project s(x) * (U . V) onto a scalar MFEM auxvariable."); | ||
| params.addRequiredParam<VariableName>("first_source_vec", "Vector MFEMVariable U"); | ||
| params.addRequiredParam<VariableName>("second_source_vec", "Vector MFEMVariable V"); | ||
| params.addParam<mfem::real_t>( | ||
| "scale_factor", 1.0, "Constant multiplier applied to the dot product"); | ||
| return params; | ||
| } | ||
|
|
||
| MFEMDotProductAux::MFEMDotProductAux(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), | ||
| _dot_uv(_u_coef, _v_coef), | ||
| _scale_c(_scale_factor), | ||
| _final_coef(_scale_c, _dot_uv) | ||
| { | ||
| // Must be L2 | ||
| mfem::ParFiniteElementSpace * fes = _result_var.ParFESpace(); | ||
| if (!dynamic_cast<const mfem::L2_FECollection *>(fes->FEColl())) | ||
| paramError("variable", "The target variable must use L2_FECollection."); | ||
|
|
||
| // Must have no shared/constrained DOFs | ||
GiudGiud marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (fes->GetTrueVSize() != fes->GetVSize()) | ||
| mooseError("MFEMDotProductAux currently supports only L2 spaces with interior DOFs (no " | ||
| "shared/constrained DOFs)."); | ||
| } | ||
|
|
||
| void | ||
| MFEMDotProductAux::execute() | ||
| { | ||
| // Project into the scalar aux result variable per element projection for L2 | ||
| _result_var = 0.0; | ||
| _result_var.ProjectCoefficient(_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
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.