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