www.mooseframework.org
Public Types | Public Member Functions | Private Attributes | Friends | List of all members
MooseADWrapper< T > Class Template Reference

#include <MooseADWrapper.h>

Public Types

typedef T DNType
 

Public Member Functions

 MooseADWrapper (bool=false)
 
 MooseADWrapper (MooseADWrapper< T > &&)=default
 
MooseADWrapper< T > & operator= (const MooseADWrapper< T > &rhs)
 
MooseADWrapper< T > & operator= (MooseADWrapper< T > &&)=default
 
const T & value () const
 Returns the value for any case where a MaterialProperty is requested as a regular (non-AD) property. More...
 
T & value ()
 Returns the value for any case where a MaterialProperty is declared as a regular (non-AD) property (used only during material calculations) More...
 
const T & dn (bool requested_by_user=true) const
 Returns the dual number for any case where a MaterialProperty is requested as a AD property. More...
 
T & dn (bool requested_by_user=true)
 Returns the value for any case where a MaterialProperty is declared as an AD property (used only during material calculations) More...
 
void copyDualNumberToValue ()
 Used during Jacobian calculations in case a property was declared as AD but a consuming object has requested it as a regular property. More...
 
void markAD (bool)
 Mark a change in whether to use AD or not. More...
 

Private Attributes

_val
 
std::unique_ptr< T > _dual_number
 

Friends

void dataStore (std::ostream &, MooseADWrapper< T > &, void *)
 
void dataLoad (std::istream &, MooseADWrapper< T > &, void *)
 

Detailed Description

template<typename T>
class MooseADWrapper< T >

Definition at line 19 of file MooseADWrapper.h.

Member Typedef Documentation

◆ DNType

template<typename T>
typedef T MooseADWrapper< T >::DNType

Definition at line 40 of file MooseADWrapper.h.

Constructor & Destructor Documentation

◆ MooseADWrapper() [1/2]

template<typename T>
MooseADWrapper< T >::MooseADWrapper ( bool  = false)
inline

Definition at line 30 of file MooseADWrapper.h.

30 : _val(), _dual_number(nullptr) {}
std::unique_ptr< T > _dual_number

◆ MooseADWrapper() [2/2]

template<typename T>
MooseADWrapper< T >::MooseADWrapper ( MooseADWrapper< T > &&  )
default

Member Function Documentation

◆ copyDualNumberToValue()

template<typename T>
void MooseADWrapper< T >::copyDualNumberToValue ( )
inline

Used during Jacobian calculations in case a property was declared as AD but a consuming object has requested it as a regular property.

Definition at line 85 of file MooseADWrapper.h.

85 {}

◆ dn() [1/2]

template<typename T>
const T& MooseADWrapper< T >::dn ( bool  requested_by_user = true) const
inline

Returns the dual number for any case where a MaterialProperty is requested as a AD property.

Definition at line 57 of file MooseADWrapper.h.

58  {
59  if (requested_by_user)
60  mooseError("Type ",
61  typeid(T).name(),
62  " does not currently support automatic differentiation. Consider using a regular "
63  "material property (declareProperty, getMaterialProperty) instead.");
64  return _val;
65  }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:208

◆ dn() [2/2]

template<typename T>
T& MooseADWrapper< T >::dn ( bool  requested_by_user = true)
inline

Returns the value for any case where a MaterialProperty is declared as an AD property (used only during material calculations)

Definition at line 71 of file MooseADWrapper.h.

72  {
73  if (requested_by_user)
74  mooseError("Type ",
75  typeid(T).name(),
76  " does not currently support automatic differentiation. Consider using a regular "
77  "material property (declareProperty, getMaterialProperty) instead.");
78  return _val;
79  }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:208

◆ markAD()

template<typename T>
void MooseADWrapper< T >::markAD ( bool  )
inline

Mark a change in whether to use AD or not.

This is relevant during stateful material calculations. E.g. when a current property becomes old we call markAD(false) and when we swap an old material property to the current property (see MaterialPropertyStorage::shift) we call markAD(true)

Definition at line 93 of file MooseADWrapper.h.

93 {}

◆ operator=() [1/2]

template<typename T>
MooseADWrapper<T>& MooseADWrapper< T >::operator= ( const MooseADWrapper< T > &  rhs)
inline

Definition at line 33 of file MooseADWrapper.h.

34  {
35  _val = rhs._val;
36  return *this;
37  }

◆ operator=() [2/2]

template<typename T>
MooseADWrapper<T>& MooseADWrapper< T >::operator= ( MooseADWrapper< T > &&  )
default

◆ value() [1/2]

template<typename T>
const T& MooseADWrapper< T >::value ( ) const
inline

Returns the value for any case where a MaterialProperty is requested as a regular (non-AD) property.

Definition at line 46 of file MooseADWrapper.h.

Referenced by dataLoad(), and dataStore().

46 { return _val; }

◆ value() [2/2]

template<typename T>
T& MooseADWrapper< T >::value ( )
inline

Returns the value for any case where a MaterialProperty is declared as a regular (non-AD) property (used only during material calculations)

Definition at line 52 of file MooseADWrapper.h.

52 { return _val; }

Friends And Related Function Documentation

◆ dataLoad

template<typename T>
void dataLoad ( std::istream &  ,
MooseADWrapper< T > &  ,
void *   
)
friend

Definition at line 663 of file DataIO.h.

664 {
665  dataLoad(stream, dn_wrapper.value(), context);
666  unsigned int n = 0;
667  stream.read((char *)&n, sizeof(n));
668  if (n)
669  {
670  dn_wrapper._dual_number = libmesh_make_unique<typename MooseADWrapper<T>::DNType>();
671  dataLoad(stream, *dn_wrapper._dual_number, context);
672  }
673 }
const T & value() const
Returns the value for any case where a MaterialProperty is requested as a regular (non-AD) property...
friend void dataLoad(std::istream &, MooseADWrapper< T > &, void *)
Definition: DataIO.h:663
PetscInt n
std::unique_ptr< T > _dual_number

◆ dataStore

template<typename T>
void dataStore ( std::ostream &  ,
MooseADWrapper< T > &  ,
void *   
)
friend

Definition at line 416 of file DataIO.h.

417 {
418  dataStore(stream, dn_wrapper.value(), context);
419  if (dn_wrapper._dual_number)
420  {
421  unsigned int m = 1;
422  stream.write((char *)&m, sizeof(m));
423  dataStore(stream, *dn_wrapper._dual_number, context);
424  }
425  else
426  {
427  unsigned int m = 0;
428  stream.write((char *)&m, sizeof(m));
429  }
430 }
PetscInt m
const T & value() const
Returns the value for any case where a MaterialProperty is requested as a regular (non-AD) property...
friend void dataStore(std::ostream &, MooseADWrapper< T > &, void *)
Definition: DataIO.h:416
std::unique_ptr< T > _dual_number

Member Data Documentation

◆ _dual_number

template<typename T>
std::unique_ptr<T> MooseADWrapper< T >::_dual_number
mutableprivate

◆ _val

template<typename T>
T MooseADWrapper< T >::_val
private

The documentation for this class was generated from the following file: