CoDiPack  3.1.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-2026 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 CallbackFuncTyped = typename Base::CallbackFuncTyped;
67
68 using OpHelper =
69 medi::OperatorHelper<medi::FunctionHelper<Type, Type, typename Type::PassiveReal, typename Type::Identifier,
70 typename Type::Gradient, CoDiPackForwardTool<Type> > >;
71
72 private:
73 OpHelper opHelper;
74
75 public:
76
77 CoDiPackForwardTool(MPI_Datatype primalMpiType, MPI_Datatype adjointMpiType)
78 : Base(primalMpiType, adjointMpiType), opHelper() {
79 opHelper.init();
80 }
81
82 ~CoDiPackForwardTool() {
83 opHelper.finalize();
84 }
85
86 CODI_INLINE_NO_FA bool isActiveType() const {
87 return false;
88 }
89
90 CODI_INLINE_NO_FA bool isHandleRequired() const {
91 return false;
92 }
93
94 CODI_INLINE_NO_FA bool isModifiedBufferRequired() const {
95 return false;
96 }
97
98 CODI_INLINE_NO_FA bool isOldPrimalsRequired() const {
99 return false;
100 }
101
102 CODI_INLINE_NO_FA void startAssembly(medi::HandleBase* h) const {
103 CODI_UNUSED(h);
104 }
105
106 CODI_INLINE_NO_FA void addToolAction(medi::HandleBase* h) const {
107 CODI_UNUSED(h);
108 }
109
110 CODI_INLINE_NO_FA void stopAssembly(medi::HandleBase* h) const {
111 CODI_UNUSED(h);
112 }
113
114 medi::AMPI_Op convertOperator(medi::AMPI_Op op) const {
115 return opHelper.convertOperator(op);
116 }
117
118 CODI_INLINE_NO_FA void createPrimalTypeBuffer(PrimalType*& buf, size_t size) const {
119 buf = new PrimalType[size];
120 }
121
122 CODI_INLINE_NO_FA void createIndexTypeBuffer(IndexType*& buf, size_t size) const {
123 buf = new IndexType[size];
124 }
125
126 CODI_INLINE_NO_FA void deletePrimalTypeBuffer(PrimalType*& buf) const {
127 if (nullptr != buf) {
128 delete[] buf;
129 buf = nullptr;
130 }
131 }
132
133 CODI_INLINE_NO_FA void deleteIndexTypeBuffer(IndexType*& buf) const {
134 if (nullptr != buf) {
135 delete[] buf;
136 buf = nullptr;
137 }
138 }
139
140 static CODI_INLINE_NO_FA int getIndex(Type const& value) {
141 return value.getIdentifier();
142 }
143
144 static CODI_INLINE_NO_FA void clearIndex(Type& value) {
145 value.~Type();
146 value.getIdentifier() = 0;
147 }
148
149 static CODI_INLINE_NO_FA void createIndex(Type& value, int& index) {
150 CODI_UNUSED(value);
151 index = 0;
152 }
153
154 static CODI_INLINE_NO_FA PrimalType getValue(Type const& value) {
155 return value.getValue();
156 }
157
158 using Base::iterateIdentifiers;
159 void iterateIdentifiers(IndexType* indices, int elements, CallbackFuncTyped func, void* userData) const {
160 for (int i = 0; i < elements; i += 1) {
161 func(&indices[i], userData);
162 }
163 }
164
165 static CODI_INLINE_NO_FA void setIntoModifyBuffer(ModifiedType& modValue, Type const& value) {
166 CODI_UNUSED(modValue, value);
167 }
168
169 static CODI_INLINE_NO_FA void getFromModifyBuffer(ModifiedType const& modValue, Type& value) {
170 CODI_UNUSED(modValue, value);
171 }
172
173 static CODI_INLINE_NO_FA void registerValue(Type& value, PrimalType& oldValue, int& index) {
174 CODI_UNUSED(value, oldValue, index);
175 }
176
177 static PrimalType getPrimalFromMod(ModifiedType const& modValue) {
178 return modValue.value();
179 }
180
181 static void setPrimalToMod(ModifiedType& modValue, PrimalType const& value) {
182 modValue.value() = value;
183 }
184
185 static void modifyDependency(ModifiedType& inval, ModifiedType& inoutval) {
186 CODI_UNUSED(inval, inoutval);
187 }
188 };
189#endif
190}
#define CODI_INLINE_NO_FA
See codi::Config::ForcedInlines.
Definition config.h:471
#define CODI_DD(Type, Default)
Abbreviation for CODI_DECLARE_DEFAULT.
Definition macros.hpp:97
inlinetypename DataExtraction< Type >::Real getValue(Type const &v)
Extract an aggregate of primal values from an aggregate of active types.
Definition realTraits.hpp:381
CoDiPack - Code Differentiation Package.
Definition codi.hpp:97
inlinevoid CODI_UNUSED(Args const &...)
Disable unused warnings for an arbitrary number of arguments.
Definition macros.hpp:55