37#include "../../expressions/logic/helpers/forEachLeafLogic.hpp"
38#include "../../expressions/aggregate/aggregatedActiveType.hpp"
39#include "../../misc/enumBitset.hpp"
40#include "../indices/indexManagerInterface.hpp"
41#include "../interfaces/fullTapeInterface.hpp"
42#include "../misc/adjointVectorAccess.hpp"
49 template<
typename Real,
typename Tag>
60 template<
typename Real,
typename Tag>
91 template<
typename T_Real,
typename T_Tag,
typename T_Gradient,
typename T_Impl>
156 template<
typename Node>
160 tape.verifyRhsAccess(
node.getValue(), tagData,
vi);
162 isActive |= tagData.
tag != 0;
168 std::swap(
curTag, other.curTag);
175 std::swap(
vi, other.vi);
206 template<
typename Real>
213 template<
typename Real>
219 template<
typename Aggregated,
typename Type,
typename Lhs,
typename Rhs>
224 int constexpr Elements = AggregatedTraits::Elements;
226 std::array<bool, Elements> isActive = {};
228 Aggregated
real = rhs.
cast().getValue();
231 ValidateTags validate;
241 lhs.
values[i.value].value() = AggregatedTraits::template arrayAccess<i.value>(
real);
247 template<
typename Aggregated,
typename Type,
typename Lhs,
typename Rhs>
254 template<
typename Lhs,
typename Rhs>
256 ValidateTags validate;
257 bool isActive =
false;
258 validate.eval(rhs,
vi, cast(), isActive);
265 lhs.
cast().value() = rhs.
cast().getValue();
269 template<
typename Lhs,
typename Rhs>
276 template<
typename Lhs>
282 lhs.
cast().value() = rhs;
306 template<
typename Lhs>
308 return value.
cast().getTapeData().tag;
312 template<
typename Lhs>
314 value.
cast().getTapeData().tag = this->curTag;
318 template<
typename Lhs>
320 value.
cast().getTapeData().tag =
Tag();
324 template<
typename Lhs>
326 value.
cast().getTapeData().properties.reset();
330 template<
typename Lhs>
332 value.
cast().getTapeData().properties.set(flag);
336 template<
typename Lhs>
338 return value.
cast().getTapeData().properties.test(flag);
390 return {
false,
true, 0, flag, value, newValue};
428 if (lhsValue != rhsValue) {
437 template<
typename Lhs>
450 std::cerr <<
"Property error '" << std::to_string(flag) <<
"' on value. current value: " << currentValue
451 <<
" new value: " << newValue <<
"" << std::endl;
459 std::cerr <<
"Use of variable with bad tag '" << wrongTag <<
"', should be '" << correctTag <<
"'.";
461 std::cerr <<
" The value seems to be a preaccumulation output.";
463 std::cerr <<
" The value seems to be used during a preaccumulation but is not declared as an input.";
465 std::cerr << std::endl;
512 return static_cast<Impl&
>(*this);
#define CODI_LAMBDA_INLINE
See codi::Config::ForcedInlines.
Definition config.h:473
#define CODI_INLINE
See codi::Config::ForcedInlines.
Definition config.h:469
#define CODI_DD(Type, Default)
Abbreviation for CODI_DECLARE_DEFAULT.
Definition macros.hpp:97
CoDiPack - Code Differentiation Package.
Definition codi.hpp:98
inlinevoid static_for(F func, Args &&... args)
Static for with i = 0 .. (N - 1). See CompileTimeLoop for details.
Definition compileTimeLoop.hpp:110
typename ArrayAccessExpressionImpl< Aggregated, element >::template Expression< Arg > ArrayAccessExpression
Expression that performs a[element] in a compile time context.
Definition arrayAccessExpression.hpp:98
inlineauto real(ExpressionInterface< std::complex< Real >, Arg > const &arg)
Function overload for FUNCTION.
Definition allOperators.hpp:75
inlinevoid CODI_UNUSED(Args const &...)
Disable unused warnings for an arbitrary number of arguments.
Definition macros.hpp:55
TagFlags
Properties for values.
Definition tagData.hpp:46
@ DoNotChange
DoNotChange: Value can be assigned, but it should not change.
Definition tagData.hpp:47
@ DoNotWrite
DoNotWrite: Value can not be assigned.
Definition tagData.hpp:48
@ DoNotUse
Definition tagData.hpp:49
@ MaxElement
Maximum number of elements.
Definition tagData.hpp:51
InnerActiveType values[Elements]
Array representation.
Definition aggregatedActiveType.hpp:75
Represents a concrete aggregated lvalue int the CoDiPack expression tree.
Definition aggregatedActiveType.hpp:164
Base class for all CoDiPack expressions.
Definition expressionInterface.hpp:60
inlineImpl const & cast() const
Cast to the implementation.
Definition expressionInterface.hpp:76
Implement logic for leaf nodes only.
Definition forEachLeafLogic.hpp:60
ValidateTags Impl
Definition forEachLeafLogic.hpp:63
Base class for all CoDiPack lvalue expression.
Definition lhsExpressionInterface.hpp:63
inlineImpl & cast()
Cast to the implementation.
Definition lhsExpressionInterface.hpp:103
Methods that access inner values of aggregated types that contain CoDiPack active types.
Definition realTraits.hpp:233
Data for a tag.
Definition tagData.hpp:56
Tag tag
Current tag of the value.
Definition tagData.hpp:61
void setTagPropertyOnVariable(LhsExpressionInterface< Real, Gradient, Impl, Lhs > &value, TagFlags flag)
Set properties on a CoDiPack active type.
Definition tagTapeBase.hpp:331
inlinevoid setTag(Tag &tag) const
Set tag on value.
Definition tagTapeBase.hpp:499
void * tagPropertyErrorUserData
Definition tagTapeBase.hpp:119
inlineTag getPreaccumulationHandlingTag()
The special tag for preaccumulation.
Definition tagTapeBase.hpp:377
ValidationEntry< Real, Tag > makeProeprtyError(TagFlags flag, Real const *value, Real newValue={})
Create a property error entry.
Definition tagTapeBase.hpp:389
Identifier tempIdentifier
Definition tagTapeBase.hpp:130
void clearTagOnVariable(LhsExpressionInterface< Real, Gradient, Impl, Lhs > &value)
Clear tag on a CoDiPack active type.
Definition tagTapeBase.hpp:319
static bool constexpr AllowJacobianOptimization
Definition tagTapeBase.hpp:203
ValidationIndicator< Real, Tag > vi
Definition tagTapeBase.hpp:134
static void defaultErrorCallback(ValidationEntry< Real, Tag > const &data, Tag const &curTag, void *userData)
Default callback for ErrorCallback. (Currently not used)
Definition tagTapeBase.hpp:469
TagErrorCallback tagErrorCallback
Definition tagTapeBase.hpp:121
void destroyTapeData(Real &value, ActiveTypeTapeData &data)
Do nothing.
Definition tagTapeBase.hpp:214
void store(LhsExpressionInterface< Real, Gradient, Impl, Lhs > &lhs, ExpressionInterface< Real, Rhs > const &rhs)
Verify all tags of the rhs and properties from the lhs and rhs.
Definition tagTapeBase.hpp:255
T_Impl Impl
See TagTapeBase.
Definition tagTapeBase.hpp:96
void(*)(Tag const &correctTag, Tag const &wrongTag, void *userData) TagErrorCallback
Callback for a tag error.
Definition tagTapeBase.hpp:106
Tag curTag
Current tag for new values.
Definition tagTapeBase.hpp:116
void(*)(ValidationEntry< Real, Tag > const &data, Tag const &curTag, void *userData) ErrorCallback
Callback for all errors.
Definition tagTapeBase.hpp:109
void setTagErrorCallback(TagErrorCallback const &callback, void *userData)
Set the callback and user data for a tag error.
Definition tagTapeBase.hpp:348
inlinevoid handleError(ValidationIndicator< Real, Tag > &vi) const
Call tag error callback.
Definition tagTapeBase.hpp:479
T_Tag Tag
See TagTapeBase.
Definition tagTapeBase.hpp:94
void setTagOnVariable(LhsExpressionInterface< Real, Gradient, Impl, Lhs > const &value)
Set tag on a CoDiPack active type.
Definition tagTapeBase.hpp:313
inlinevoid verifyRegisterValue(LhsExpressionInterface< Real, Gradient, Impl, Lhs > &value)
Verify tag, properties and lhs error.
Definition tagTapeBase.hpp:438
inlinebool isPreaccumulationHandlingEnabled()
If handling for preaccumulation is enabled.
Definition tagTapeBase.hpp:372
bool preaccumulationHandling
Definition tagTapeBase.hpp:127
inlineIdentifier const & getIdentifier(ActiveTypeTapeData const &data)
Definition tagTapeBase.hpp:184
TagTapeBase()
Constructor.
Definition tagTapeBase.hpp:140
Tag getTagFromVariable(LhsExpressionInterface< Real, Gradient, Impl, Lhs > &value)
Get tag of a CoDiPack active type.
Definition tagTapeBase.hpp:307
inlinevoid setPreaccumulationHandlingTag(Tag tag)
Set the special tag for preaccumulation regions. See setPreaccumulationHandlingEnabled().
Definition tagTapeBase.hpp:367
static void defaultPropertyErrorCallback(Real const ¤tValue, Real const &newValue, TagFlags flag, void *userData)
Definition tagTapeBase.hpp:446
T_Real Real
See TagTapeBase.
Definition tagTapeBase.hpp:93
inlinevoid resetTag(Tag &tag) const
Reset tag on value.
Definition tagTapeBase.hpp:504
void clearTagPropertiesOnVariable(LhsExpressionInterface< Real, Gradient, Impl, Lhs > &value)
Clear properties on a CoDiPack active type.
Definition tagTapeBase.hpp:325
ValidationEntry< Real, Tag > makeTagError(Tag tag, Real const *value)
Create a tag error entry.
Definition tagTapeBase.hpp:384
void store(LhsExpressionInterface< Real, Gradient, Impl, Lhs > &lhs, LhsExpressionInterface< Real, Gradient, Impl, Rhs > const &rhs)
Verify all tags of the rhs and the lhs properties.
Definition tagTapeBase.hpp:270
TagPropertyErrorCallback tagPropertyErrorCallback
Definition tagTapeBase.hpp:118
void verifyRhsAccessForTag(Real const &value, ActiveTypeTapeData const &data, ValidationIndicator< Real, Tag > &vi)
Check tag errors. Raises an error for tags that are not equal to the current tag. Ignores passive tag...
Definition tagTapeBase.hpp:410
inlinevoid setPreaccumulationHandlingEnabled(bool enabled)
Enable or disable specialized handling for preaccumulation. Default: true Uses a special tag to sanit...
Definition tagTapeBase.hpp:362
Identifier const activeIdentifier
Definition tagTapeBase.hpp:131
inlinevoid store(AggregatedActiveType< Aggregated, Type, Lhs > &lhs, AggregatedActiveType< Aggregated, Type, Rhs > const &rhs)
Has to be called by an AD variable every time it is assigned.
Definition tagTapeBase.hpp:248
static Tag constexpr PassiveTag
Definition tagTapeBase.hpp:111
void store(LhsExpressionInterface< Real, Gradient, Impl, Lhs > &lhs, Real const &rhs)
Verify the lhs properties.
Definition tagTapeBase.hpp:277
Identifier const passiveIdentifier
Definition tagTapeBase.hpp:132
void * errorUserData
Definition tagTapeBase.hpp:125
void setTagPropertyErrorCallback(TagPropertyErrorCallback const &callback, void *userData)
Set the callback and user data for a property error error.
Definition tagTapeBase.hpp:342
T_Gradient Gradient
See TagTapeBase.
Definition tagTapeBase.hpp:95
ErrorCallback errorCallback
Definition tagTapeBase.hpp:124
int Identifier
See TapeTypesInterface.
Definition tagTapeBase.hpp:98
static void defaultTagErrorCallback(Tag const &correctTag, Tag const &wrongTag, void *userData)
Definition tagTapeBase.hpp:455
void setErrorCallback(ErrorCallback const &callback, void *userData)
Definition tagTapeBase.hpp:355
void setDoActivityAnalysis(bool active)
Enable or disable the activity analysis for the tags. Disabling will mark all active types with the c...
Definition tagTapeBase.hpp:291
void initTapeData(Real &value, ActiveTypeTapeData &data)
Do nothing.
Definition tagTapeBase.hpp:207
void verifyRhsAccessForProperty(Real const &value, ActiveTypeTapeData const &data, ValidationIndicator< Real, Tag > &vi)
Check properties for rhs values. Validates the 'DoNotUse' property.
Definition tagTapeBase.hpp:419
static Tag constexpr InvalidTag
Definition tagTapeBase.hpp:112
Tag getCurTag()
Get the current tag of the tape.
Definition tagTapeBase.hpp:301
TagData< Tag > ActiveTypeTapeData
See TapeTypesInterface.
Definition tagTapeBase.hpp:99
inlineIdentifier & getIdentifier(ActiveTypeTapeData &data)
Definition tagTapeBase.hpp:193
bool hasTagPropertyOnVariable(LhsExpressionInterface< Real, Gradient, Impl, Lhs > &value, TagFlags flag)
Check properties on a CoDiPack active type.
Definition tagTapeBase.hpp:337
void updateLhsTagData(ActiveTypeTapeData &lhsData, bool isActive) const
Update the tag data for a lhs write. Updates the properties and sets the tag based on the activity.
Definition tagTapeBase.hpp:394
inlinevoid store(AggregatedActiveType< Aggregated, Type, Lhs > &lhs, ExpressionInterface< Aggregated, Rhs > const &rhs)
Verify all tags of the rhs and properties from the lhs and rhs.
Definition tagTapeBase.hpp:220
void setCurTag(const Tag &tag)
Set the current tag of the tape.
Definition tagTapeBase.hpp:296
inlinevoid verifyLhsWrite(Real const &lhsValue, ActiveTypeTapeData const &lhsData, Real const &rhsValue, ValidationIndicator< Real, Tag > &vi)
Validates the lhs properties.
Definition tagTapeBase.hpp:426
Tag preaccumulationTag
Definition tagTapeBase.hpp:128
void verifyRhsAccess(Real const &value, ActiveTypeTapeData const &data, ValidationIndicator< Real, Tag > &vi)
Check tag and property errors.
Definition tagTapeBase.hpp:404
void swap(Impl &other)
Swap members.
Definition tagTapeBase.hpp:167
void(*)(Real const ¤tValue, Real const &newValue, TagFlags flag, void *userData) TagPropertyErrorCallback
Callback for a change in a lhs value.
Definition tagTapeBase.hpp:102
void * tagErrorUserData
Definition tagTapeBase.hpp:122
bool doActivityAnalysis
Definition tagTapeBase.hpp:135
inlinevoid node(Node const &node, Args &&... args)
Definition traversalLogic.hpp:87
Helper class for statement validation.
Definition tagTapeBase.hpp:50
TagFlags propertyError
Wrong property.
Definition tagTapeBase.hpp:54
Real newValue
New value for property errors.
Definition tagTapeBase.hpp:56
Tag tagError
Wrong tag.
Definition tagTapeBase.hpp:53
Real const * value
Address of the offending value.
Definition tagTapeBase.hpp:55
bool isTagError
true if the tag on the value is wrong.
Definition tagTapeBase.hpp:51
bool isPropertyError
true if a property on the value is wrong.
Definition tagTapeBase.hpp:52
Helper class for statement validation.
Definition tagTapeBase.hpp:61
bool hasError()
Test if there is an error.
Definition tagTapeBase.hpp:76
void reset()
Clear all errors.
Definition tagTapeBase.hpp:71
std::vector< ValidationEntry< Real, Tag > > errorEntries
Stores all problematic entries.
Definition tagTapeBase.hpp:63
void addEntry(ValidationEntry< Real, Tag > const &entry)
Add a new entry.
Definition tagTapeBase.hpp:66