Skip to content

Commit

Permalink
Address comments (#27513)
Browse files Browse the repository at this point in the history
  • Loading branch information
dschwen committed May 8, 2024
1 parent 0eacf4f commit 37fe25d
Show file tree
Hide file tree
Showing 11 changed files with 122 additions and 145 deletions.
2 changes: 1 addition & 1 deletion framework/include/actions/MaterialOutputAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class MaterialOutputAction : public Action

/// Universal output object setup function
std::vector<std::string> 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);
Expand Down
5 changes: 3 additions & 2 deletions framework/include/auxkernels/MaterialAuxBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class MaterialAuxBaseTempl : public AuxKernelTempl<RT>
using PropertyType = typename std::conditional<is_functor,
Moose::Functor<Moose::GenericType<T, is_ad>>,
GenericMaterialProperty<T, is_ad>>::type;
using PropertyName =
typename std::conditional<is_functor, MooseFunctorName, MaterialPropertyName>::type;

protected:
virtual RT computeValue() override;
Expand Down Expand Up @@ -68,8 +70,7 @@ InputParameters
MaterialAuxBaseTempl<T, is_ad, is_functor, RT>::validParams()
{
InputParameters params = AuxKernelTempl<RT>::validParams();
params.addRequiredParam<MaterialPropertyName>("property",
"The scalar (functor)material property name.");
params.addRequiredParam<PropertyName>("property", "The scalar (functor)material property name.");
params.addParam<Real>(
"factor", 1, "The factor by which to multiply your material property for visualization");
params.addParam<RT>("offset", 0, "The offset to add to your material property for visualization");
Expand Down
2 changes: 1 addition & 1 deletion framework/include/base/MooseObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
111 changes: 0 additions & 111 deletions framework/include/utils/ADReal.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,114 +11,3 @@

#include "ADRealForward.h"
#include "DualRealOps.h"

namespace Eigen
{
namespace internal
{
template <typename V, typename D, bool asd>
inline bool
isinf_impl(const MetaPhysicL::DualNumber<V, D, asd> & a)
{
return std::isinf(a);
}

template <typename V, typename D, bool asd>
inline bool
isnan_impl(const MetaPhysicL::DualNumber<V, D, asd> & a)
{
return std::isnan(a);
}

template <typename V, typename D, bool asd>
inline MetaPhysicL::DualNumber<V, D, asd>
sqrt(const MetaPhysicL::DualNumber<V, D, asd> & a)
{
return std::sqrt(a);
}

template <typename V, typename D, bool asd>
inline MetaPhysicL::DualNumber<V, D, asd>
abs(const MetaPhysicL::DualNumber<V, D, asd> & 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 <Eigen/Core>
#include "libmesh/restore_warnings.h"

// Eigen needs this
namespace MetaPhysicL
{
// raw_value AD->non-AD conversion for ADReal valued Eigen::Matrix objects
template <typename T, int M, int N, int O, int M2, int N2>
struct RawType<Eigen::Matrix<T, M, N, O, M2, N2>>
{
typedef Eigen::Matrix<typename RawType<T>::value_type, M, N, O, M2, N2> value_type;

static value_type value(const Eigen::Matrix<T, M, N, O, M2, N2> & 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 <typename T>
auto
raw_value(const Eigen::Map<T> & in)
{
return raw_value(in.eval());
}
} // namespace MetaPhysicL

namespace Eigen
{
// libEigen support for dual number types
template <typename V, typename D, bool asd>
struct NumTraits<MetaPhysicL::DualNumber<V, D, asd>>
: NumTraits<V> // permits to get the epsilon, dummy_precision, lowest, highest functions
{
typedef MetaPhysicL::DualNumber<V, D, asd> Real;
typedef MetaPhysicL::DualNumber<V, D, asd> NonInteger;
typedef MetaPhysicL::DualNumber<V, D, asd> Nested;

enum
{
IsComplex = 0,
IsInteger = 0,
IsSigned = 1,
RequireInitialization = 1,
ReadCost = HugeCost,
AddCost = HugeCost,
MulCost = HugeCost
};
};

template <typename BinaryOp, typename V, typename D, bool asd>
struct ScalarBinaryOpTraits<Real, MetaPhysicL::DualNumber<V, D, asd>, BinaryOp>
{
typedef MetaPhysicL::DualNumber<V, D, asd> ReturnType;
};
template <typename BinaryOp, typename V, typename D, bool asd>
struct ScalarBinaryOpTraits<MetaPhysicL::DualNumber<V, D, asd>, Real, BinaryOp>
{
typedef MetaPhysicL::DualNumber<V, D, asd> ReturnType;
};
} // namespace Eigen

namespace Moose
{
template <typename T>
struct ADType;

template <typename T, int M, int N, int O, int M2, int N2>
struct ADType<Eigen::Matrix<T, M, N, O, M2, N2>>
{
typedef typename Eigen::Matrix<typename ADType<T>::type, M, N, O, M2, N2> type;
};
}
111 changes: 111 additions & 0 deletions framework/include/utils/EigenADReal.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,118 @@
#pragma once

#include "ADReal.h"
#include "metaphysicl/raw_type.h"

namespace Eigen
{
namespace internal
{
template <typename V, typename D, bool asd>
inline bool
isinf_impl(const MetaPhysicL::DualNumber<V, D, asd> & a)
{
return std::isinf(a);
}

template <typename V, typename D, bool asd>
inline bool
isnan_impl(const MetaPhysicL::DualNumber<V, D, asd> & a)
{
return std::isnan(a);
}

template <typename V, typename D, bool asd>
inline MetaPhysicL::DualNumber<V, D, asd>
sqrt(const MetaPhysicL::DualNumber<V, D, asd> & a)
{
return std::sqrt(a);
}

template <typename V, typename D, bool asd>
inline MetaPhysicL::DualNumber<V, D, asd>
abs(const MetaPhysicL::DualNumber<V, D, asd> & 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 <Eigen/Core>
#include "libmesh/restore_warnings.h"

// Eigen needs this
namespace MetaPhysicL
{
// raw_value AD->non-AD conversion for ADReal valued Eigen::Matrix objects
template <typename T, int M, int N, int O, int M2, int N2>
struct RawType<Eigen::Matrix<T, M, N, O, M2, N2>>
{
typedef Eigen::Matrix<typename RawType<T>::value_type, M, N, O, M2, N2> value_type;

static value_type value(const Eigen::Matrix<T, M, N, O, M2, N2> & 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 <typename T>
auto
raw_value(const Eigen::Map<T> & in)
{
return raw_value(in.eval());
}
} // namespace MetaPhysicL

namespace Eigen
{
// libEigen support for dual number types
template <typename V, typename D, bool asd>
struct NumTraits<MetaPhysicL::DualNumber<V, D, asd>>
: NumTraits<V> // permits to get the epsilon, dummy_precision, lowest, highest functions
{
typedef MetaPhysicL::DualNumber<V, D, asd> Real;
typedef MetaPhysicL::DualNumber<V, D, asd> NonInteger;
typedef MetaPhysicL::DualNumber<V, D, asd> Nested;

enum
{
IsComplex = 0,
IsInteger = 0,
IsSigned = 1,
RequireInitialization = 1,
ReadCost = HugeCost,
AddCost = HugeCost,
MulCost = HugeCost
};
};

template <typename BinaryOp, typename V, typename D, bool asd>
struct ScalarBinaryOpTraits<Real, MetaPhysicL::DualNumber<V, D, asd>, BinaryOp>
{
typedef MetaPhysicL::DualNumber<V, D, asd> ReturnType;
};
template <typename BinaryOp, typename V, typename D, bool asd>
struct ScalarBinaryOpTraits<MetaPhysicL::DualNumber<V, D, asd>, Real, BinaryOp>
{
typedef MetaPhysicL::DualNumber<V, D, asd> ReturnType;
};
} // namespace Eigen

namespace Moose
{
template <typename T>
struct ADType;

template <typename T, int M, int N, int O, int M2, int N2>
struct ADType<Eigen::Matrix<T, M, N, O, M2, N2>>
{
typedef typename Eigen::Matrix<typename ADType<T>::type, M, N, O, M2, N2> type;
};
}

namespace Eigen::internal
{
Expand Down
1 change: 1 addition & 0 deletions framework/include/utils/MooseTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "Moose.h"
#include "ADReal.h"
#include "EigenADReal.h"
#include "ChainedReal.h"
#include "ChainedADReal.h"
#include "ADRankTwoTensorForward.h"
Expand Down
3 changes: 1 addition & 2 deletions framework/include/utils/MooseUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
26 changes: 1 addition & 25 deletions framework/src/actions/MaterialOutputAction.C
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> 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<std::string> MaterialOutputAction::_index_symbols = {
// "", "xyz", "012", "012", "012", "012345", "012345"};

// /// List of coefficient parameter names (one entry for each type in SupportedTypes)
// const std::vector<std::vector<std::string>> 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");

Expand Down Expand Up @@ -338,7 +314,7 @@ MaterialOutputAction::materialOutput(const std::string & property_name,

std::vector<std::string>
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion modules/contact/include/utils/TwoVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#pragma once

#include "ADReal.h"
#include "EigenADReal.h"
#include <Eigen/Dense>

/**
Expand Down
2 changes: 1 addition & 1 deletion unit/src/ADTypesTest.C
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 37fe25d

Please sign in to comment.