From 04a62274a5f2c99a45e0802c82784e8732e06111 Mon Sep 17 00:00:00 2001 From: Daniel Schwen Date: Wed, 8 May 2024 13:11:26 -0600 Subject: [PATCH] Address comments (#27513) --- .../include/actions/MaterialOutputAction.h | 2 +- .../include/auxkernels/MaterialAuxBase.h | 9 +- framework/include/base/MooseObject.h | 2 +- framework/include/utils/ADReal.h | 111 ------------------ framework/include/utils/EigenADReal.h | 111 ++++++++++++++++++ framework/include/utils/MooseTypes.h | 1 + framework/include/utils/MooseUtils.h | 3 +- framework/src/actions/MaterialOutputAction.C | 33 ++---- .../PenaltySimpleCohesiveZoneModel.h | 2 +- modules/contact/include/utils/TwoVector.h | 2 +- .../auxkernels/functor_material_aux/real.i | 4 +- .../auxkernels/functor_material_aux/tests | 2 +- unit/src/ADTypesTest.C | 2 +- 13 files changed, 134 insertions(+), 150 deletions(-) diff --git a/framework/include/actions/MaterialOutputAction.h b/framework/include/actions/MaterialOutputAction.h index bccce6f0dab7..c7940657c1fb 100644 --- a/framework/include/actions/MaterialOutputAction.h +++ b/framework/include/actions/MaterialOutputAction.h @@ -46,7 +46,7 @@ class MaterialOutputAction : public Action /// Universal output object setup function std::vector outputHelper(const OutputMetaData & metadata, - const MaterialPropertyName & property_name, + const std::string & property_name, const std::string & var_name_base, const MaterialBase & material, bool get_names_only); diff --git a/framework/include/auxkernels/MaterialAuxBase.h b/framework/include/auxkernels/MaterialAuxBase.h index a8c0d19020fa..1e4565188bcb 100644 --- a/framework/include/auxkernels/MaterialAuxBase.h +++ b/framework/include/auxkernels/MaterialAuxBase.h @@ -68,8 +68,11 @@ InputParameters MaterialAuxBaseTempl::validParams() { InputParameters params = AuxKernelTempl::validParams(); - params.addRequiredParam("property", - "The scalar (functor)material property name."); + if constexpr (is_functor) + params.addRequiredParam("functor", "The functor name."); + else + params.addRequiredParam("property", "The material property name."); + params.addParam( "factor", 1, "The factor by which to multiply your material property for visualization"); params.addParam("offset", 0, "The offset to add to your material property for visualization"); @@ -93,7 +96,7 @@ MaterialAuxBaseTempl::MaterialAuxBaseTempl( : AuxKernelTempl(parameters), _prop([this]() -> const auto & { if constexpr (is_functor) - return this->template getFunctor>("property"); + return this->template getFunctor>("functor"); else return this->template getGenericMaterialProperty("property"); }()), diff --git a/framework/include/base/MooseObject.h b/framework/include/base/MooseObject.h index 2f363eaeb8b2..e605a297d9ac 100644 --- a/framework/include/base/MooseObject.h +++ b/framework/include/base/MooseObject.h @@ -10,13 +10,13 @@ #pragma once // MOOSE includes +#include "MooseUtils.h" #include "MooseBase.h" #include "MooseBaseParameterInterface.h" #include "MooseBaseErrorInterface.h" #include "InputParameters.h" #include "ConsoleStreamInterface.h" #include "Registry.h" -#include "MooseUtils.h" #include "DataFileInterface.h" #include "MooseObjectParameterName.h" diff --git a/framework/include/utils/ADReal.h b/framework/include/utils/ADReal.h index 4c3f462e891d..a90985172d5b 100644 --- a/framework/include/utils/ADReal.h +++ b/framework/include/utils/ADReal.h @@ -11,114 +11,3 @@ #include "ADRealForward.h" #include "DualRealOps.h" - -namespace Eigen -{ -namespace internal -{ -template -inline bool -isinf_impl(const MetaPhysicL::DualNumber & a) -{ - return std::isinf(a); -} - -template -inline bool -isnan_impl(const MetaPhysicL::DualNumber & a) -{ - return std::isnan(a); -} - -template -inline MetaPhysicL::DualNumber -sqrt(const MetaPhysicL::DualNumber & a) -{ - return std::sqrt(a); -} - -template -inline MetaPhysicL::DualNumber -abs(const MetaPhysicL::DualNumber & a) -{ - return std::abs(a); -} -} -} // namespace Eigen - -// this include _must_ come after the Eigen::internal overloads above. We also ignore a warning -// about an Eigen internal use of a potentially uninitialized variable -#include "libmesh/ignore_warnings.h" -#include -#include "libmesh/restore_warnings.h" - -// Eigen needs this -namespace MetaPhysicL -{ -// raw_value AD->non-AD conversion for ADReal valued Eigen::Matrix objects -template -struct RawType> -{ - typedef Eigen::Matrix::value_type, M, N, O, M2, N2> value_type; - - static value_type value(const Eigen::Matrix & in) - { - return value_type::NullaryExpr([&in](Eigen::Index i) { return raw_value(in(i)); }); - } -}; - -// raw_value overload for Map type objects that forces evaluation -template -auto -raw_value(const Eigen::Map & in) -{ - return raw_value(in.eval()); -} -} // namespace MetaPhysicL - -namespace Eigen -{ -// libEigen support for dual number types -template -struct NumTraits> - : NumTraits // permits to get the epsilon, dummy_precision, lowest, highest functions -{ - typedef MetaPhysicL::DualNumber Real; - typedef MetaPhysicL::DualNumber NonInteger; - typedef MetaPhysicL::DualNumber Nested; - - enum - { - IsComplex = 0, - IsInteger = 0, - IsSigned = 1, - RequireInitialization = 1, - ReadCost = HugeCost, - AddCost = HugeCost, - MulCost = HugeCost - }; -}; - -template -struct ScalarBinaryOpTraits, BinaryOp> -{ - typedef MetaPhysicL::DualNumber ReturnType; -}; -template -struct ScalarBinaryOpTraits, Real, BinaryOp> -{ - typedef MetaPhysicL::DualNumber ReturnType; -}; -} // namespace Eigen - -namespace Moose -{ -template -struct ADType; - -template -struct ADType> -{ - typedef typename Eigen::Matrix::type, M, N, O, M2, N2> type; -}; -} diff --git a/framework/include/utils/EigenADReal.h b/framework/include/utils/EigenADReal.h index 5fc7c83fa1c3..71f36c47d457 100644 --- a/framework/include/utils/EigenADReal.h +++ b/framework/include/utils/EigenADReal.h @@ -10,7 +10,118 @@ #pragma once #include "ADReal.h" +#include "metaphysicl/raw_type.h" + +namespace Eigen +{ +namespace internal +{ +template +inline bool +isinf_impl(const MetaPhysicL::DualNumber & a) +{ + return std::isinf(a); +} + +template +inline bool +isnan_impl(const MetaPhysicL::DualNumber & a) +{ + return std::isnan(a); +} + +template +inline MetaPhysicL::DualNumber +sqrt(const MetaPhysicL::DualNumber & a) +{ + return std::sqrt(a); +} + +template +inline MetaPhysicL::DualNumber +abs(const MetaPhysicL::DualNumber & a) +{ + return std::abs(a); +} +} +} // namespace Eigen + +// this include _must_ come after the Eigen::internal overloads above. We also ignore a warning +// about an Eigen internal use of a potentially uninitialized variable +#include "libmesh/ignore_warnings.h" #include +#include "libmesh/restore_warnings.h" + +// Eigen needs this +namespace MetaPhysicL +{ +// raw_value AD->non-AD conversion for ADReal valued Eigen::Matrix objects +template +struct RawType> +{ + typedef Eigen::Matrix::value_type, M, N, O, M2, N2> value_type; + + static value_type value(const Eigen::Matrix & in) + { + return value_type::NullaryExpr([&in](Eigen::Index i) { return raw_value(in(i)); }); + } +}; + +// raw_value overload for Map type objects that forces evaluation +template +auto +raw_value(const Eigen::Map & in) +{ + return raw_value(in.eval()); +} +} // namespace MetaPhysicL + +namespace Eigen +{ +// libEigen support for dual number types +template +struct NumTraits> + : NumTraits // permits to get the epsilon, dummy_precision, lowest, highest functions +{ + typedef MetaPhysicL::DualNumber Real; + typedef MetaPhysicL::DualNumber NonInteger; + typedef MetaPhysicL::DualNumber Nested; + + enum + { + IsComplex = 0, + IsInteger = 0, + IsSigned = 1, + RequireInitialization = 1, + ReadCost = HugeCost, + AddCost = HugeCost, + MulCost = HugeCost + }; +}; + +template +struct ScalarBinaryOpTraits, BinaryOp> +{ + typedef MetaPhysicL::DualNumber ReturnType; +}; +template +struct ScalarBinaryOpTraits, Real, BinaryOp> +{ + typedef MetaPhysicL::DualNumber ReturnType; +}; +} // namespace Eigen + +namespace Moose +{ +template +struct ADType; + +template +struct ADType> +{ + typedef typename Eigen::Matrix::type, M, N, O, M2, N2> type; +}; +} namespace Eigen::internal { diff --git a/framework/include/utils/MooseTypes.h b/framework/include/utils/MooseTypes.h index 54f3b803f033..4a0811cbd36c 100644 --- a/framework/include/utils/MooseTypes.h +++ b/framework/include/utils/MooseTypes.h @@ -11,6 +11,7 @@ #include "Moose.h" #include "ADReal.h" +#include "EigenADReal.h" #include "ChainedReal.h" #include "ChainedADReal.h" #include "ADRankTwoTensorForward.h" diff --git a/framework/include/utils/MooseUtils.h b/framework/include/utils/MooseUtils.h index 6692f03e5960..81f5cef566df 100644 --- a/framework/include/utils/MooseUtils.h +++ b/framework/include/utils/MooseUtils.h @@ -10,13 +10,12 @@ #pragma once // MOOSE includes +#include "MooseTypes.h" #include "HashMap.h" #include "InfixIterator.h" #include "MooseEnumItem.h" #include "MooseError.h" -#include "MooseTypes.h" #include "Moose.h" -#include "ADReal.h" #include "ExecutablePath.h" #include "ConsoleUtils.h" diff --git a/framework/src/actions/MaterialOutputAction.C b/framework/src/actions/MaterialOutputAction.C index bb28a360fe5e..3c0517601958 100644 --- a/framework/src/actions/MaterialOutputAction.C +++ b/framework/src/actions/MaterialOutputAction.C @@ -24,30 +24,6 @@ #include "libmesh/utility.h" -// /// List of AuxKernels used for the respective property type output (one entry for each type in SupportedTypes) -// const std::vector MaterialOutputAction::_aux_kernel_names = { -// "MaterialRealAux", -// "MaterialRealVectorValueAux", -// "MaterialRealTensorValueAux", -// "MaterialRankTwoTensorAux", -// "MaterialRankFourTensorAux", -// "MaterialSymmetricRankTwoTensorAux", -// "MaterialSymmetricRankFourTensorAux"}; - -// /// List of index symbols (one entry for each type in SupportedTypes) -// const std::vector MaterialOutputAction::_index_symbols = { -// "", "xyz", "012", "012", "012", "012345", "012345"}; - -// /// List of coefficient parameter names (one entry for each type in SupportedTypes) -// const std::vector> MaterialOutputAction::_param_names = { -// {}, -// {"component"}, -// {"row", "column"}, -// {"i", "j"}, -// {"i", "j", "k", "l"}, -// {"component"}, -// {"i", "j"}}; - registerMooseAction("MooseApp", MaterialOutputAction, "add_output_aux_variables"); registerMooseAction("MooseApp", MaterialOutputAction, "add_aux_kernel"); @@ -338,7 +314,7 @@ MaterialOutputAction::materialOutput(const std::string & property_name, std::vector MaterialOutputAction::outputHelper(const MaterialOutputAction::OutputMetaData & metadata, - const MaterialPropertyName & property_name, + const std::string & property_name, const std::string & var_name_base, const MaterialBase & material, bool get_names_only) @@ -382,7 +358,12 @@ MaterialOutputAction::getParams(const std::string & type, // Set the action parameters InputParameters params = _factory.getValidParams(type); - params.set("property") = property_name; + if (params.have_parameter("property")) + params.set("property") = property_name; + else if (params.have_parameter("functor")) + params.set("functor") = property_name; + else + mooseError("Internal error. AuxKernel has neither a `functor` nor a `property` parameter."); params.set("variable") = variable_name; if (_output_only_on_timestep_end) diff --git a/modules/contact/include/userobjects/PenaltySimpleCohesiveZoneModel.h b/modules/contact/include/userobjects/PenaltySimpleCohesiveZoneModel.h index 70551b0a7543..46bd3873d909 100644 --- a/modules/contact/include/userobjects/PenaltySimpleCohesiveZoneModel.h +++ b/modules/contact/include/userobjects/PenaltySimpleCohesiveZoneModel.h @@ -9,10 +9,10 @@ #pragma once +#include "TwoVector.h" #include "PenaltyWeightedGapUserObject.h" #include "WeightedVelocitiesUserObject.h" #include "AugmentedLagrangeInterface.h" -#include "TwoVector.h" /** * User object that interface pressure resulting from a simple traction separation law. diff --git a/modules/contact/include/utils/TwoVector.h b/modules/contact/include/utils/TwoVector.h index 8f6b18cf957c..98b4f90782df 100644 --- a/modules/contact/include/utils/TwoVector.h +++ b/modules/contact/include/utils/TwoVector.h @@ -9,7 +9,7 @@ #pragma once -#include "ADReal.h" +#include "EigenADReal.h" #include /** diff --git a/test/tests/auxkernels/functor_material_aux/real.i b/test/tests/auxkernels/functor_material_aux/real.i index e58eed116c64..546a47b374dd 100644 --- a/test/tests/auxkernels/functor_material_aux/real.i +++ b/test/tests/auxkernels/functor_material_aux/real.i @@ -29,12 +29,12 @@ [u] type = FunctorMaterialRealAux variable = u - property = functor + functor = functor [] [v] type = FunctorMaterialRealAux variable = v - property = functor + functor = functor [] [] diff --git a/test/tests/auxkernels/functor_material_aux/tests b/test/tests/auxkernels/functor_material_aux/tests index fb56a5bef278..b791b4829262 100644 --- a/test/tests/auxkernels/functor_material_aux/tests +++ b/test/tests/auxkernels/functor_material_aux/tests @@ -4,7 +4,7 @@ input = real.i requirement = "The system shall be able to output a functor to a nodal or elemental variable." design = "MaterialRealAux.md" - issues = #27513 + issues = '#27513' exodiff = real_out.e [] [] diff --git a/unit/src/ADTypesTest.C b/unit/src/ADTypesTest.C index d2b72f3e5554..95ab38f0313b 100644 --- a/unit/src/ADTypesTest.C +++ b/unit/src/ADTypesTest.C @@ -10,7 +10,7 @@ #include "Moose.h" #include "Material.h" #include "DenseMatrix.h" -#include "ADReal.h" +#include "EigenADReal.h" #include "libmesh/dense_vector.h" #include "gtest_include.h"