Skip to content

Commit

Permalink
Simplify AD headers and remove DualReal from the repo
Browse files Browse the repository at this point in the history
  • Loading branch information
lindsayad committed May 8, 2024
1 parent 82d4457 commit a09bb7d
Show file tree
Hide file tree
Showing 139 changed files with 1,001 additions and 1,111 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# DualReal
# ADReal

`DualReal` is the type underpinning all of MOOSE's automatic differentiation (AD)
`ADReal` is the type underpinning all of MOOSE's automatic differentiation (AD)
capabilities.

[#overview]
[#timings]

## Overview id=overview

`DualReal` is a MOOSE typedef defined from the
`ADReal` is a MOOSE typedef defined from the
[MetaPhysicL](https://github.com/libMesh/MetaPhysicL) template class
`DualNumber`. `DualNumber` takes two template arguments `T` and `D`; `T`
represents the "value" type of the `DualNumber`, e.g. the type of $f(\vec{x})$,
Expand Down
2 changes: 1 addition & 1 deletion framework/doc/content/source/utils/MooseTypes.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ differentiation in MOOSE. It defines the following macros:
- `ADRankTwoTensor`
- `ADRankFourTensor`

which resolve to either `Real` or [`DualReal`](/DualReal.md) based objects
which resolve to either `Real` or [`ADReal`](/ADReal.md) based objects
depending on whether `compute_stage` is equivalent to `RESIDUAL` or
`JACOBIAN`. `compute_stage` is a template argument to AD consuming and producing
objects like `ADKernel` and `ADMaterial` respectively.
50 changes: 24 additions & 26 deletions framework/include/base/Assembly.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
#include "libmesh/numeric_vector.h"
#include "libmesh/elem_side_builder.h"

#include "DualRealOps.h"

#include <unordered_map>

// libMesh forward declarations
Expand Down Expand Up @@ -2376,7 +2374,7 @@ class Assembly
/// The current coordinate transformation coefficients
MooseArray<Real> _coord;
/// The AD version of the current coordinate transformation coefficients
MooseArray<DualReal> _ad_coord;
MooseArray<ADReal> _ad_coord;

/// Data structure for tracking/grouping a set of quadrature rules for a
/// particular dimensionality of mesh element.
Expand Down Expand Up @@ -2777,30 +2775,30 @@ class Assembly
std::vector<Point> _temp_reference_points;

/// AD quantities
std::vector<VectorValue<DualReal>> _ad_dxyzdxi_map;
std::vector<VectorValue<DualReal>> _ad_dxyzdeta_map;
std::vector<VectorValue<DualReal>> _ad_dxyzdzeta_map;
std::vector<VectorValue<DualReal>> _ad_d2xyzdxi2_map;
std::vector<VectorValue<DualReal>> _ad_d2xyzdxideta_map;
std::vector<VectorValue<DualReal>> _ad_d2xyzdeta2_map;
std::vector<DualReal> _ad_jac;
MooseArray<DualReal> _ad_JxW;
MooseArray<VectorValue<DualReal>> _ad_q_points;
std::vector<DualReal> _ad_dxidx_map;
std::vector<DualReal> _ad_dxidy_map;
std::vector<DualReal> _ad_dxidz_map;
std::vector<DualReal> _ad_detadx_map;
std::vector<DualReal> _ad_detady_map;
std::vector<DualReal> _ad_detadz_map;
std::vector<DualReal> _ad_dzetadx_map;
std::vector<DualReal> _ad_dzetady_map;
std::vector<DualReal> _ad_dzetadz_map;

MooseArray<DualReal> _ad_JxW_face;
MooseArray<VectorValue<DualReal>> _ad_normals;
MooseArray<VectorValue<DualReal>> _ad_q_points_face;
std::vector<VectorValue<ADReal>> _ad_dxyzdxi_map;
std::vector<VectorValue<ADReal>> _ad_dxyzdeta_map;
std::vector<VectorValue<ADReal>> _ad_dxyzdzeta_map;
std::vector<VectorValue<ADReal>> _ad_d2xyzdxi2_map;
std::vector<VectorValue<ADReal>> _ad_d2xyzdxideta_map;
std::vector<VectorValue<ADReal>> _ad_d2xyzdeta2_map;
std::vector<ADReal> _ad_jac;
MooseArray<ADReal> _ad_JxW;
MooseArray<VectorValue<ADReal>> _ad_q_points;
std::vector<ADReal> _ad_dxidx_map;
std::vector<ADReal> _ad_dxidy_map;
std::vector<ADReal> _ad_dxidz_map;
std::vector<ADReal> _ad_detadx_map;
std::vector<ADReal> _ad_detady_map;
std::vector<ADReal> _ad_detadz_map;
std::vector<ADReal> _ad_dzetadx_map;
std::vector<ADReal> _ad_dzetady_map;
std::vector<ADReal> _ad_dzetadz_map;

MooseArray<ADReal> _ad_JxW_face;
MooseArray<VectorValue<ADReal>> _ad_normals;
MooseArray<VectorValue<ADReal>> _ad_q_points_face;
MooseArray<Real> _curvatures;
MooseArray<DualReal> _ad_curvatures;
MooseArray<ADReal> _ad_curvatures;

/**
* Container of displacement numbers and directions
Expand Down
2 changes: 0 additions & 2 deletions framework/include/dgkernels/ADDGKernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

#include "DGKernelBase.h"

#include "DualRealOps.h"

class ADDGKernel : public DGKernelBase, public NeighborMooseVariableInterface<Real>
{
public:
Expand Down
4 changes: 2 additions & 2 deletions framework/include/interfaces/Coupleable.h
Original file line number Diff line number Diff line change
Expand Up @@ -1395,7 +1395,7 @@ class Coupleable
_default_value;

/// Will hold the default value for optional coupled variables for automatic differentiation.
mutable std::unordered_map<std::string, std::unique_ptr<MooseArray<DualReal>>> _ad_default_value;
mutable std::unordered_map<std::string, std::unique_ptr<MooseArray<ADReal>>> _ad_default_value;

/// Will hold the default value for optional vector coupled variables.
mutable std::unordered_map<std::string, std::unique_ptr<VectorVariableValue>>
Expand Down Expand Up @@ -1432,7 +1432,7 @@ class Coupleable
/// Zero value of a variable
const VariableValue & _zero;
const VariablePhiValue & _phi_zero;
const MooseArray<DualReal> & _ad_zero;
const MooseArray<ADReal> & _ad_zero;

/// Zero gradient of a variable
const VariableGradient & _grad_zero;
Expand Down
1 change: 0 additions & 1 deletion framework/include/kernels/ADKernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

#include "KernelBase.h"
#include "ADFunctorInterface.h"
#include "DualRealOps.h"

// forward declarations
template <typename>
Expand Down
14 changes: 7 additions & 7 deletions framework/include/restart/DataIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#pragma once

// MOOSE includes
#include "DualReal.h"
#include "ADReal.h"
#include "MooseTypes.h"
#include "HashMap.h"
#include "MooseError.h"
Expand Down Expand Up @@ -397,7 +397,7 @@ void dataStore(std::ostream & stream, Node *& n, void * context);
template <>
void dataStore(std::ostream & stream, std::stringstream & s, void * context);
template <>
void dataStore(std::ostream & stream, DualReal & dn, void * context);
void dataStore(std::ostream & stream, ADReal & dn, void * context);
template <>
void dataStore(std::ostream & stream, RealEigenVector & v, void * context);
template <>
Expand All @@ -421,15 +421,15 @@ void dataStore(std::ostream & stream,

template <std::size_t N>
inline void
dataStore(std::ostream & stream, std::array<DualReal, N> & dn, void * context)
dataStore(std::ostream & stream, std::array<ADReal, N> & dn, void * context)
{
for (std::size_t i = 0; i < N; ++i)
dataStore(stream, dn[i], context);
}

template <std::size_t N>
inline void
dataStore(std::ostream & stream, DualReal (&dn)[N], void * context)
dataStore(std::ostream & stream, ADReal (&dn)[N], void * context)
{
for (std::size_t i = 0; i < N; ++i)
dataStore(stream, dn[i], context);
Expand Down Expand Up @@ -722,7 +722,7 @@ void dataLoad(std::istream & stream, Node *& e, void * context);
template <>
void dataLoad(std::istream & stream, std::stringstream & s, void * context);
template <>
void dataLoad(std::istream & stream, DualReal & dn, void * context);
void dataLoad(std::istream & stream, ADReal & dn, void * context);
template <>
void dataLoad(std::istream & stream, RealEigenVector & v, void * context);
template <>
Expand Down Expand Up @@ -753,15 +753,15 @@ void dataLoad(std::istream & stream,

template <std::size_t N>
inline void
dataLoad(std::istream & stream, std::array<DualReal, N> & dn, void * context)
dataLoad(std::istream & stream, std::array<ADReal, N> & dn, void * context)
{
for (std::size_t i = 0; i < N; ++i)
dataLoad(stream, dn[i], context);
}

template <std::size_t N>
inline void
dataLoad(std::istream & stream, DualReal (&dn)[N], void * context)
dataLoad(std::istream & stream, ADReal (&dn)[N], void * context)
{
for (std::size_t i = 0; i < N; ++i)
dataLoad(stream, dn[i], context);
Expand Down
4 changes: 2 additions & 2 deletions framework/include/timeintegrators/AStableDirk4.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ class AStableDirk4 : public TimeIntegrator

virtual int order() override { return 4; }
virtual void computeTimeDerivatives() override;
void computeADTimeDerivatives(DualReal & ad_u_dot,
void computeADTimeDerivatives(ADReal & ad_u_dot,
const dof_id_type & dof,
DualReal & ad_u_dotdot) const override;
ADReal & ad_u_dotdot) const override;
virtual void solve() override;
virtual void postResidual(NumericVector<Number> & residual) override;

Expand Down
4 changes: 2 additions & 2 deletions framework/include/timeintegrators/ActuallyExplicitEuler.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class ActuallyExplicitEuler : public ExplicitTimeIntegrator

virtual int order() override { return 1; }
virtual void computeTimeDerivatives() override;
void computeADTimeDerivatives(DualReal & ad_u_dot,
void computeADTimeDerivatives(ADReal & ad_u_dot,
const dof_id_type & dof,
DualReal & ad_u_dotdot) const override;
ADReal & ad_u_dotdot) const override;
virtual void solve() override;
virtual void postResidual(NumericVector<Number> & residual) override;

Expand Down
4 changes: 2 additions & 2 deletions framework/include/timeintegrators/BDF2.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ class BDF2 : public TimeIntegrator
virtual int order() override { return 2; }
virtual void preStep() override;
virtual void computeTimeDerivatives() override;
void computeADTimeDerivatives(DualReal & ad_u_dot,
void computeADTimeDerivatives(ADReal & ad_u_dot,
const dof_id_type & dof,
DualReal & ad_u_dotdot) const override;
ADReal & ad_u_dotdot) const override;
virtual void postResidual(NumericVector<Number> & residual) override;

protected:
Expand Down
4 changes: 2 additions & 2 deletions framework/include/timeintegrators/CentralDifference.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ class CentralDifference : public ActuallyExplicitEuler

virtual int order() override { return 2; }
virtual void computeTimeDerivatives() override;
void computeADTimeDerivatives(DualReal & ad_u_dot,
void computeADTimeDerivatives(ADReal & ad_u_dot,
const dof_id_type & dof,
DualReal & ad_u_dotdot) const override;
ADReal & ad_u_dotdot) const override;

protected:
/// solution vector for \f$ {du^dotdot}\over{du} \f$
Expand Down
4 changes: 2 additions & 2 deletions framework/include/timeintegrators/CrankNicolson.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ class CrankNicolson : public TimeIntegrator
virtual void init() override;
virtual int order() override { return 2; }
virtual void computeTimeDerivatives() override;
void computeADTimeDerivatives(DualReal & ad_u_dot,
void computeADTimeDerivatives(ADReal & ad_u_dot,
const dof_id_type & dof,
DualReal & ad_u_dotdot) const override;
ADReal & ad_u_dotdot) const override;
virtual void postResidual(NumericVector<Number> & residual) override;
virtual void postStep() override;

Expand Down
4 changes: 2 additions & 2 deletions framework/include/timeintegrators/ExplicitEuler.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class ExplicitEuler : public TimeIntegrator
virtual void preSolve() override;
virtual int order() override { return 1; }
virtual void computeTimeDerivatives() override;
void computeADTimeDerivatives(DualReal & ad_u_dot,
void computeADTimeDerivatives(ADReal & ad_u_dot,
const dof_id_type & dof,
DualReal & ad_u_dotdot) const override;
ADReal & ad_u_dotdot) const override;
virtual void postResidual(NumericVector<Number> & residual) override;

protected:
Expand Down
4 changes: 2 additions & 2 deletions framework/include/timeintegrators/ExplicitRK2.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ class ExplicitRK2 : public TimeIntegrator
virtual int order() override { return 2; }

virtual void computeTimeDerivatives() override;
void computeADTimeDerivatives(DualReal & ad_u_dot,
void computeADTimeDerivatives(ADReal & ad_u_dot,
const dof_id_type & dof,
DualReal & ad_u_dotdot) const override;
ADReal & ad_u_dotdot) const override;
virtual void solve() override;
virtual void postResidual(NumericVector<Number> & residual) override;

Expand Down
4 changes: 2 additions & 2 deletions framework/include/timeintegrators/ExplicitSSPRungeKutta.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ class ExplicitSSPRungeKutta : public ExplicitTimeIntegrator
ExplicitSSPRungeKutta(const InputParameters & parameters);

virtual void computeTimeDerivatives() override;
virtual void computeADTimeDerivatives(DualReal & ad_u_dot,
virtual void computeADTimeDerivatives(ADReal & ad_u_dot,
const dof_id_type & dof,
DualReal & ad_u_dotdot) const override;
ADReal & ad_u_dotdot) const override;
virtual void solve() override;
virtual void postResidual(NumericVector<Number> & residual) override;
virtual int order() override { return _order; }
Expand Down
4 changes: 2 additions & 2 deletions framework/include/timeintegrators/ExplicitTVDRK2.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ class ExplicitTVDRK2 : public TimeIntegrator
virtual int order() override { return 2; }

virtual void computeTimeDerivatives() override;
void computeADTimeDerivatives(DualReal & ad_u_dot,
void computeADTimeDerivatives(ADReal & ad_u_dot,
const dof_id_type & dof,
DualReal & ad_u_dotdot) const override;
ADReal & ad_u_dotdot) const override;
virtual void solve() override;
virtual void postResidual(NumericVector<Number> & residual) override;

Expand Down
4 changes: 2 additions & 2 deletions framework/include/timeintegrators/ImplicitEuler.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class ImplicitEuler : public TimeIntegrator

virtual int order() override { return 1; }
virtual void computeTimeDerivatives() override;
void computeADTimeDerivatives(DualReal & ad_u_dot,
void computeADTimeDerivatives(ADReal & ad_u_dot,
const dof_id_type & dof,
DualReal & ad_u_dotdot) const override;
ADReal & ad_u_dotdot) const override;
virtual void postResidual(NumericVector<Number> & residual) override;

protected:
Expand Down
4 changes: 2 additions & 2 deletions framework/include/timeintegrators/ImplicitMidpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ class ImplicitMidpoint : public TimeIntegrator
virtual int order() override { return 2; }

virtual void computeTimeDerivatives() override;
void computeADTimeDerivatives(DualReal & ad_u_dot,
void computeADTimeDerivatives(ADReal & ad_u_dot,
const dof_id_type & dof,
DualReal & ad_u_dotdot) const override;
ADReal & ad_u_dotdot) const override;
virtual void solve() override;
virtual void postResidual(NumericVector<Number> & residual) override;

Expand Down
4 changes: 2 additions & 2 deletions framework/include/timeintegrators/LStableDirk2.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ class LStableDirk2 : public TimeIntegrator

virtual int order() override { return 2; }
virtual void computeTimeDerivatives() override;
void computeADTimeDerivatives(DualReal & ad_u_dot,
void computeADTimeDerivatives(ADReal & ad_u_dot,
const dof_id_type & dof,
DualReal & ad_u_dotdot) const override;
ADReal & ad_u_dotdot) const override;
virtual void solve() override;
virtual void postResidual(NumericVector<Number> & residual) override;

Expand Down
4 changes: 2 additions & 2 deletions framework/include/timeintegrators/LStableDirk3.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ class LStableDirk3 : public TimeIntegrator

virtual int order() override { return 3; }
virtual void computeTimeDerivatives() override;
virtual void computeADTimeDerivatives(DualReal & ad_u_dot,
virtual void computeADTimeDerivatives(ADReal & ad_u_dot,
const dof_id_type & dof,
DualReal & ad_u_dotdot) const override;
ADReal & ad_u_dotdot) const override;
virtual void solve() override;
virtual void postResidual(NumericVector<Number> & residual) override;

Expand Down
4 changes: 2 additions & 2 deletions framework/include/timeintegrators/LStableDirk4.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ class LStableDirk4 : public TimeIntegrator

virtual int order() override { return 4; }
virtual void computeTimeDerivatives() override;
virtual void computeADTimeDerivatives(DualReal & ad_u_dot,
virtual void computeADTimeDerivatives(ADReal & ad_u_dot,
const dof_id_type & dof,
DualReal & ad_u_dotdot) const override;
ADReal & ad_u_dotdot) const override;
virtual void solve() override;
virtual void postResidual(NumericVector<Number> & residual) override;

Expand Down
4 changes: 2 additions & 2 deletions framework/include/timeintegrators/NewmarkBeta.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ class NewmarkBeta : public TimeIntegrator

virtual int order() override { return 1; }
virtual void computeTimeDerivatives() override;
virtual void computeADTimeDerivatives(DualReal & ad_u_dot,
virtual void computeADTimeDerivatives(ADReal & ad_u_dot,
const dof_id_type & dof,
DualReal & ad_u_dotdot) const override;
ADReal & ad_u_dotdot) const override;
virtual void postResidual(NumericVector<Number> & residual) override;

protected:
Expand Down
4 changes: 2 additions & 2 deletions framework/include/timeintegrators/TimeIntegrator.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ class TimeIntegrator : public MooseObject, public Restartable
/**
* method for computing local automatic differentiation time derivatives
*/
virtual void computeADTimeDerivatives(DualReal & ad_u_dot,
virtual void computeADTimeDerivatives(ADReal & ad_u_dot,
const dof_id_type & dof,
DualReal & ad_u_dot_dot) const = 0;
ADReal & ad_u_dot_dot) const = 0;

/**
* Gets the total number of nonlinear iterations over all stages of the time step.
Expand Down
Loading

0 comments on commit a09bb7d

Please sign in to comment.