From 731326336aee75cab6b536db6592f0bac7720380 Mon Sep 17 00:00:00 2001 From: Daniel Schwen Date: Wed, 8 May 2024 09:33:10 -0600 Subject: [PATCH] Backwards compatible approach (#27513) --- .../include/actions/MaterialOutputAction.h | 79 ++-- .../include/auxkernels/MaterialAuxBase.h | 129 ++++--- .../include/auxkernels/MaterialRateAuxBase.h | 2 - .../include/auxkernels/MaterialRealAux.h | 14 +- .../auxkernels/MaterialRealVectorValueAux.h | 16 +- .../VectorMaterialRealVectorValueAux.h | 2 +- framework/include/base/Assembly.h | 2 +- framework/include/functions/Function.h | 9 +- .../functions/PiecewiseMultiInterpolation.h | 5 +- .../include/functions/PiecewiseMultilinear.h | 3 +- framework/include/kernels/BodyForce.h | 2 +- .../materials/MaterialFunctorConverter.h | 2 +- .../include/materials/MaterialProperty.h | 15 +- .../SideDiffusiveFluxIntegral.h | 2 +- framework/include/utils/MooseADWrapper.h | 42 --- framework/include/utils/MooseTypes.h | 67 ++-- framework/include/utils/MooseUtils.h | 2 +- framework/include/utils/NestedSolve.h | 7 +- framework/src/actions/MaterialOutputAction.C | 338 ++++++++++-------- framework/src/auxkernels/MaterialRealAux.C | 24 +- .../auxkernels/MaterialRealVectorValueAux.C | 28 +- .../VectorMaterialRealVectorValueAux.C | 4 +- framework/src/base/Assembly.C | 4 +- .../functions/PiecewiseMultiInterpolation.C | 8 +- .../src/functions/PiecewiseMultilinear.C | 8 +- .../PenaltyInterfaceDiffusion.C | 2 +- .../materials/CoupledValueFunctionMaterial.C | 2 +- .../src/materials/MaterialFunctorConverter.C | 2 +- .../SideDiffusiveFluxIntegral.C | 2 +- .../include/materials/ADComputeFiniteStrain.h | 2 +- .../ADComputeFiniteStrainElasticStress.h | 4 +- .../ADComputeIncrementalSmallStrain.h | 2 +- .../ADComputeIncrementalStrainBase.h | 2 +- .../include/materials/StressUpdateBase.h | 4 +- .../IsotropicPlasticityStressUpdate.C | 2 +- test/include/materials/OutputTestMaterial.h | 5 +- 36 files changed, 423 insertions(+), 420 deletions(-) delete mode 100644 framework/include/utils/MooseADWrapper.h diff --git a/framework/include/actions/MaterialOutputAction.h b/framework/include/actions/MaterialOutputAction.h index af3e58120f6b..bccce6f0dab7 100644 --- a/framework/include/actions/MaterialOutputAction.h +++ b/framework/include/actions/MaterialOutputAction.h @@ -9,72 +9,48 @@ #pragma once -// MOOSE includes #include "Action.h" #include "MaterialData.h" #include "FEProblemBase.h" -#include "SerialAccess.h" class MooseObjectAction; class MaterialBase; -struct MaterialOutputActionDescriptor -{ -}; - /** * Creates AuxVariables and AuxKernels for automatic output of material properties */ class MaterialOutputAction : public Action { public: - /** - * Class constructor - * @param params Input parameters for this action object - */ static InputParameters validParams(); MaterialOutputAction(const InputParameters & params); - virtual void act() override; - /// output function called from SetupOutput::apply (through Moose::typeLoop) - template - void setupOutput(const MaterialPropertyName & prop_name, const MaterialBase & material); + virtual void act() override; -protected: - template - void setupOutputHelper(const MaterialPropertyName & prop_name, const MaterialBase & material); - - /// List of supported raw types (equivalent AD types are also supported) - typedef Moose::TypeList - SupportedTypes; - - /// List of AuxKernels used for the respective property type output ('AD' prefix is added automatically for is_ad) - static const std::vector _aux_kernel_names; - - /// List of index symbols - static const std::vector _index_symbols; - - /// List of coefficient parameter names - static const std::vector> _param_names; - - template - struct SetupOutput + /// Meta data describing the setup of an output object + struct OutputMetaData { - static void apply(MaterialOutputAction * self, - const MaterialPropertyName & prop_name, - const MaterialBase & material) - { - self->setupOutput(prop_name, material); - } + std::string _aux_kernel_name; + std::string _index_symbols; + std::vector _param_names; }; +protected: + /** + * A function to be overriden by derived actions to handle a set of material property types + */ + virtual std::vector materialOutput(const std::string & property_name, + const MaterialBase & material, + bool get_names_only); + + /// Universal output object setup function + std::vector outputHelper(const OutputMetaData & metadata, + const MaterialPropertyName & property_name, + const std::string & var_name_base, + const MaterialBase & material, + bool get_names_only); + /** * Helper method for testing if the material exists as a block or boundary material * @tparam T The property type (e.g., REAL) @@ -108,7 +84,6 @@ class MaterialOutputAction : public Action * * @return An InputParameter object with common properties added. */ - template InputParameters getParams(const std::string & type, const std::string & property_name, const std::string & variable_name, @@ -127,12 +102,6 @@ class MaterialOutputAction : public Action /// variables for the current MaterialBase object std::set _material_variable_names; - /// all variables added by this action - std::set _all_variable_names; - - /// property names we succeeded to set output up for - std::set _supported_properties; - /// Map of output names and list of variables associated with the output std::map> _material_variable_names_map; @@ -169,9 +138,5 @@ template bool MaterialOutputAction::hasFunctorProperty(const std::string & property_name) { - // functors support a limited set of types - if constexpr (std::is_same_v || std::is_same_v) - return _problem->hasFunctorWithType(property_name, 0); - else - return false; + return _problem->hasFunctorWithType(property_name, 0); } diff --git a/framework/include/auxkernels/MaterialAuxBase.h b/framework/include/auxkernels/MaterialAuxBase.h index df876e3ce18c..34957701ee64 100644 --- a/framework/include/auxkernels/MaterialAuxBase.h +++ b/framework/include/auxkernels/MaterialAuxBase.h @@ -16,7 +16,7 @@ * A base class for the various Material related AuxKernal objects. * \p RT is short for return type */ -template +template class MaterialAuxBaseTempl : public AuxKernelTempl { public: @@ -29,10 +29,9 @@ class MaterialAuxBaseTempl : public AuxKernelTempl MaterialAuxBaseTempl(const InputParameters & parameters); /// Functors really only work for Real and RealVectorValue for now :( - using MaterialAuxFunctorType = - typename std::conditional || std::is_same_v, - Moose::Functor>, - void>::type; + using PropertyType = typename std::conditional>, + GenericMaterialProperty>::type; protected: virtual RT computeValue() override; @@ -43,17 +42,14 @@ class MaterialAuxBaseTempl : public AuxKernelTempl /// Returns material property values at quadrature points virtual RT getRealValue() = 0; - /// Material property for this AuxKernel - const GenericMaterialProperty * _property; - - /// Functor for this AuxKernel - const MaterialAuxFunctorType * _functor; + /// (Functor)Material property for this AuxKernel + const PropertyType & _prop; /// Evaluate at this quadrature point only const unsigned int _selected_qp; /// T Value evaluated from either the property or the functor - GenericType _full_value; + Moose::GenericType _full_value; private: /// Multiplier for the material property @@ -61,67 +57,76 @@ class MaterialAuxBaseTempl : public AuxKernelTempl /// Value to be added to the material property const RT _offset; + + /// ID of the subdomain currently being iterated over + const SubdomainID & _current_subdomain_id; }; -template +template InputParameters -MaterialAuxBaseTempl::validParams() +MaterialAuxBaseTempl::validParams() { InputParameters params = AuxKernelTempl::validParams(); - params.addParam( - "property", "The scalar material property name (set either this or `functor`)."); - // functors do not support all types - if constexpr (!std::is_same_v) - params.addParam( - "functor", "The scalar material property name (set either this or `property`)."); + params.addRequiredParam("property", + "The scalar (functor)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"); - params.addParam( - "selected_qp", - "Evaluate the material property at a specified quadrature point. This only needs " - "to be used if you are interested in a particular quadrature point in each element. " - "Otherwise do not include this parameter in your input file."); - params.addParamNamesToGroup("selected_qp", "Advanced"); + if constexpr (!is_functor) + { + params.addParam( + "selected_qp", + "Evaluate the material property at a specified quadrature point. This only needs " + "to be used if you are interested in a particular quadrature point in each element. " + "Otherwise do not include this parameter in your input file."); + params.addParamNamesToGroup("selected_qp", "Advanced"); + } return params; } -template -MaterialAuxBaseTempl::MaterialAuxBaseTempl(const InputParameters & parameters) +template +MaterialAuxBaseTempl::MaterialAuxBaseTempl( + const InputParameters & parameters) : AuxKernelTempl(parameters), - _property(this->isParamValid("property") - ? &this->template getGenericMaterialProperty("property") - : nullptr), - _functor(this->isParamValid("functor") - ? [this]() { - if constexpr (!std::is_same_v) - return &this->template getFunctor>("functor"); - else - { - libmesh_ignore(this); - return nullptr; - } - }() - : nullptr), - _selected_qp(this->isParamValid("selected_qp") ? this->template getParam("selected_qp") : libMesh::invalid_uint), + _prop([this]() -> const auto & { + if constexpr (is_functor) + return this->template getFunctor>("property"); + else + return this->template getGenericMaterialProperty("property"); + }()), + _selected_qp(this->isParamValid("selected_qp") + ? this->template getParam("selected_qp") + : libMesh::invalid_uint), _factor(this->template getParam("factor")), - _offset(this->template getParam("offset")) + _offset(this->template getParam("offset")), + _current_subdomain_id(this->_assembly.currentSubdomainID()) { - if (!_property == !_functor) - mooseError("Specify either a `property` or a `functor` parameter."); - if (_functor && _selected_qp != libMesh::invalid_uint) - this->paramError("selected_qp", - "Selective quadrature point evaluation is not implemented for functors."); } -template +template RT -MaterialAuxBaseTempl::computeValue() +MaterialAuxBaseTempl::computeValue() { - // Material Property Values - if (_property) + // Functor Values + if constexpr (is_functor) + { + if (this->isNodal()) + { + const Moose::NodeArg node_arg{this->_current_node, _current_subdomain_id}; + const auto state = this->determineState(); + _full_value = _prop(node_arg, state); + } + else + { + const auto elem_arg = this->makeElemArg(this->_current_elem); + const auto state = this->determineState(); + _full_value = _prop(elem_arg, state); + } + } + // Material Properties + else { if (_selected_qp != libMesh::invalid_uint) { @@ -135,29 +140,15 @@ MaterialAuxBaseTempl::computeValue() this->_q_point.size(), " quadrature points in the element"); } - _full_value = (*_property)[_selected_qp]; - } - else - _full_value = (*_property)[this->_qp]; - } - - // Functor Values - if (_functor) - { - if constexpr (!std::is_same_v) - { - const auto elem_arg = this->makeElemArg(this->_current_elem); - const auto state = this->determineState(); - _full_value = (*_functor)(elem_arg, state); + _full_value = _prop[_selected_qp]; } else - mooseError("Unsupported functor type"); + _full_value = _prop[this->_qp]; } checkFullValue(); - return _factor * getRealValue() + _offset; } template -using MaterialAuxBase = MaterialAuxBaseTempl; +using MaterialAuxBase = MaterialAuxBaseTempl; diff --git a/framework/include/auxkernels/MaterialRateAuxBase.h b/framework/include/auxkernels/MaterialRateAuxBase.h index e1b93408d4b1..277ff76270a2 100644 --- a/framework/include/auxkernels/MaterialRateAuxBase.h +++ b/framework/include/auxkernels/MaterialRateAuxBase.h @@ -44,8 +44,6 @@ MaterialRateAuxBaseTempl::MaterialRateAuxBaseTempl(const InputPara : MaterialAuxBaseTempl(parameters), _prop_old(this->template getMaterialPropertyOld("property")) { - if (!this->_property) - this->paramError("functor", "This object does not support functors yet."); } template diff --git a/framework/include/auxkernels/MaterialRealAux.h b/framework/include/auxkernels/MaterialRealAux.h index f17baf4fd74c..242242be67a6 100644 --- a/framework/include/auxkernels/MaterialRealAux.h +++ b/framework/include/auxkernels/MaterialRealAux.h @@ -12,16 +12,11 @@ // MOOSE includes #include "MaterialAuxBase.h" -// Forward Declarations -template -class MaterialRealAuxTempl; -typedef MaterialRealAuxTempl MaterialRealAux; - /** * Object for passing a scalar, REAL material property to an AuxVariable */ -template -class MaterialRealAuxTempl : public MaterialAuxBaseTempl +template +class MaterialRealAuxTempl : public MaterialAuxBaseTempl { public: static InputParameters validParams(); @@ -37,4 +32,7 @@ class MaterialRealAuxTempl : public MaterialAuxBaseTempl Real getRealValue() override; }; -typedef MaterialRealAuxTempl ADMaterialRealAux; +typedef MaterialRealAuxTempl MaterialRealAux; +typedef MaterialRealAuxTempl ADMaterialRealAux; +typedef MaterialRealAuxTempl FunctorMaterialRealAux; +typedef MaterialRealAuxTempl ADFunctorMaterialRealAux; diff --git a/framework/include/auxkernels/MaterialRealVectorValueAux.h b/framework/include/auxkernels/MaterialRealVectorValueAux.h index 03e156a3be18..b2c6fcbf7a3e 100644 --- a/framework/include/auxkernels/MaterialRealVectorValueAux.h +++ b/framework/include/auxkernels/MaterialRealVectorValueAux.h @@ -16,8 +16,8 @@ /** * AuxKernel for outputting a RealVectorValue material property component to an AuxVariable */ -template -class MaterialRealVectorValueAuxTempl : public MaterialAuxBaseTempl +template +class MaterialRealVectorValueAuxTempl : public MaterialAuxBaseTempl { public: static InputParameters validParams(); @@ -35,9 +35,13 @@ class MaterialRealVectorValueAuxTempl : public MaterialAuxBaseTempl unsigned int _component; }; -typedef MaterialRealVectorValueAuxTempl MaterialRealVectorValueAux; -typedef MaterialRealVectorValueAuxTempl ADMaterialRealVectorValueAux; -typedef MaterialRealVectorValueAuxTempl +typedef MaterialRealVectorValueAuxTempl MaterialRealVectorValueAux; +typedef MaterialRealVectorValueAuxTempl ADMaterialRealVectorValueAux; +typedef MaterialRealVectorValueAuxTempl + FunctorMaterialRealVectorValueAux; +typedef MaterialRealVectorValueAuxTempl + ADFunctorMaterialRealVectorValueAux; +typedef MaterialRealVectorValueAuxTempl MaterialSymmetricRankTwoTensorAux; -typedef MaterialRealVectorValueAuxTempl +typedef MaterialRealVectorValueAuxTempl ADMaterialSymmetricRankTwoTensorAux; diff --git a/framework/include/auxkernels/VectorMaterialRealVectorValueAux.h b/framework/include/auxkernels/VectorMaterialRealVectorValueAux.h index efbfbb54d19a..907c0107377a 100644 --- a/framework/include/auxkernels/VectorMaterialRealVectorValueAux.h +++ b/framework/include/auxkernels/VectorMaterialRealVectorValueAux.h @@ -17,7 +17,7 @@ */ template class VectorMaterialRealVectorValueAuxTempl - : public MaterialAuxBaseTempl + : public MaterialAuxBaseTempl { public: static InputParameters validParams(); diff --git a/framework/include/base/Assembly.h b/framework/include/base/Assembly.h index 76f221963e3a..62a4fe32b77f 100644 --- a/framework/include/base/Assembly.h +++ b/framework/include/base/Assembly.h @@ -358,7 +358,7 @@ class Assembly } template - const MooseArray> & genericQPoints() const; + const MooseArray> & genericQPoints() const; /** * Return the current element diff --git a/framework/include/functions/Function.h b/framework/include/functions/Function.h index e336238074a8..3f5912ab6b12 100644 --- a/framework/include/functions/Function.h +++ b/framework/include/functions/Function.h @@ -18,7 +18,6 @@ #include "MeshChangedInterface.h" #include "ScalarCoupleable.h" #include "MooseFunctor.h" -#include "MooseADWrapper.h" #include "ChainedReal.h" // libMesh @@ -209,7 +208,7 @@ template auto Function::value(const U & t) const { - static const GenericType::value> p; + static const Moose::GenericType::value> p; return value(t, p); } @@ -217,7 +216,7 @@ template auto Function::value(const U & t, const U & x, const U & y, const U & z) const { - GenericType::value> p(x, y, z); + Moose::GenericType::value> p(x, y, z); return value(t, p); } @@ -225,7 +224,7 @@ template auto Function::timeDerivative(const U & t) const { - static const GenericType::value> p; + static const Moose::GenericType::value> p; return timeDerivative(t, p); } @@ -233,6 +232,6 @@ template auto Function::timeDerivative(const U & t, const U & x, const U & y, const U & z) const { - GenericType::value> p(x, y, z); + Moose::GenericType::value> p(x, y, z); return timeDerivative(t, p); } diff --git a/framework/include/functions/PiecewiseMultiInterpolation.h b/framework/include/functions/PiecewiseMultiInterpolation.h index e2d3eb89b404..55cd1398a069 100644 --- a/framework/include/functions/PiecewiseMultiInterpolation.h +++ b/framework/include/functions/PiecewiseMultiInterpolation.h @@ -47,8 +47,9 @@ class PiecewiseMultiInterpolation : public Function /// convert cartesian+time coordinates into grid coordinates template - GenericType pointInGrid(const GenericType & t, - const GenericType & p) const; + Moose::GenericType + pointInGrid(const Moose::GenericType & t, + const Moose::GenericType & p) const; /** * This does the core work. Given a point, pt, defined diff --git a/framework/include/functions/PiecewiseMultilinear.h b/framework/include/functions/PiecewiseMultilinear.h index 57f8f3172f52..70b1e6591511 100644 --- a/framework/include/functions/PiecewiseMultilinear.h +++ b/framework/include/functions/PiecewiseMultilinear.h @@ -39,5 +39,6 @@ class PiecewiseMultilinear : public PiecewiseMultiInterpolation private: template - GenericType sampleInternal(const GenericType pt) const; + Moose::GenericType + sampleInternal(const Moose::GenericType pt) const; }; diff --git a/framework/include/kernels/BodyForce.h b/framework/include/kernels/BodyForce.h index 66767e7cfbc1..153e343baa39 100644 --- a/framework/include/kernels/BodyForce.h +++ b/framework/include/kernels/BodyForce.h @@ -42,7 +42,7 @@ class BodyForceTempl : public GenericKernel const PostprocessorValue & _postprocessor; // AD/non-AD version of the quadrature point coordinates - const MooseArray> * _generic_q_point; + const MooseArray> * _generic_q_point; usingGenericKernelMembers; }; diff --git a/framework/include/materials/MaterialFunctorConverter.h b/framework/include/materials/MaterialFunctorConverter.h index 75fddc943224..44631bd91f48 100644 --- a/framework/include/materials/MaterialFunctorConverter.h +++ b/framework/include/materials/MaterialFunctorConverter.h @@ -30,7 +30,7 @@ class MaterialFunctorConverterTempl : public Material const std::size_t _num_functors_to_convert; /// Incoming functors to convert. We up-convert non-AD functors to AD functors to ease implementation - std::vector> *> _functors_in; + std::vector> *> _functors_in; /// Regular material properties to create std::vector *> _reg_props_out; /// AD material properties to create diff --git a/framework/include/materials/MaterialProperty.h b/framework/include/materials/MaterialProperty.h index 038ceed46290..4ca96ef53498 100644 --- a/framework/include/materials/MaterialProperty.h +++ b/framework/include/materials/MaterialProperty.h @@ -13,7 +13,6 @@ #include #include -#include "MooseADWrapper.h" #include "MooseArray.h" #include "MooseTypes.h" #include "DataIO.h" @@ -110,7 +109,7 @@ template class MaterialPropertyBase : public PropertyValue { public: - typedef GenericType value_type; + typedef Moose::GenericType value_type; MaterialPropertyBase(const PropertyValue::id_type id) : PropertyValue(id) {} @@ -119,12 +118,12 @@ class MaterialPropertyBase : public PropertyValue /** * @returns a read-only reference to the parameter value. */ - const MooseArray> & get() const { return _value; } + const MooseArray> & get() const { return _value; } /** * @returns a writable reference to the parameter value. */ - MooseArray> & set() { return _value; } + MooseArray> & set() { return _value; } /** * String identifying the type of parameter stored. @@ -141,12 +140,12 @@ class MaterialPropertyBase : public PropertyValue /** * Get element i out of the array as a writeable reference. */ - GenericType & operator[](const unsigned int i) { return _value[i]; } + Moose::GenericType & operator[](const unsigned int i) { return _value[i]; } /** * Get element i out of the array as a ready-only reference. */ - const GenericType & operator[](const unsigned int i) const { return _value[i]; } + const Moose::GenericType & operator[](const unsigned int i) const { return _value[i]; } /** * Copy the value of a Property from one specific to a specific qp in this Property. @@ -197,7 +196,7 @@ class MaterialPropertyBase : public PropertyValue protected: /// Stored parameter value. - MooseArray> _value; + MooseArray> _value; }; template @@ -471,7 +470,7 @@ class GenericOptionalMaterialProperty : public GenericOptionalMaterialPropertyBa operator=(const GenericOptionalMaterialProperty &) = delete; /// pass through operator[] to provide a similar API as MaterialProperty - const GenericType & operator[](const unsigned int i) const + const Moose::GenericType & operator[](const unsigned int i) const { // check if the optional property is valid in debug mode mooseAssert( diff --git a/framework/include/postprocessors/SideDiffusiveFluxIntegral.h b/framework/include/postprocessors/SideDiffusiveFluxIntegral.h index f0d4a102aac8..1b8d28cadefb 100644 --- a/framework/include/postprocessors/SideDiffusiveFluxIntegral.h +++ b/framework/include/postprocessors/SideDiffusiveFluxIntegral.h @@ -36,7 +36,7 @@ class SideDiffusiveFluxIntegralTempl : public SideIntegralVariablePostprocessor Real computeFaceInfoIntegral(const FaceInfo * fi) override; const GenericMaterialProperty * const _diffusion_coef; - const Moose::Functor> * const _functor_diffusion_coef; + const Moose::Functor> * const _functor_diffusion_coef; private: /// Routine to get the diffusive flux with a Real diffusivity diff --git a/framework/include/utils/MooseADWrapper.h b/framework/include/utils/MooseADWrapper.h deleted file mode 100644 index d3f0e68c5924..000000000000 --- a/framework/include/utils/MooseADWrapper.h +++ /dev/null @@ -1,42 +0,0 @@ -//* This file is part of the MOOSE framework -//* https://www.mooseframework.org -//* -//* 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 - -#pragma once - -#include "MooseTypes.h" - -template -struct MooseIsADType -{ - static constexpr bool value = false; -}; - -template <> -struct MooseIsADType -{ - static constexpr bool value = true; -}; - -template <> -struct MooseIsADType -{ - static constexpr bool value = true; -}; - -template