-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Extend MFEMSumAux to sum over an arbitrary number of MFEMVariables #31599
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
lindsayad
merged 7 commits into
idaholab:next
from
alexanderianblair:alexanderianblair/mfem-multivariate-sum
Oct 3, 2025
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f287180
Extend MFEMSumAux to sum an arbitrary number of MFEMVariables. Refs #…
alexanderianblair 416f653
Build default scale factors in MFEMSumAux if not provided by the user…
alexanderianblair 9ecba66
Add unit test to check implementation of scale factors and check FESp…
alexanderianblair b2781bd
Add unit test to check an inconsistent number of scale factors relati…
alexanderianblair 89bd234
Add missing copyright header to MFEM unit tests
alexanderianblair 1643c99
Change mooseError calls in MFEMSumAux to paramErrors for greater desc…
alexanderianblair 44238c2
Apply suggestions from code review
alexanderianblair 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
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
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,86 @@ | ||
| //* 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 | ||
lindsayad marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| #include "MFEMObjectUnitTest.h" | ||
| #include "MFEMSumAux.h" | ||
|
|
||
| class MFEMAuxKernelTest : public MFEMObjectUnitTest | ||
| { | ||
| public: | ||
| MFEMAuxKernelTest() : MFEMObjectUnitTest("MooseUnitApp") {} | ||
| }; | ||
|
|
||
| /** | ||
| * Test MFEMSumAux creates sums input GridFunctions successfully. | ||
| */ | ||
| TEST_F(MFEMAuxKernelTest, MFEMSumAux) | ||
| { | ||
| // Register dummy (Par)GridFunctions to test MFEMSumAux against | ||
| auto pm = _mfem_mesh_ptr->getMFEMParMeshPtr().get(); | ||
| mfem::common::H1_ParFESpace fe(pm, 1); | ||
| mfem::common::H1_ParFESpace different_fe(pm, 2); | ||
|
|
||
| auto pgf_1 = std::make_shared<mfem::ParGridFunction>(&fe); | ||
| auto pgf_2 = std::make_shared<mfem::ParGridFunction>(&fe); | ||
| auto pgf_3 = std::make_shared<mfem::ParGridFunction>(&fe); | ||
| auto pgf_out = std::make_shared<mfem::ParGridFunction>(&fe); | ||
| auto pgf_ho = std::make_shared<mfem::ParGridFunction>(&different_fe); | ||
|
|
||
| _mfem_problem->getProblemData().gridfunctions.Register("source_variable_1", pgf_1); | ||
| _mfem_problem->getProblemData().gridfunctions.Register("source_variable_2", pgf_2); | ||
| _mfem_problem->getProblemData().gridfunctions.Register("source_variable_3", pgf_3); | ||
| _mfem_problem->getProblemData().gridfunctions.Register("summed_variable", pgf_out); | ||
| _mfem_problem->getProblemData().gridfunctions.Register("source_ho_variable", pgf_ho); | ||
|
|
||
| // Initialise variables that are to be summed over | ||
| mfem::ConstantCoefficient initial_condition_coef(2.0); | ||
| pgf_1->ProjectCoefficient(initial_condition_coef); | ||
| pgf_2->ProjectCoefficient(initial_condition_coef); | ||
| pgf_3->ProjectCoefficient(initial_condition_coef); | ||
| pgf_ho->ProjectCoefficient(initial_condition_coef); | ||
|
|
||
| { | ||
| // Construct auxkernel | ||
| InputParameters auxkernel_params = _factory.getValidParams("MFEMSumAux"); | ||
| auxkernel_params.set<AuxVariableName>("variable") = "summed_variable"; | ||
| auxkernel_params.set<std::vector<VariableName>>("source_variables") = { | ||
| "source_variable_1", "source_variable_2", "source_variable_3"}; | ||
| auxkernel_params.set<std::vector<mfem::real_t>>("scale_factors") = {1.0, 2.0, 5.0}; | ||
|
|
||
| MFEMSumAux & auxkernel = addObject<MFEMSumAux>("MFEMSumAux", "auxkernel1", auxkernel_params); | ||
| auxkernel.execute(); | ||
|
|
||
| // Check the value of the output gridfunction is the scaled sum of the components | ||
| ASSERT_EQ(pgf_out->GetData()[5], 16.0); | ||
| } | ||
| { | ||
| // Check for failure if a variable to be summed has a different FESpace from the parent | ||
| InputParameters auxkernel_params = _factory.getValidParams("MFEMSumAux"); | ||
| auxkernel_params.set<AuxVariableName>("variable") = "summed_variable"; | ||
| auxkernel_params.set<std::vector<VariableName>>("source_variables") = { | ||
| "source_variable_1", "source_ho_variable", "source_variable_3"}; | ||
| auxkernel_params.set<std::vector<mfem::real_t>>("scale_factors") = {1.0, 2.0, 5.0}; | ||
| EXPECT_THROW(addObject<MFEMSumAux>("MFEMSumAux", "failed_auxkernel", auxkernel_params), | ||
| std::runtime_error); | ||
| } | ||
| { | ||
| // Check for failure if an inconsistent number of scale factors are provided | ||
| InputParameters auxkernel_params = _factory.getValidParams("MFEMSumAux"); | ||
| auxkernel_params.set<AuxVariableName>("variable") = "summed_variable"; | ||
| auxkernel_params.set<std::vector<VariableName>>("source_variables") = { | ||
| "source_variable_1", "source_variable_2", "source_variable_3"}; | ||
| auxkernel_params.set<std::vector<mfem::real_t>>("scale_factors") = {1.0, 2.0}; | ||
| EXPECT_THROW(addObject<MFEMSumAux>("MFEMSumAux", "failed_scaled_auxkernel", auxkernel_params), | ||
| std::runtime_error); | ||
| } | ||
| } | ||
|
|
||
| #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
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
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
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
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.