Skip to content

Commit

Permalink
NEML2 submodule update
Browse files Browse the repository at this point in the history
- Update neml2 submodule
- Remove dependency on LabeledTensor
- Update all neml2 models
- Update all moose-neml2 input files
- Attempted to speedup data transfer between moose and neml2
- Make moose data types trivially copyable
- Add a neml2 crystal plasticity example
- Add ability to initialize neml2 variables in neml2 action

ref idaholab#29579
  • Loading branch information
hugary1995 committed Dec 22, 2024
1 parent dc0e9c8 commit 1585b08
Show file tree
Hide file tree
Showing 57 changed files with 1,209 additions and 682 deletions.
34 changes: 34 additions & 0 deletions framework/include/materials/GenericConstantRealVectorValue.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//* 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 "Material.h"

/**
* Declares a constant material property of type RealVectorValue.
*/
template <bool is_ad>
class GenericConstantRealVectorValueTempl : public Material
{
public:
static InputParameters validParams();

GenericConstantRealVectorValueTempl(const InputParameters & parameters);

protected:
virtual void initQpStatefulProperties() override;
virtual void computeQpProperties() override;

const RealVectorValue _vector;
GenericMaterialProperty<RealVectorValue, is_ad> & _prop;
};

typedef GenericConstantRealVectorValueTempl<false> GenericConstantRealVectorValue;
typedef GenericConstantRealVectorValueTempl<true> ADGenericConstantRealVectorValue;
3 changes: 3 additions & 0 deletions framework/include/utils/MooseArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,13 @@ class MooseArray
*/
std::vector<T> stdVector() const;

///@{
/**
* Reference to first element of array
*/
const T * data() const { return _data; }
T * data() { return _data; }
///@}

private:
/// Smart pointer storage
Expand Down
2 changes: 1 addition & 1 deletion framework/include/utils/RankFourTensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ class RankFourTensorTempl
void printReal(std::ostream & stm = Moose::out) const;

/// copies values from a into this tensor
RankFourTensorTempl<T> & operator=(const RankFourTensorTempl<T> & a);
RankFourTensorTempl<T> & operator=(const RankFourTensorTempl<T> & a) = default;

/**
* Assignment-from-scalar operator. Used only to zero out the tensor.
Expand Down
9 changes: 0 additions & 9 deletions framework/include/utils/RankFourTensorImplementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,6 @@ RankFourTensorTempl<T>::zero()
_vals[i] = 0.0;
}

template <typename T>
RankFourTensorTempl<T> &
RankFourTensorTempl<T>::operator=(const RankFourTensorTempl<T> & a)
{
for (auto i : make_range(N4))
_vals[i] = a._vals[i];
return *this;
}

template <typename T>
template <template <typename> class Tensor, typename T2>
auto
Expand Down
2 changes: 1 addition & 1 deletion framework/include/utils/RankTwoTensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ class RankTwoTensorTempl : public libMesh::TensorValue<T>
* // 7 4 1 ]
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
RankTwoTensorTempl<T> & operator=(const RankTwoTensorTempl<T> & a);
RankTwoTensorTempl<T> & operator=(const RankTwoTensorTempl<T> & a) = default;

/**
* @brief Assignment operator (from a ColumnMajorMatrixTempl<T>)
Expand Down
8 changes: 0 additions & 8 deletions framework/include/utils/RankTwoTensorImplementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -369,14 +369,6 @@ RankTwoTensorTempl<T>::transpose() const
return libMesh::TensorValue<T>::transpose();
}

template <typename T>
RankTwoTensorTempl<T> &
RankTwoTensorTempl<T>::operator=(const RankTwoTensorTempl<T> & a)
{
libMesh::TensorValue<T>::operator=(a);
return *this;
}

template <typename T>
RankTwoTensorTempl<T> &
RankTwoTensorTempl<T>::operator+=(const RankTwoTensorTempl<T> & a)
Expand Down
2 changes: 1 addition & 1 deletion framework/include/utils/SymmetricRankFourTensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class SymmetricRankFourTensorTempl
void printReal(std::ostream & stm = Moose::out) const;

/// copies values from a into this tensor
SymmetricRankFourTensorTempl<T> & operator=(const SymmetricRankFourTensorTempl<T> & a);
SymmetricRankFourTensorTempl<T> & operator=(const SymmetricRankFourTensorTempl<T> & a) = default;

/**
* Assignment-from-scalar operator. Used only to zero out the tensor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,6 @@ SymmetricRankFourTensorTempl<T>::rotate(const TypeTensor<T> & R)
(*this) = M * (*this) * M.transposeMajor();
}

template <typename T>
SymmetricRankFourTensorTempl<T> &
SymmetricRankFourTensorTempl<T>::operator=(const SymmetricRankFourTensorTempl<T> & a)
{
std::copy(a._vals.begin(), a._vals.end(), _vals.begin());
return *this;
}

template <typename T>
SymmetricRankFourTensorTempl<T> &
SymmetricRankFourTensorTempl<T>::operator*=(const T & a)
Expand Down
53 changes: 53 additions & 0 deletions framework/src/materials/GenericConstantRealVectorValue.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//* 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

#include "GenericConstantRealVectorValue.h"

registerMooseObject("MooseApp", GenericConstantRealVectorValue);
registerMooseObject("MooseApp", ADGenericConstantRealVectorValue);

template <bool is_ad>
InputParameters
GenericConstantRealVectorValueTempl<is_ad>::validParams()
{
InputParameters params = Material::validParams();
params.addClassDescription("Object for declaring a constant 3-vector as a material property.");
params.addRequiredParam<RealVectorValue>("vector_values", "Values defining the constant vector");
params.addRequiredParam<MaterialPropertyName>(
"vector_name", "Name of the vector material property to be created");
params.set<MooseEnum>("constant_on") = "SUBDOMAIN";
return params;
}

template <bool is_ad>
GenericConstantRealVectorValueTempl<is_ad>::GenericConstantRealVectorValueTempl(
const InputParameters & parameters)
: Material(parameters),
_vector(getParam<RealVectorValue>("vector_values")),
_prop(declareGenericProperty<RealVectorValue, is_ad>(
getParam<MaterialPropertyName>("vector_name")))
{
}

template <bool is_ad>
void
GenericConstantRealVectorValueTempl<is_ad>::initQpStatefulProperties()
{
GenericConstantRealVectorValueTempl<is_ad>::computeQpProperties();
}

template <bool is_ad>
void
GenericConstantRealVectorValueTempl<is_ad>::computeQpProperties()
{
_prop[_qp] = _vector;
}

template class GenericConstantRealVectorValueTempl<false>;
template class GenericConstantRealVectorValueTempl<true>;
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[Models]
[adjoint_elasticity_model]
type = LinearIsotropicElasticity
youngs_modulus = 5.0
poisson_ratio = 0.3
coefficients = '5.0 0.3'
coefficient_types = 'YOUNGS_MODULUS POISSONS_RATIO'
strain = 'forces/E'
[]
[forward_elasticity_model]
type = LinearIsotropicElasticity
youngs_modulus = 5.0
poisson_ratio = 0.3
coefficients = '5.0 0.3'
coefficient_types = 'YOUNGS_MODULUS POISSONS_RATIO'
strain = 'forces/E'
[]
[]
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
verbose = true
device = 'cpu'
[forward]
enable_AD = true
model = 'forward_elasticity_model'

moose_input_types = 'MATERIAL'
Expand Down
2 changes: 1 addition & 1 deletion modules/solid_mechanics/contrib/neml2
Submodule neml2 updated 645 files
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//* 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 "ComputeLagrangianStressCauchy.h"
#include "DerivativeMaterialPropertyNameInterface.h"

/// Provide the Cauchy stress and jacobian directly
///
class ComputeLagrangianCauchyCustomStress : public ComputeLagrangianStressCauchy,
public DerivativeMaterialPropertyNameInterface
{
public:
static InputParameters validParams();
ComputeLagrangianCauchyCustomStress(const InputParameters & parameters);

protected:
/// Implement the copy
virtual void computeQpCauchyStress() override;

const MaterialProperty<RankTwoTensor> & _custom_stress;
const MaterialProperty<RankFourTensor> & _custom_jacobian;
};
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ class ComputeLagrangianStrainBase : public Material, public G
/// Strain increment
MaterialProperty<RankTwoTensor> & _strain_increment;

/// Spatial velocity gradient increment
MaterialProperty<RankTwoTensor> & _spatial_velocity_increment;

/// Vorticity increment
MaterialProperty<RankTwoTensor> & _vorticity_increment;

Expand Down
33 changes: 33 additions & 0 deletions modules/solid_mechanics/include/neml2/actions/NEML2Action.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

#include "Action.h"

class NEML2ActionCommon;

/**
* Action to set up NEML2 objects.
*/
Expand All @@ -28,6 +30,8 @@ class NEML2Action : public Action
virtual void act() override;

protected:
const NEML2ActionCommon & getCommonAction() const;

#ifdef NEML2_ENABLED

enum class MOOSEIOType
Expand Down Expand Up @@ -130,6 +134,35 @@ class NEML2Action : public Action
/// Blocks this sub-block action applies to
const std::vector<SubdomainName> _block;

/// Material property initial conditions
std::map<MaterialPropertyName, MaterialPropertyName> _initialize_output_values;

/// Material property additional outputs
std::map<MaterialPropertyName, std::vector<OutputName>> _export_output_targets;

private:
/// Get parameter lists for mapping between MOOSE and NEML2 quantities
template <typename EnumType, typename T1, typename T2>
std::tuple<std::vector<EnumType>, std::vector<T1>, std::vector<T2>>
getInputParameterMapping(const std::string & moose_type_opt,
const std::string & moose_name_opt,
const std::string & neml2_name_opt) const
{
const auto moose_types = getParam<MultiMooseEnum>(moose_type_opt).getSetValueIDs<EnumType>();
const auto moose_names = getParam<std::vector<T1>>(moose_name_opt);
const auto neml2_names = getParam<std::vector<T2>>(neml2_name_opt);

if (moose_types.size() != moose_names.size())
paramError(moose_name_opt, moose_name_opt, " must have the same length as ", moose_type_opt);
if (moose_names.size() != neml2_names.size())
paramError(moose_name_opt, moose_name_opt, " must have the same length as ", neml2_name_opt);

return {moose_types, moose_names, neml2_names};
}

/// Print a summary of the NEML2 model
void printSummary(const neml2::Model &) const;

/// Get the maximum length of all MOOSE names (for printing purposes)
std::size_t getLongestMOOSEName() const;
};
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,19 @@ class NEML2ActionCommon : public Action
/// Parameters that can be specified EITHER under the common area OR under sub-blocks
static InputParameters commonParams();

/// Parameters that can ONLY be specified under the common area
static InputParameters validParams();

NEML2ActionCommon(const InputParameters &);

virtual void act() override;

const FileName & fname() const { return _fname; }

protected:
/// Name of the NEML2 input file
const FileName _fname;

/// List of cli-args
const std::vector<std::string> _cli_args;
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "InputParameters.h"

#ifdef NEML2_ENABLED
#include "neml2/tensors/LabeledVector.h"
#include "neml2/models/Model.h"
#endif

Expand Down Expand Up @@ -70,7 +69,7 @@ class MOOSEToNEML2
virtual neml2::Tensor gatheredData() const = 0;

/// Insert the gathered data into the NEML2 material model
void insertInto(neml2::Model &) const;
void insertInto(neml2::ValueMap &, std::map<std::string, neml2::Tensor> &) const;

protected:
/// Whether we should insert into NEML2 input variable or NEML2 model parameter
Expand Down
Loading

0 comments on commit 1585b08

Please sign in to comment.