Skip to content
Permalink
Browse files

Merge pull request #13026 from aeslaughter/template-rankthree-12599

Template RankThreeTensor for AD
  • Loading branch information...
lindsayad committed Mar 12, 2019
2 parents 89905e9 + a902b6e commit 86b5d3230b29d9bc7edf7478a961aa9a6aed1d9a
@@ -17,6 +17,7 @@
#include "MooseError.h"
#include "Backup.h"
#include "RankTwoTensor.h"
#include "RankThreeTensor.h"
#include "RankFourTensor.h"
#include "MooseADWrapper.h"

@@ -396,6 +397,13 @@ dataStore(std::ostream & stream, RankTwoTensorTempl<T> & rtt, void * context)
dataStore(stream, rtt._coords, context);
}

template <typename T>
void
dataStore(std::ostream & stream, RankThreeTensorTempl<T> & rtt, void * context)
{
dataStore(stream, rtt._vals, context);
}

template <typename T>
void
dataStore(std::ostream & stream, RankFourTensorTempl<T> & rft, void * context)
@@ -636,6 +644,13 @@ dataLoad(std::istream & stream, RankTwoTensorTempl<T> & rtt, void * context)
dataLoad(stream, rtt._coords, context);
}

template <typename T>
void
dataLoad(std::istream & stream, RankThreeTensorTempl<T> & rtt, void * context)
{
dataLoad(stream, rtt._vals, context);
}

template <typename T>
void
dataLoad(std::istream & stream, RankFourTensorTempl<T> & rft, void * context)
@@ -4,6 +4,7 @@
#include "MooseError.h"
#include "DualReal.h"
#include "RankTwoTensor.h"
#include "RankThreeTensor.h"
#include "RankFourTensor.h"

#include "libmesh/vector_value.h"
@@ -236,6 +237,44 @@ class MooseADWrapper<RankTwoTensorTempl<Real>>
void *);
};

template <>
class MooseADWrapper<RankThreeTensorTempl<Real>>
{
public:
MooseADWrapper(bool use_ad = false);
MooseADWrapper(MooseADWrapper<RankThreeTensorTempl<Real>> &&) = default;

typedef RankThreeTensorTempl<DualReal> DNType;

const RankThreeTensorTempl<Real> & value() const { return _val; }

RankThreeTensorTempl<Real> & value() { return _val; }

const RankThreeTensorTempl<DualReal> & dn(bool = true) const;

RankThreeTensorTempl<DualReal> & dn(bool = true);

void copyDualNumberToValue();

void markAD(bool use_ad);

MooseADWrapper<RankThreeTensorTempl<Real>> &
operator=(const MooseADWrapper<RankThreeTensorTempl<Real>> &);
MooseADWrapper<RankThreeTensorTempl<Real>> &
operator=(MooseADWrapper<RankThreeTensorTempl<Real>> &&) = default;

private:
bool _use_ad;
RankThreeTensorTempl<Real> _val;
mutable std::unique_ptr<RankThreeTensorTempl<DualReal>> _dual_number;
friend void dataStore<RankThreeTensorTempl<Real>>(std::ostream &,
MooseADWrapper<RankThreeTensorTempl<Real>> &,
void *);
friend void dataLoad<RankThreeTensorTempl<Real>>(std::istream &,
MooseADWrapper<RankThreeTensorTempl<Real>> &,
void *);
};

template <>
class MooseADWrapper<RankFourTensorTempl<Real>>
{
@@ -34,10 +34,8 @@ class VectorValue;
class MooseEnum;
template <typename>
class RankTwoTensorTempl;
typedef RankTwoTensorTempl<Real> RankTwoTensor;
template <typename>
class RankFourTensorTempl;
typedef RankFourTensorTempl<Real> RankFourTensor;

template <typename T>
void mooseSetToZero(T & v);
@@ -412,9 +410,13 @@ class RankFourTensorTempl
friend class RankTwoTensorTempl;
template <typename T2>
friend class RankFourTensorTempl;
friend class RankThreeTensor;
template <typename T2>
friend class RankThreeTensorTempl;
};

typedef RankFourTensorTempl<Real> RankFourTensor;
typedef RankFourTensorTempl<DualReal> DualRankFourTensor;

template <typename T1, typename T2>
inline auto operator*(const T1 & a, const RankFourTensorTempl<T2> & b) ->
typename std::enable_if<ScalarTraits<T1>::value,
Oops, something went wrong.

0 comments on commit 86b5d32

Please sign in to comment.
You can’t perform that action at this time.