CoDiPack  2.2.0
A Code Differentiation Package
SciComp TU Kaiserslautern
Loading...
Searching...
No Matches
codiForwardMeDiPackTool.hpp
1/*
2 * CoDiPack, a Code Differentiation Package
3 *
4 * Copyright (C) 2015-2024 Chair for Scientific Computing (SciComp), University of Kaiserslautern-Landau
5 * Homepage: http://scicomp.rptu.de
6 * Contact: Prof. Nicolas R. Gauger (codi@scicomp.uni-kl.de)
7 *
8 * Lead developers: Max Sagebaum, Johannes Blühdorn (SciComp, University of Kaiserslautern-Landau)
9 *
10 * This file is part of CoDiPack (http://scicomp.rptu.de/software/codi).
11 *
12 * CoDiPack is free software: you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, either version 3 of the
15 * License, or (at your option) any later version.
16 *
17 * CoDiPack is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty
19 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20 *
21 * See the GNU General Public License for more details.
22 * You should have received a copy of the GNU
23 * General Public License along with CoDiPack.
24 * If not, see <http://www.gnu.org/licenses/>.
25 *
26 * For other licensing options please contact us.
27 *
28 * Authors:
29 * - SciComp, University of Kaiserslautern-Landau:
30 * - Max Sagebaum
31 * - Johannes Blühdorn
32 * - Former members:
33 * - Tim Albring
34 */
35#pragma once
36
37#include <medi/adToolInterface.h>
38#include <medi/ampi/ampiMisc.h>
39
40#include <medi/ampi/typeDefault.hpp>
41#include <medi/ampi/types/indexTypeHelper.hpp>
42
43#include "../../config.h"
44#include "../../expressions/lhsExpressionInterface.hpp"
45#include "../../misc/macros.hpp"
46
48namespace codi {
49
50#ifndef DOXYGEN_DISABLE
51
52 template<typename T_Type>
53 struct CoDiPackForwardTool : public medi::ADToolBase<CoDiPackForwardTool<T_Type>, typename T_Type::Gradient,
54 typename T_Type::PassiveReal, int> {
55 public:
56
57 using Type = CODI_DD(T_Type, CODI_DEFAULT_LHS_EXPRESSION);
58
59 using PrimalType = typename Type::Real;
60 using AdjointType = void;
61 using ModifiedType = Type;
62 using IndexType = int;
63
64 using Base = medi::ADToolBase<CoDiPackForwardTool, typename Type::Gradient, typename Type::PassiveReal, int>;
65
66 using OpHelper =
67 medi::OperatorHelper<medi::FunctionHelper<Type, Type, typename Type::PassiveReal, typename Type::Identifier,
68 typename Type::Gradient, CoDiPackForwardTool<Type> > >;
69
70 private:
71 OpHelper opHelper;
72
73 public:
74
75 CoDiPackForwardTool(MPI_Datatype primalMpiType, MPI_Datatype adjointMpiType)
76 : Base(primalMpiType, adjointMpiType), opHelper() {
77 opHelper.init();
78 }
79
80 ~CoDiPackForwardTool() {
81 opHelper.finalize();
82 }
83
84 CODI_INLINE_NO_FA bool isActiveType() const {
85 return false;
86 }
87
88 CODI_INLINE_NO_FA bool isHandleRequired() const {
89 return false;
90 }
91
92 CODI_INLINE_NO_FA bool isModifiedBufferRequired() const {
93 return false;
94 }
95
96 CODI_INLINE_NO_FA bool isOldPrimalsRequired() const {
97 return false;
98 }
99
100 CODI_INLINE_NO_FA void startAssembly(medi::HandleBase* h) const {
101 CODI_UNUSED(h);
102 }
103
104 CODI_INLINE_NO_FA void addToolAction(medi::HandleBase* h) const {
105 CODI_UNUSED(h);
106 }
107
108 CODI_INLINE_NO_FA void stopAssembly(medi::HandleBase* h) const {
109 CODI_UNUSED(h);
110 }
111
112 medi::AMPI_Op convertOperator(medi::AMPI_Op op) const {
113 return opHelper.convertOperator(op);
114 }
115
116 CODI_INLINE_NO_FA void createPrimalTypeBuffer(PrimalType*& buf, size_t size) const {
117 buf = new PrimalType[size];
118 }
119
120 CODI_INLINE_NO_FA void createIndexTypeBuffer(IndexType*& buf, size_t size) const {
121 buf = new IndexType[size];
122 }
123
124 CODI_INLINE_NO_FA void deletePrimalTypeBuffer(PrimalType*& buf) const {
125 if (nullptr != buf) {
126 delete[] buf;
127 buf = nullptr;
128 }
129 }
130
131 CODI_INLINE_NO_FA void deleteIndexTypeBuffer(IndexType*& buf) const {
132 if (nullptr != buf) {
133 delete[] buf;
134 buf = nullptr;
135 }
136 }
137
138 static CODI_INLINE_NO_FA int getIndex(Type const& value) {
139 return value.getIdentifier();
140 }
141
142 static CODI_INLINE_NO_FA void clearIndex(Type& value) {
143 value.~Type();
144 value.getIdentifier() = 0;
145 }
146
147 static CODI_INLINE_NO_FA void createIndex(Type& value, int& index) {
148 CODI_UNUSED(value);
149 index = 0;
150 }
151
152 static CODI_INLINE_NO_FA PrimalType getValue(Type const& value) {
153 return value.getValue();
154 }
155
156 static CODI_INLINE_NO_FA void setIntoModifyBuffer(ModifiedType& modValue, Type const& value) {
157 CODI_UNUSED(modValue, value);
158 }
159
160 static CODI_INLINE_NO_FA void getFromModifyBuffer(ModifiedType const& modValue, Type& value) {
161 CODI_UNUSED(modValue, value);
162 }
163
164 static CODI_INLINE_NO_FA void registerValue(Type& value, PrimalType& oldValue, int& index) {
165 CODI_UNUSED(value, oldValue, index);
166 }
167
168 static PrimalType getPrimalFromMod(ModifiedType const& modValue) {
169 return modValue.value();
170 }
171
172 static void setPrimalToMod(ModifiedType& modValue, PrimalType const& value) {
173 modValue.value() = value;
174 }
175
176 static void modifyDependency(ModifiedType& inval, ModifiedType& inoutval) {
177 CODI_UNUSED(inval, inoutval);
178 }
179 };
180#endif
181}
#define CODI_INLINE_NO_FA
See codi::Config::ForcedInlines.
Definition config.h:459
#define CODI_DD(Type, Default)
Abbreviation for CODI_DECLARE_DEFAULT.
Definition macros.hpp:94
DataExtraction< Type >::Real getValue(Type const &v)
Extract the primal values from a type of aggregated active types.
Definition realTraits.hpp:210
CoDiPack - Code Differentiation Package.
Definition codi.hpp:90
void CODI_UNUSED(Args const &...)
Disable unused warnings for an arbitrary number of arguments.
Definition macros.hpp:46