Reference documentation for deal.II version 9.6.0
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
Differentiation::AD::VectorFunction< dim, ADNumberTypeCode, ScalarType > Class Template Reference

#include <deal.II/differentiation/ad/ad_helpers.h>

Inheritance diagram for Differentiation::AD::VectorFunction< dim, ADNumberTypeCode, ScalarType >:

Public Types

using scalar_type
 
using ad_type
 

Public Member Functions

Constructor / destructor
 VectorFunction (const unsigned int n_independent_variables, const unsigned int n_dependent_variables)
 
virtual ~VectorFunction ()=default
 
Operations specific to taped mode: Reusing tapes
void set_independent_variables (const std::vector< scalar_type > &values)
 
void set_independent_variable (const ValueType &value, const ExtractorType &extractor)
 
Interrogation of internal information
std::size_t n_independent_variables () const
 
std::size_t n_dependent_variables () const
 
void print (std::ostream &stream) const
 
void print_values (std::ostream &stream) const
 
void print_tape_stats (const typename Types< ad_type >::tape_index tape_index, std::ostream &stream) const
 
Operations specific to taped mode: Recording tapes
bool is_recording () const
 
Types< ad_type >::tape_index active_tape_index () const
 
bool is_registered_tape (const typename Types< ad_type >::tape_index tape_index) const
 
void set_tape_buffer_sizes (const typename Types< ad_type >::tape_buffer_sizes obufsize=64 *1024 *1024, const typename Types< ad_type >::tape_buffer_sizes lbufsize=64 *1024 *1024, const typename Types< ad_type >::tape_buffer_sizes vbufsize=64 *1024 *1024, const typename Types< ad_type >::tape_buffer_sizes tbufsize=64 *1024 *1024)
 
bool start_recording_operations (const typename Types< ad_type >::tape_index tape_index, const bool overwrite_tape=false, const bool keep_independent_values=true)
 
void stop_recording_operations (const bool write_tapes_to_file=false)
 
void activate_recorded_tape (const typename Types< ad_type >::tape_index tape_index)
 
bool recorded_tape_requires_retaping (const typename Types< ad_type >::tape_index tape_index) const
 
bool active_tape_requires_retaping () const
 
void clear_active_tape ()
 

Static Public Member Functions

Operations specific to tapeless mode
static void configure_tapeless_mode (const unsigned int n_independent_variables, const bool ensure_persistent_setting=true)
 

Static Public Attributes

static constexpr unsigned int dimension
 

Dependent variables

void register_dependent_variables (const std::vector< ad_type > &funcs)
 
template<typename ValueType , typename ExtractorType >
void register_dependent_variable (const ValueType &funcs, const ExtractorType &extractor)
 
void compute_values (Vector< scalar_type > &values) const
 
void compute_jacobian (FullMatrix< scalar_type > &jacobian) const
 
template<typename ExtractorType_Row >
static internal::VectorFieldValue< dim, scalar_type, ExtractorType_Row >::type extract_value_component (const Vector< scalar_type > &values, const ExtractorType_Row &extractor_row)
 
template<typename ExtractorType_Row , typename ExtractorType_Col >
static internal::VectorFieldJacobian< dim, scalar_type, ExtractorType_Row, ExtractorType_Col >::type extract_jacobian_component (const FullMatrix< scalar_type > &jacobian, const ExtractorType_Row &extractor_row, const ExtractorType_Col &extractor_col)
 
static Tensor< 0, dim, scalar_typeextract_jacobian_component (const FullMatrix< scalar_type > &jacobian, const FEValuesExtractors::Scalar &extractor_row, const FEValuesExtractors::Scalar &extractor_col)
 
static SymmetricTensor< 4, dim, scalar_typeextract_jacobian_component (const FullMatrix< scalar_type > &jacobian, const FEValuesExtractors::SymmetricTensor< 2 > &extractor_row, const FEValuesExtractors::SymmetricTensor< 2 > &extractor_col)
 

Independent variables

virtual void reset (const unsigned int n_independent_variables=::numbers::invalid_unsigned_int, const unsigned int n_dependent_variables=::numbers::invalid_unsigned_int, const bool clear_registered_tapes=true) override
 
void register_independent_variables (const std::vector< scalar_type > &values)
 
void register_independent_variable (const ValueType &value, const ExtractorType &extractor)
 
const std::vector< ad_type > & get_sensitive_variables () const
 
internal::Extractor< dim, ExtractorType >::template tensor_type< typename HelperBase< ADNumberTypeCode, double >::ad_typeget_sensitive_variables (const ExtractorType &extractor) const
 
std::vector< boolsymmetric_independent_variables
 
void set_sensitivity_value (const unsigned int index, const bool symmetric_component, const scalar_type &value)
 
bool is_symmetric_independent_variable (const unsigned int index) const
 
unsigned int n_symmetric_independent_variables () const
 

Independent variables

void set_sensitivity_value (const unsigned int index, const scalar_type &value)
 
void reset_registered_independent_variables ()
 
void mark_independent_variable (const unsigned int index, ad_type &out) const
 
void finalize_sensitive_independent_variables () const
 
void initialize_non_sensitive_independent_variable (const unsigned int index, ad_type &out) const
 
unsigned int n_registered_independent_variables () const
 
std::vector< scalar_typeindependent_variable_values
 
std::vector< ad_typeindependent_variables
 
std::vector< boolregistered_independent_variable_values
 
std::vector< boolregistered_marked_independent_variables
 

Drivers and taping

void activate_tape (const typename Types< ad_type >::tape_index tape_index, const bool read_mode)
 
TapedDrivers< ad_type, scalar_typetaped_driver
 
TapelessDrivers< ad_type, scalar_typetapeless_driver
 

Dependent variables

void reset_registered_dependent_variables (const bool flag=false)
 
unsigned int n_registered_dependent_variables () const
 
void register_dependent_variable (const unsigned int index, const ad_type &func)
 
std::vector< ad_typedependent_variables
 
std::vector< boolregistered_marked_dependent_variables
 

Detailed Description

template<int dim, enum AD::NumberTypes ADNumberTypeCode, typename ScalarType = double>
class Differentiation::AD::VectorFunction< dim, ADNumberTypeCode, ScalarType >

A helper class that facilitates the evaluation of a vector of functions, typically one that represents a collection of coupled, multi-dimensional fields. This class would typically be used to compute the linearization of a set of kinetic field variables defined at the quadrature point level.

An example of its usage in the case of linearizing the kinetic variables derived from a multi-field constitutive law might be as follows:

// Define some extractors that will help us set independent variables
// and later get the computed values related to the dependent
// variables. Each of these extractors is related to the gradient of a
// component of the solution field (in this case, displacement and
// magnetic scalar potential). Here "C" is the right Cauchy-Green
// tensor and "H" is the magnetic field.
const unsigned int n_independent_variables =
// Declare how many dependent variables we expect to compute.
// In this case, we will be computing a stress field (a symmetric
// rank-2 tensor) and the magnetic induction (a vector field).
// At the same time we define some additional extractors associated
// with these kinetic fields. In general, these need not be of the same
// layout as the independent variables.
const unsigned int n_dependent_variables =
// Define the helper that we will use in the AD computations for our
// scalar energy function. Note that we expect it to return values of
// type double.
using ADNumberType = typename ADHelper::ad_type;
// Compute the fields that provide the independent values.
// When the tape is being replayed, these should be set to something
// meaningful.
const Tensor<1,dim> H = ...;
const SymmetricTensor<2,dim> C = ...;
// If using a taped AD number, then at this point we would initiate
// taping of the expression for the material stored energy function
// for this particular set of material parameters:
// Select a tape number to record to
const typename Types<ADNumberType>::tape_index tape_index = ...;
// Indicate that we are about to start tracing the operations for
// function evaluation on the tape. If this tape has already been
// used (i.e. the operations are already recorded) then we
// (optionally) load the tape and reuse this data.
const bool is_recording
= ad_helper.start_recording_operations(tape_index);
// The steps that follow in the recording phase are required for
// tapeless methods as well.
if (is_recording == true)
{
// This is the "recording" phase of the operations.
// First, we set the values for all fields.
// These could happily be set to anything, unless the function will
// be evaluated along a branch not otherwise traversed during later
// use. For this reason, in this example instead of using some dummy
// values, we'll actually map out the function at the same point
// around which we'll later linearize it.
ad_helper.register_independent_variable(H, H_dofs);
ad_helper.register_independent_variable(C, C_dofs);
// NOTE: We have to extract the sensitivities in the order we wish to
// introduce them. So this means we have to do it by logical order
// of the extractors that we've created.
ad_helper.get_sensitive_variables(C_dofs);
ad_helper.get_sensitive_variables(H_dofs);
// Here we define the stress and magnetic induction in terms
// of the independent values C_AD and H_AD.
const Tensor<1, dim, ad_type> B_AD = ...;
// Register the definition of the kinetic fields. The second
// argument to the function provides a non-overlapping ordering
// of the
ad_helper.register_dependent_variable(S_AD, S_dofs);
ad_helper.register_dependent_variable(B_AD, B_dofs);
// Indicate that we have completed tracing the operations onto
// the tape.
ad_helper.stop_recording_operations(false); // write_tapes_to_file
}
else
{
// This is the "tape reuse" phase of the operations.
// Here we will leverage the already traced operations that reside
// on a tape, and simply re-evaluate the tape at a different point
// to get the function values and their derivatives.
// Load the existing tape to be reused
ad_helper.activate_recorded_tape(tape_index);
// Set the new values of the independent variables where the
// recorded dependent functions are to be evaluated (and
// differentiated around).
ad_helper.set_independent_variable(C, C_dofs);
ad_helper.set_independent_variable(H, H_dofs);
}
// Play the tape and store the output function value, its gradient and
// linearization. These are expensive to compute, so we'll do this once
// and extract the desired values from these intermediate outputs.
Vector<double> values (ad_helper.n_dependent_variables());
FullMatrix<double> jacobian (ad_helper.n_dependent_variables(),
ad_helper.n_independent_variables());
ad_helper.compute_values(values);
ad_helper.compute_jacobian(jacobian);
// Extract the desired components of the value vector and its Jacobian
// matrix. In this example, we use them to compute the Piola-Kirchhoff
// stress tensor S and its associated tangent, defined
// as HH = 2*dS/dC...
ad_helper.extract_value_component(values,S_dofs);
2.0*ad_helper.extract_jacobian_component(jacobian,S_dofs,C_dofs);
// ... the magnetic induction B and its associated tangent defined
// as BB = dB/dH...
const Tensor<1,dim> B =
ad_helper.extract_value_component(values,H_dofs);
symmetrize(ad_helper.extract_jacobian_component(jacobian,B_dofs,H_dofs));
// ... and finally the magnetoelastic coupling tangent, defined
// as PP = -dS/dH. Here the order of the extractor arguments is
// especially important, as it dictates the field that is being
// differentiated, and which the directional derivatives are being
// computed.
-ad_helper.extract_jacobian_component(jacobian,S_dofs,H_dofs)
DEAL_II_HOST constexpr SymmetricTensor< 2, dim, Number > symmetrize(const Tensor< 2, dim, Number > &t)
Warning
ADOL-C does not support the standard threading models used by deal.II, so this class should not be embedded within a multithreaded function when using ADOL-C number types. It is, however, suitable for use in both serial and MPI routines.

Definition at line 3507 of file ad_helpers.h.

Member Typedef Documentation

◆ scalar_type

template<int dim, enum AD::NumberTypes ADNumberTypeCode, typename ScalarType = double>
using Differentiation::AD::VectorFunction< dim, ADNumberTypeCode, ScalarType >::scalar_type
Initial value:
typename AD::NumberTraits< ScalarType, ADNumberTypeCode >::scalar_type scalar_type
Definition ad_helpers.h:175

Type definition for the floating point number type that is used in, and results from, all computations.

Definition at line 3515 of file ad_helpers.h.

◆ ad_type

template<int dim, enum AD::NumberTypes ADNumberTypeCode, typename ScalarType = double>
using Differentiation::AD::VectorFunction< dim, ADNumberTypeCode, ScalarType >::ad_type
Initial value:
typename AD::NumberTraits< ScalarType, ADNumberTypeCode >::ad_type ad_type
Definition ad_helpers.h:182

Type definition for the auto-differentiation number type that is used in all computations.

Definition at line 3522 of file ad_helpers.h.

Constructor & Destructor Documentation

◆ VectorFunction()

template<int dim, enum AD::NumberTypes ADNumberTypeCode, typename ScalarType >
Differentiation::AD::VectorFunction< dim, ADNumberTypeCode, ScalarType >::VectorFunction ( const unsigned int n_independent_variables,
const unsigned int n_dependent_variables )

The constructor for the class.

Parameters
[in]n_independent_variablesThe number of independent variables that will be used in the definition of the functions that it is desired to compute the sensitivities of. In the computation of \(\mathbf{f}(\mathbf{X})\), this will be the number of inputs \(\mathbf{X}\), i.e., the dimension of the domain space.
[in]n_dependent_variablesThe number of scalar functions to be defined that will have a sensitivity to the given independent variables. In the computation of \(\mathbf{f}(\mathbf{X})\), this will be the number of outputs \(\mathbf{f}\), i.e., the dimension of the image space.

Definition at line 1645 of file ad_helpers.cc.

◆ ~VectorFunction()

template<int dim, enum AD::NumberTypes ADNumberTypeCode, typename ScalarType = double>
virtual Differentiation::AD::VectorFunction< dim, ADNumberTypeCode, ScalarType >::~VectorFunction ( )
virtualdefault

Destructor.

Member Function Documentation

◆ register_dependent_variables()

template<int dim, enum AD::NumberTypes ADNumberTypeCode, typename ScalarType >
void Differentiation::AD::VectorFunction< dim, ADNumberTypeCode, ScalarType >::register_dependent_variables ( const std::vector< ad_type > & funcs)

Register the definition of the vector field \(\boldsymbol{\Psi}(\mathbf{X})\).

Parameters
[in]funcsA vector of recorded functions that defines the dependent variables.
Note
For this class that expects only vector field of dependent variables, this function must only be called once per tape.
For taped AD numbers, this operation is only valid in recording mode.

Definition at line 1659 of file ad_helpers.cc.

◆ register_dependent_variable() [1/2]

template<int dim, enum AD::NumberTypes ADNumberTypeCode, typename ScalarType = double>
template<typename ValueType , typename ExtractorType >
void Differentiation::AD::VectorFunction< dim, ADNumberTypeCode, ScalarType >::register_dependent_variable ( const ValueType & funcs,
const ExtractorType & extractor )

Register the definition of the vector field \(\hat{\mathbf{g}}(\mathbf{X}) \subset \boldsymbol{\Psi}(\mathbf{X})\) that may represent a subset of the dependent variables.

Parameters
[in]funcsThe recorded functions that define a set of dependent variables.
[in]extractorAn extractor associated with the input field variables. This effectively defines which components of the global set of dependent variables this field is associated with.
Note
The input extractor must correspond to the input ValueType. So, for example, if a value is a rank-1 tensor (i.e. of type Tensor<1,dim,scalar_type>), then the extractor must be an FEValuesExtractors::Vector or FEValuesExtractors::Tensor<1>.
For taped AD numbers, this operation is only valid in recording mode.

◆ compute_values()

template<int dim, enum AD::NumberTypes ADNumberTypeCode, typename ScalarType >
void Differentiation::AD::VectorFunction< dim, ADNumberTypeCode, ScalarType >::compute_values ( Vector< scalar_type > & values) const

Compute the value of the vector field \(\boldsymbol{\Psi}(\mathbf{X})\).

Parameters
[out]valuesA Vector object with the value for each component of the vector field evaluated at the point defined by the independent variable values. The output values vector has a length corresponding to n_dependent_variables.

Definition at line 1676 of file ad_helpers.cc.

◆ compute_jacobian()

template<int dim, enum AD::NumberTypes ADNumberTypeCode, typename ScalarType >
void Differentiation::AD::VectorFunction< dim, ADNumberTypeCode, ScalarType >::compute_jacobian ( FullMatrix< scalar_type > & jacobian) const

Compute the Jacobian (first derivative) of the vector field with respect to all independent variables, i.e.

\[ \mathbf{J}(\boldsymbol{\Psi}) = \frac{\partial\boldsymbol{\Psi}(\mathbf{X})}{\partial\mathbf{X}} \]

Parameters
[out]jacobianA FullMatrix with the gradient of each component of the vector field evaluated at the point defined by the independent variable values. The output jacobian matrix has dimensions corresponding to n_dependent_variables \(\times\)n_independent_variables.

Definition at line 1732 of file ad_helpers.cc.

◆ extract_value_component()

template<int dim, enum AD::NumberTypes ADNumberTypeCode, typename ScalarType = double>
template<typename ExtractorType_Row >
static internal::VectorFieldValue< dim, scalar_type, ExtractorType_Row >::type Differentiation::AD::VectorFunction< dim, ADNumberTypeCode, ScalarType >::extract_value_component ( const Vector< scalar_type > & values,
const ExtractorType_Row & extractor_row )
static

Extract the set of functions' values for a subset of dependent variables \(\mathbf{g} \subset \boldsymbol{\Psi}(\mathbf{X})\).

Parameters
[in]valuesA Vector object with the value for each component of the vector field evaluated at the point defined by the independent variable values.
[in]extractor_rowAn extractor associated with the input field variables. This effectively defines which components of the global set of dependent variables this field is associated with.

◆ extract_jacobian_component() [1/3]

template<int dim, enum AD::NumberTypes ADNumberTypeCode, typename ScalarType = double>
template<typename ExtractorType_Row , typename ExtractorType_Col >
static internal::VectorFieldJacobian< dim, scalar_type, ExtractorType_Row, ExtractorType_Col >::type Differentiation::AD::VectorFunction< dim, ADNumberTypeCode, ScalarType >::extract_jacobian_component ( const FullMatrix< scalar_type > & jacobian,
const ExtractorType_Row & extractor_row,
const ExtractorType_Col & extractor_col )
static

Extract the Jacobian of the subset of dependent functions \(\mathbf{g} \subset \boldsymbol{\Psi}(\mathbf{X})\) for a subset of independent variables \(\mathbf{A} \subset \mathbf{X}\), i.e.

\[ \mathbf{J}(\mathbf{g}) = \frac{\partial\mathbf{g}(\mathbf{X})}{\partial\mathbf{A}} \]

The first index of the Jacobian matrix \(\mathbf{J}(\mathbf{g})\) relates to the dependent variables, while the second index relates to the independent variables.

Parameters
[in]jacobianThe Jacobian of the vector function with respect to all independent variables, i.e., that returned by compute_jacobian().
[in]extractor_rowAn extractor associated with the input field variables for which the first index of the Jacobian is extracted. This effectively defines the correspondence between components of the global set of dependent variables and the field (representing a subset of dependent functions) associated with the extractor.
[in]extractor_colAn extractor associated with the input field variables for which the second index of the Jacobian is extracted. This effectively defines the correspondence between components of the global set of independent variables and the field (representing a subset of independent variables) associated with the extractor.
Returns
A Tensor or SymmetricTensor with its rank and symmetries determined by the extractor_row and extractor_col . This corresponds to subsetting a whole set of rows and columns of the Jacobian matrix, scaling those entries to take account of tensor symmetries, and then reshaping the (sub-)matrix so obtained into a tensor, the final result. For example, if extractor_row is a FEValuesExtractors::Vector and extractor_col is a FEValuesExtractors::Tensor, then the returned object is a Tensor of rank 3, with its first index associated with the field corresponding to the row extractor and the second and third indices associated with the field corresponding to the column extractor. Similarly, if extractor_row is a FEValuesExtractors::SymmetricTensor and extractor_col is a FEValuesExtractors::SymmetricTensor, then the returned object is a SymmetricTensor of rank 4, with its first two indices associated with the field corresponding to the row extractor and the last two indices associated with the field corresponding to the column extractor.

◆ extract_jacobian_component() [2/3]

template<int dim, enum AD::NumberTypes ADNumberTypeCode, typename ScalarType >
Tensor< 0, dim, typename VectorFunction< dim, ADNumberTypeCode, ScalarType >::scalar_type > Differentiation::AD::VectorFunction< dim, ADNumberTypeCode, ScalarType >::extract_jacobian_component ( const FullMatrix< scalar_type > & jacobian,
const FEValuesExtractors::Scalar & extractor_row,
const FEValuesExtractors::Scalar & extractor_col )
static

Extract the Jacobian of the subset of dependent functions \(\mathbf{g} \subset \boldsymbol{\Psi}(\mathbf{X})\) for a subset of independent variables \(\mathbf{A} \subset \mathbf{X}\), i.e.

\[ \mathbf{J}(\mathbf{g}) = \frac{\partial\mathbf{g}(\mathbf{X})}{\partial\mathbf{A}} \]

This function is a specialization of the above for rank-0 tensors (scalars). This corresponds to extracting a single entry of the Jacobian matrix because both extractors imply selection of just a single row or column of the matrix.

Definition at line 1810 of file ad_helpers.cc.

◆ extract_jacobian_component() [3/3]

template<int dim, enum AD::NumberTypes ADNumberTypeCode, typename ScalarType >
SymmetricTensor< 4, dim, typename VectorFunction< dim, ADNumberTypeCode, ScalarType >::scalar_type > Differentiation::AD::VectorFunction< dim, ADNumberTypeCode, ScalarType >::extract_jacobian_component ( const FullMatrix< scalar_type > & jacobian,
const FEValuesExtractors::SymmetricTensor< 2 > & extractor_row,
const FEValuesExtractors::SymmetricTensor< 2 > & extractor_col )
static

Extract the Jacobian of the subset of dependent functions \(\mathbf{g} \subset \boldsymbol{\Psi}(\mathbf{X})\) for a subset of independent variables \(\mathbf{A} \subset \mathbf{X}\), i.e.

\[ \mathbf{J}(\mathbf{g}) = \frac{\partial\mathbf{g}(\mathbf{X})}{\partial\mathbf{A}} \]

This function is a specialization of the above for rank-4 symmetric tensors.

Definition at line 1848 of file ad_helpers.cc.

◆ reset()

void Differentiation::AD::PointLevelFunctionsBase< dim, ADNumberTypeCode, double >::reset ( const unsigned int n_independent_variables = ::numbers::invalid_unsigned_int,
const unsigned int n_dependent_variables = ::numbers::invalid_unsigned_int,
const bool clear_registered_tapes = true )
overridevirtualinherited

Reset the state of the class.

When an instance of the class is stored as a class member object with the intention to reuse its instance, it may be necessary to reset the state of the object before use. This is because, internally, there is error checking performed to ensure that the correct auto-differentiable data is being tracked and used only when appropriate. This function clears all member data and, therefore, allows the state of all internal flags to be safely reset to their initial state.

In the rare case that the number of independent or dependent variables has changed, this can also be reconfigured by passing in the appropriate arguments to the function.

Parameters
[in]n_independent_variablesThe number of independent variables that will be used in the definition of the functions that it is desired to compute the sensitivities of. In the computation of \(\mathbf{f}(\mathbf{X})\), this will be the number of inputs \(\mathbf{X}\), i.e., the dimension of the domain space.
[in]n_dependent_variablesThe number of scalar functions to be defined that will have a sensitivity to the given independent variables. In the computation of \(\mathbf{f}(\mathbf{X})\), this will be the number of outputs \(\mathbf{f}\), i.e., the dimension of the image space.
[in]clear_registered_tapesA flag that indicates the that list of registered_tapes must be cleared. If set to true then the data structure that tracks which tapes have been recorded is cleared as well. It is then expected that any preexisting tapes be re-recorded.
Note
This also resets the active tape number to an invalid number, and deactivates the recording mode for taped variables.

Reimplemented from Differentiation::AD::HelperBase< ADNumberTypeCode, double >.

Definition at line 2733 of file ad_helpers.cc.

◆ register_independent_variables()

void Differentiation::AD::PointLevelFunctionsBase< dim, ADNumberTypeCode, double >::register_independent_variables ( const std::vector< scalar_type > & values)
inherited

Register the complete set of independent variables \(\mathbf{X}\).

Parameters
[in]valuesA field that defines the values of all independent variables. When considering taped AD numbers with branching functions, to avoid potential issues with branch switching it may be a good idea to choose these values close or equal to those that will be later evaluated and differentiated around.
Note
The input value type must correspond to this class's scalar_type. Depending on the selected ADNumberTypeCode, this may or may not correspond with the ScalarType prescribed as a template argument.
For taped AD numbers, this operation is only valid in recording mode.

Definition at line 2755 of file ad_helpers.cc.

◆ register_independent_variable()

void Differentiation::AD::PointLevelFunctionsBase< dim, ADNumberTypeCode, double >::register_independent_variable ( const ValueType & value,
const ExtractorType & extractor )
inherited

Register the subset of independent variables \(\mathbf{A} \subset \mathbf{X}\).

Parameters
[in]valueA field that defines a number of independent variables. When considering taped AD numbers with branching functions, to avoid potential issues with branch switching it may be a good idea to choose these values close or equal to those that will be later evaluated and differentiated around.
[in]extractorAn extractor associated with the input field variables. This effectively defines which components of the global set of independent variables this field is associated with.
Note
The input value type must correspond to this class's scalar_type. Depending on the selected ADNumberTypeCode, this may or may not correspond with the ScalarType prescribed as a template argument.
The input extractor must correspond to the input ValueType. So, for example, if a value is a rank-1 tensor (i.e. of type Tensor<1,dim,scalar_type>), then the extractor must be an FEValuesExtractors::Vector or FEValuesExtractors::Tensor<1>.
This function may be repeatedly used until a call to finalize_sensitive_independent_variables() or get_sensitive_variables() is made.
For taped AD numbers, this operation is only valid in recording mode.

◆ get_sensitive_variables() [1/2]

const std::vector< typename PointLevelFunctionsBase< dim, ADNumberTypeCode, double >::ad_type > & Differentiation::AD::PointLevelFunctionsBase< dim, ADNumberTypeCode, double >::get_sensitive_variables ( ) const
inherited

Return the complete set of independent variables as represented by auto-differentiable numbers. These are the independent variables \(\mathbf{X}\) at which the dependent values are evaluated and differentiated.

This function indicates to the AD library that implements the auto-differentiable number type that operations performed on these numbers are to be tracked so they are considered "sensitive" variables. This is, therefore, the set of variables with which one would then perform computations, and based on which one can then extract both the value of the function and its derivatives with the member functions below. The values of the components of the returned object are initialized to the values set with register_independent_variable().

Returns
An array of auto-differentiable type numbers.
Note
For taped AD numbers, this operation is only valid in recording mode.

Definition at line 2811 of file ad_helpers.cc.

◆ get_sensitive_variables() [2/2]

internal::Extractor< dim, ExtractorType >::template tensor_type< typename HelperBase< ADNumberTypeCode, double >::ad_type > Differentiation::AD::PointLevelFunctionsBase< dim, ADNumberTypeCode, double >::get_sensitive_variables ( const ExtractorType & extractor) const
inherited

◆ set_independent_variables()

void Differentiation::AD::PointLevelFunctionsBase< dim, ADNumberTypeCode, double >::set_independent_variables ( const std::vector< scalar_type > & values)
inherited

Set the values for the independent variables \(\mathbf{X}\).

Parameters
[in]valuesA vector that defines the values of all independent variables.
Note
The input value type must correspond to this class's scalar_type. Depending on the selected ADNumberTypeCode, this may or may not correspond with the ScalarType prescribed as a template argument.
If the keep_independent_values flag has been set when HelperBase::start_recording_operations() is called then the tape is immediately usable after creation, and the values of the independent variables set by register_independent_variables() are those at which the function is to be evaluated. In this case, a separate call to this function is not strictly necessary.

Definition at line 2868 of file ad_helpers.cc.

◆ set_independent_variable()

void Differentiation::AD::PointLevelFunctionsBase< dim, ADNumberTypeCode, double >::set_independent_variable ( const ValueType & value,
const ExtractorType & extractor )
inherited

Set the values for a subset of independent variables \(\mathbf{A} \subset \mathbf{X}\).

Parameters
[in]valueA field that defines the values of a number of independent variables.
[in]extractorAn extractor associated with the input field variables. This effectively defines which components of the global set of independent variables this field is associated with.
Note
The input value type must correspond to this class's scalar_type. Depending on the selected ADNumberTypeCode, this may or may not correspond with the ScalarType prescribed as a template argument.
The input extractor must correspond to the input ValueType. So, for example, if a value is a rank-1 tensor (i.e. of type Tensor<1,dim,scalar_type>), then the extractor must be an FEValuesExtractors::Vector or FEValuesExtractors::Tensor<1>.
If the keep_independent_values flag has been set when HelperBase::start_recording_operations() is called then the tape is immediately usable after creation, and the values of the independent variables set by register_independent_variable() are those at which the function is to be evaluated. In this case, a separate call to this function is not strictly necessary.

◆ set_sensitivity_value() [1/2]

void Differentiation::AD::PointLevelFunctionsBase< dim, ADNumberTypeCode, double >::set_sensitivity_value ( const unsigned int index,
const bool symmetric_component,
const scalar_type & value )
protectedinherited

Set the actual value of the independent variable \(X_{i}\).

Parameters
[in]indexThe index in the vector of independent variables.
[in]symmetric_componentMark whether this index relates to a component of a field that has a symmetric counterpart (e.g. if index represents an off-diagonal entry in a symmetric tensor).
[in]valueThe value to set the index'd independent variable to.

Definition at line 2920 of file ad_helpers.cc.

◆ set_sensitivity_value() [2/2]

void Differentiation::AD::HelperBase< ADNumberTypeCode, double >::set_sensitivity_value ( const unsigned int index,
const scalar_type & value )
protectedinherited

Set the actual value of the independent variable \(X_{i}\).

Parameters
[in]indexThe index in the vector of independent variables.
[in]valueThe value to set the index'd independent variable to.

Definition at line 673 of file ad_helpers.cc.

◆ is_symmetric_independent_variable()

bool Differentiation::AD::PointLevelFunctionsBase< dim, ADNumberTypeCode, double >::is_symmetric_independent_variable ( const unsigned int index) const
protectedinherited

Return whether the index'th independent variables is one for which we must take into account symmetry when extracting their gradient or Hessian values.

Definition at line 2930 of file ad_helpers.cc.

◆ n_symmetric_independent_variables()

unsigned int Differentiation::AD::PointLevelFunctionsBase< dim, ADNumberTypeCode, double >::n_symmetric_independent_variables ( ) const
protectedinherited

Return the number of independent variables that have been marked as being components of a symmetric field.

Definition at line 2937 of file ad_helpers.cc.

◆ n_independent_variables()

std::size_t Differentiation::AD::HelperBase< ADNumberTypeCode, double >::n_independent_variables ( ) const
inherited

Return the number of independent variables that this object expects to work with. This is the dimension of the domain space.

Definition at line 224 of file ad_helpers.cc.

◆ n_dependent_variables()

std::size_t Differentiation::AD::HelperBase< ADNumberTypeCode, double >::n_dependent_variables ( ) const
inherited

Return the number of dependent variables that this object expects to operate on. This is the dimension of the image space.

Definition at line 231 of file ad_helpers.cc.

◆ print()

void Differentiation::AD::HelperBase< ADNumberTypeCode, double >::print ( std::ostream & stream) const
inherited

Print the status of all queryable data. Exactly what is printed and its format depends on the ad_type, as is determined by the ADNumberTypeCode template parameter.

Parameters
[in]streamThe output stream to which the values are to be written.

Definition at line 242 of file ad_helpers.cc.

◆ print_values()

void Differentiation::AD::HelperBase< ADNumberTypeCode, double >::print_values ( std::ostream & stream) const
inherited

Print the values currently assigned to the independent variables.

Parameters
[in]streamThe output stream to which the values are to be written.

Definition at line 251 of file ad_helpers.cc.

◆ print_tape_stats()

void Differentiation::AD::HelperBase< ADNumberTypeCode, double >::print_tape_stats ( const typename Types< ad_type >::tape_index tape_index,
std::ostream & stream ) const
inherited

Print the statistics regarding the usage of the tapes.

Parameters
[in]tape_indexThe index of the tape to get the statistics of.
[out]streamThe output stream to which the values are to be written.
Note
This function only produces meaningful output when ad_type is a taped auto-differentiable number.

Definition at line 264 of file ad_helpers.cc.

◆ configure_tapeless_mode()

void Differentiation::AD::HelperBase< ADNumberTypeCode, double >::configure_tapeless_mode ( const unsigned int n_independent_variables,
const bool ensure_persistent_setting = true )
staticinherited

Pre-specify the number of independent_variables to be used in tapeless mode.

Although this function is called internally in the HelperBase constructor, there may be occasions when ADOL-C tapeless numbers (adtl::adoubles) are created before an instance of this class is created. This function therefore allows one to declare at the earliest possible instance how many directional derivatives will be considered in tapeless mode.

Warning
With ensure_persistent_setting set to true when the ad_type is an ADOL-C tapeless number, calling this function leaves the set number of directional derivatives in a persistent state. It will therefore not be possible to further modify the number of directional derivatives to be tracked by adtl::adoubles's during course of the program's execution.

Definition at line 293 of file ad_helpers.cc.

◆ is_recording()

bool Differentiation::AD::HelperBase< ADNumberTypeCode, double >::is_recording ( ) const
inherited

Return whether or not this class is tracking calculations performed with its marked independent variables.

Definition at line 350 of file ad_helpers.cc.

◆ active_tape_index()

Types< typenameHelperBase< ADNumberTypeCode, double >::ad_type >::tape_index Differentiation::AD::HelperBase< ADNumberTypeCode, double >::active_tape_index ( ) const
inherited

Return the tape index which is currently activated for recording or reading.

Definition at line 357 of file ad_helpers.cc.

◆ is_registered_tape()

bool Differentiation::AD::HelperBase< ADNumberTypeCode, double >::is_registered_tape ( const typename Types< ad_type >::tape_index tape_index) const
inherited

Return whether or not a tape number has already been used or registered.

Definition at line 364 of file ad_helpers.cc.

◆ set_tape_buffer_sizes()

void Differentiation::AD::HelperBase< ADNumberTypeCode, double >::set_tape_buffer_sizes ( const typename Types< ad_type >::tape_buffer_sizes obufsize = 64 * 1024 * 1024,
const typename Types< ad_type >::tape_buffer_sizes lbufsize = 64 * 1024 * 1024,
const typename Types< ad_type >::tape_buffer_sizes vbufsize = 64 * 1024 * 1024,
const typename Types< ad_type >::tape_buffer_sizes tbufsize = 64 * 1024 * 1024 )
inherited

Set the buffer sizes for the next active tape.

This function must be called before start_recording_operations() for it to have any influence on the memory allocated to the next recorded tape.

Note
This function only has an effect when using ADOL-C numbers. As stated by the ADOL-C manual, it may be desirable to create a file ".adolcrc" in the program run directory and set the buffer size therein. Alternatively, this function can be used to override the settings for any given tape, or can be used in the event that no ".adolcrc" file exists. The default value for each buffer is set at 64 megabytes, a heuristically chosen value thought to be appropriate for use within the context of finite element analysis when considering coupled problems with multiple vector-valued fields discretised by higher order shape functions, as well as complex constitutive laws.
Parameters
[in]obufsizeADOL-C operations buffer size
[in]lbufsizeADOL-C locations buffer size
[in]vbufsizeADOL-C value buffer size
[in]tbufsizeADOL-C Taylor buffer size

Definition at line 393 of file ad_helpers.cc.

◆ start_recording_operations()

bool Differentiation::AD::HelperBase< ADNumberTypeCode, double >::start_recording_operations ( const typename Types< ad_type >::tape_index tape_index,
const bool overwrite_tape = false,
const bool keep_independent_values = true )
inherited

Enable recording mode for a given tape. The use of this function is mandatory if the auto-differentiable number is a taped type. However, for the purpose of developing generic code, it can also be safely called for tapeless auto-differentiable numbers.

The operations that take place between this function call and that of stop_recording_operations() are recorded to the tape and can be replayed and reevaluated as necessary.

The typical set of operations to be performed during this "recording" phase (between the calls to start_recording_operations() and stop_recording_operations() ) are:

Parameters
[in]tape_indexThe index of the tape to be written
[in]overwrite_tapeExpress whether tapes are allowed to be overwritten. If true then any existing tape with a given tape_index will be destroyed and a new tape traced over it.
[in]keep_independent_valuesDetermines whether the numerical values of all independent variables are recorded in the tape buffer. If true, then the tape can be immediately used to perform computations after recording is complete.
Note
During the recording phase, no value(), gradient(), hessian(), or jacobian() operations can be performed.
The chosen tape index must be greater than Numbers<ad_type>::invalid_tape_index and less than Numbers<ad_type>::max_tape_index.

Definition at line 449 of file ad_helpers.cc.

◆ stop_recording_operations()

void Differentiation::AD::HelperBase< ADNumberTypeCode, double >::stop_recording_operations ( const bool write_tapes_to_file = false)
inherited

Disable recording mode for a given tape. The use of this function is mandatory if the auto-differentiable number is a taped type. However, for the purpose of developing generic code, it can also be safely called for tapeless auto-differentiable numbers.

Note
After this function call, the tape is considered ready for use and operations such as value(), gradient() or hessian() can be executed.
For taped AD numbers, this operation is only valid in recording mode.

Definition at line 466 of file ad_helpers.cc.

◆ activate_recorded_tape()

void Differentiation::AD::HelperBase< ADNumberTypeCode, double >::activate_recorded_tape ( const typename Types< ad_type >::tape_index tape_index)
inherited

Select a pre-recorded tape to read from.

Parameters
[in]tape_indexThe index of the tape to be read from.
Note
The chosen tape index must be greater than Numbers<ad_type>::invalid_tape_index and less than Numbers<ad_type>::max_tape_index.

Definition at line 478 of file ad_helpers.cc.

◆ recorded_tape_requires_retaping()

bool Differentiation::AD::HelperBase< ADNumberTypeCode, double >::recorded_tape_requires_retaping ( const typename Types< ad_type >::tape_index tape_index) const
inherited

Return a flag that, when true, indicates that the retaping of the dependent function is necessary for a reliable computation to be performed on a tape with the given tape_index. This may be necessary if a sign comparison within branched operations yields different results to those computed at the original tape evaluation point.

This issue, known as "branch switching", can be clarified by means of a trivial, contrived example:

ADNumberType func (ADNumberType x, ADNumberType y, ADNumberType z)
{
if (x < y)
return y;
else
return x*z;
}

During taping, the conditional statement may be either true or false, and the result (with its sensitivities) returned by this function. The AD library doesn't just record the parse tree of the operations applied on the branch chosen at the time to taping, but also checks that the condition continues to be satisfied. For some other evaluation of the tape (i.e. for some different inputs x and y), the other branch of the conditional check may be chosen. The result of following this code path has not been recorded on the tape, and therefore cannot be evaluated. In such a case, the underlying AD library will be able to tell you that it is necessary to re-record the tape at the new evaluation point in order to resolve the new code branch. This function can be used to find out whether this is so.

For the output of this function to be meaningful, it must be called after activate_recorded_tape() is called and the new evaluation point for the tape (i.e. values of the independent variables) have been set and subsequently used (i.e. in the determination of the values or derivatives of the dependent variables).

Definition at line 521 of file ad_helpers.cc.

◆ active_tape_requires_retaping()

bool Differentiation::AD::HelperBase< ADNumberTypeCode, double >::active_tape_requires_retaping ( ) const
inherited

Return a flag that, when true, indicates that the retaping of the dependent function is necessary for a reliable computation to be performed on the currently active tape. This may be necessary if a sign comparison within branched operations yields different results to those computed at the original tape evaluation point.

This issue, known as "branch switching", can be clarified by means of a trivial, contrived example:

ADNumberType func (ADNumberType x, ADNumberType y, ADNumberType z)
{
if (x < y)
return y;
else
return x*z;
}

During taping, the conditional statement may be either true or false, and the result (with its sensitivities) returned by this function. The AD library doesn't just record the parse tree of the operations applied on the branch chosen at the time to taping, but also checks that the condition continues to be satisfied. For some other evaluation of the tape (i.e. for some different inputs x and y), the other branch of the conditional check may be chosen. The result of following this code path has not been recorded on the tape, and therefore cannot be evaluated. In such a case, the underlying AD library will be able to tell you that it is necessary to re-record the tape at the new evaluation point in order to resolve the new code branch. This function can be used to find out whether this is so.

For the output of this function to be meaningful, it must be called after activate_recorded_tape() is called and the new evaluation point for the tape (i.e. values of the independent variables) have been set and subsequently used (i.e. in the determination of the values or derivatives of the dependent variables).

Definition at line 564 of file ad_helpers.cc.

◆ clear_active_tape()

void Differentiation::AD::HelperBase< ADNumberTypeCode, double >::clear_active_tape ( )
inherited

Clears and removes the currently active tape.

This is typically only necessary when branch switching is detected on the original tape at evaluation point. This state can be checked using the active_tape_requires_retaping() function.

Definition at line 574 of file ad_helpers.cc.

◆ activate_tape()

void Differentiation::AD::HelperBase< ADNumberTypeCode, double >::activate_tape ( const typename Types< ad_type >::tape_index tape_index,
const bool read_mode )
protectedinherited

Select a tape to record to or read from.

This function activates a tape, but depending on whether read_mode is set, the tape is either taken as previously written to (and put into read-only mode), or cleared for (re-)taping.

Parameters
[in]tape_indexThe index of the tape to be written to/read from.
[in]read_modeA flag that marks whether or not we expect to read data from a preexisting tape.
Note
The chosen tape index must be greater than Numbers<ad_type>::invalid_tape_index and less than Numbers<ad_type>::max_tape_index.

Definition at line 617 of file ad_helpers.cc.

◆ reset_registered_independent_variables()

void Differentiation::AD::HelperBase< ADNumberTypeCode, double >::reset_registered_independent_variables ( )
protectedinherited

Reset the boolean vector registered_independent_variable_values that indicates which independent variables we've been manipulating for the current set of operations.

Definition at line 664 of file ad_helpers.cc.

◆ mark_independent_variable()

void Differentiation::AD::HelperBase< ADNumberTypeCode, double >::mark_independent_variable ( const unsigned int index,
ad_type & out ) const
protectedinherited

Initialize an independent variable \(X_{i}\) such that subsequent operations performed with it are tracked.

Note
Care must be taken to mark each independent variable only once.
The order in which the independent variables are marked defines the order of all future internal operations. They must be manipulated in the same order as that in which they are first marked. If not then, for example, ADOL-C won't throw an error, but rather it might complain nonsensically during later computations or produce garbage results.
Parameters
[in]indexThe index in the vector of independent variables.
[out]outAn auto-differentiable number that is ready for use in computations. The operations that are performed with it are recorded on the tape and will be considered in the computation of dependent variable values.

Definition at line 694 of file ad_helpers.cc.

◆ finalize_sensitive_independent_variables()

void Differentiation::AD::HelperBase< ADNumberTypeCode, double >::finalize_sensitive_independent_variables ( ) const
protectedinherited

Finalize the state of the independent variables before use.

This step and the storage of the independent variables is done separately because some derived classes may offer the capability to add independent variables in a staggered manner. This function is to be triggered when these values are considered finalized and we can safely initialize the sensitive equivalents of those values.

Definition at line 707 of file ad_helpers.cc.

◆ initialize_non_sensitive_independent_variable()

void Differentiation::AD::HelperBase< ADNumberTypeCode, double >::initialize_non_sensitive_independent_variable ( const unsigned int index,
ad_type & out ) const
protectedinherited

Initialize an independent variable \(X_{i}\).

Parameters
[out]outAn auto-differentiable number that is ready for use in standard computations. The operations that are performed with it are not recorded on the tape, and so should only be used when not in recording mode.
[in]indexThe index in the vector of independent variables.

Definition at line 719 of file ad_helpers.cc.

◆ n_registered_independent_variables()

unsigned int Differentiation::AD::HelperBase< ADNumberTypeCode, double >::n_registered_independent_variables ( ) const
protectedinherited

The number of independent variables that have been manipulated within a set of operations.

Definition at line 727 of file ad_helpers.cc.

◆ reset_registered_dependent_variables()

void Differentiation::AD::HelperBase< ADNumberTypeCode, double >::reset_registered_dependent_variables ( const bool flag = false)
protectedinherited

Reset the boolean vector registered_marked_dependent_variables that indicates which independent variables have been manipulated by the current set of operations. All entries in the vector are set to the value of the flag.

Definition at line 762 of file ad_helpers.cc.

◆ n_registered_dependent_variables()

unsigned int Differentiation::AD::HelperBase< ADNumberTypeCode, double >::n_registered_dependent_variables ( ) const
protectedinherited

The number of dependent variables that have been registered.

Definition at line 768 of file ad_helpers.cc.

◆ register_dependent_variable() [2/2]

void Differentiation::AD::HelperBase< ADNumberTypeCode, double >::register_dependent_variable ( const unsigned int index,
const ad_type & func )
protectedinherited

Register the definition of the index'th dependent variable \(f(\mathbf{X})\).

Parameters
[in]indexThe index of the entry in the global list of dependent variables that this function belongs to.
[in]funcThe recorded function that defines a dependent variable.
Note
Each dependent variable must only be registered once.

Definition at line 782 of file ad_helpers.cc.

Member Data Documentation

◆ dimension

unsigned int Differentiation::AD::PointLevelFunctionsBase< dim, ADNumberTypeCode, double >::dimension
staticconstexprinherited

Type definition for the dimension of the associated input and output tensor types.

Definition at line 2647 of file ad_helpers.h.

◆ symmetric_independent_variables

std::vector<bool> Differentiation::AD::PointLevelFunctionsBase< dim, ADNumberTypeCode, double >::symmetric_independent_variables
privateinherited

The independent variables for which we must take into account symmetry when extracting their gradient or Hessian values.

Definition at line 2951 of file ad_helpers.h.

◆ taped_driver

TapedDrivers<ad_type, scalar_type> Differentiation::AD::HelperBase< ADNumberTypeCode, double >::taped_driver
protectedinherited

An object used to help manage stored tapes.

In the event that the ad_type is a tapeless AD type, then the object constructed here is, effectively, a dummy one.

Definition at line 590 of file ad_helpers.h.

◆ tapeless_driver

TapelessDrivers<ad_type, scalar_type> Differentiation::AD::HelperBase< ADNumberTypeCode, double >::tapeless_driver
protectedinherited

An object used to help manage tapeless data structures.

In the event that the ad_type is a taped AD type, then the object constructed here is, effectively, a dummy one.

Definition at line 598 of file ad_helpers.h.

◆ independent_variable_values

std::vector<scalar_type> Differentiation::AD::HelperBase< ADNumberTypeCode, double >::independent_variable_values
mutableprotectedinherited

A set of independent variables \(\mathbf{X}\) that differentiation will be performed with respect to.

The gradients and Hessians of dependent variables will be computed at these finite values.

Definition at line 634 of file ad_helpers.h.

◆ independent_variables

std::vector<ad_type> Differentiation::AD::HelperBase< ADNumberTypeCode, double >::independent_variables
mutableprotectedinherited

A set of sensitive independent variables \(\mathbf{X}\) that differentiation will be performed with respect to.

The gradients and Hessians of dependent variables will be computed using these configured AD numbers. Note that only reverse-mode AD requires that the sensitive independent variables be stored.

Definition at line 644 of file ad_helpers.h.

◆ registered_independent_variable_values

std::vector<bool> Differentiation::AD::HelperBase< ADNumberTypeCode, double >::registered_independent_variable_values
protectedinherited

A list of registered independent variables that have been manipulated for a given set of operations.

Definition at line 650 of file ad_helpers.h.

◆ registered_marked_independent_variables

std::vector<bool> Differentiation::AD::HelperBase< ADNumberTypeCode, double >::registered_marked_independent_variables
mutableprotectedinherited

A list of registered independent variables that have been extracted and their sensitivities marked.

Definition at line 656 of file ad_helpers.h.

◆ dependent_variables

std::vector<ad_type> Differentiation::AD::HelperBase< ADNumberTypeCode, double >::dependent_variables
protectedinherited

The set of dependent variables \(\mathbf{f}(\mathbf{X})\) of which the derivatives with respect to \(\mathbf{X}\) will be computed.

The gradients and Hessians of these dependent variables will be computed at the values \(\mathbf{X}\) set with the set_sensitivity_value() function.

Note
These are stored as an ad_type so that we can use them to compute function values and directional derivatives in the case that tapeless numbers are used

Definition at line 748 of file ad_helpers.h.

◆ registered_marked_dependent_variables

std::vector<bool> Differentiation::AD::HelperBase< ADNumberTypeCode, double >::registered_marked_dependent_variables
protectedinherited

A list of registered dependent variables.

Definition at line 753 of file ad_helpers.h.


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