CoDiPack  2.2.0
A Code Differentiation Package
SciComp TU Kaiserslautern
Loading...
Searching...
No Matches
jacobianInterface.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 "../../config.h"
38#include "../../misc/macros.hpp"
39#include "../../traits/misc/enableIfHelpers.hpp"
40
42namespace codi {
43
53 template<typename T_T>
55 public:
56
57 using T = CODI_DD(T_T, double);
58
59 size_t getM() const;
60 size_t getN() const;
61
63 T operator()(size_t const i, size_t const j) const;
64
66 T& operator()(size_t const i, size_t const j);
67
68 void resize(size_t const m, size_t const n);
69 size_t size() const;
70
72 void setLogic(size_t const i, size_t const j, T const& v);
73 };
74
83 template<typename Stream, typename Jac, typename = enable_if_base_of<Jac, JacobianInterface<typename Jac::T>>>
84 Stream& operator<<(Stream& out, CODI_DD(Jac, CODI_T(JacobianInterface<double>)) const& jacobian) {
85 out << "[";
86 for (size_t i = 0; i < jacobian.getM(); ++i) {
87 if (i != 0) {
88 out << " "; // Padding for the '['.
89 }
90
91 for (size_t j = 0; j < jacobian.getN(); ++j) {
92 if (j != 0) {
93 out << ", ";
94 }
95 out << jacobian(i, j);
96 }
97
98 if (i + 1 < jacobian.getM()) {
99 out << ";\n";
100 } else {
101 out << "]";
102 }
103 }
104
105 return out;
106 }
107}
#define CODI_DD(Type, Default)
Abbreviation for CODI_DECLARE_DEFAULT.
Definition macros.hpp:94
#define CODI_T(...)
Abbreviation for CODI_TEMPLATE.
Definition macros.hpp:111
CoDiPack - Code Differentiation Package.
Definition codi.hpp:90
ExpressionTraits::EnableIfExpression< Expr, std::ostream > & operator<<(std::ostream &out, Expr const &v)
Write the primal value to the stream.
Definition expressionInterface.hpp:129
General interface for Jacobian access in CoDiPack.
Definition jacobianInterface.hpp:54
T operator()(size_t const i, size_t const j) const
Value access, i in [0, ..., m), j in [0, ..., n).
void resize(size_t const m, size_t const n)
Resize the Jacobian.
size_t getM() const
Get size of rows (output variables).
void setLogic(size_t const i, size_t const j, T const &v)
Interface for the JacobianDelayAccessor.
T & operator()(size_t const i, size_t const j)
Reference access, i in [0, ..., m), j in [0, ..., n).
size_t size() const
Get total size of the Jacobian.
size_t getN() const
Get size of columns (input variables).
T_T T
See JacobianInterface.
Definition jacobianInterface.hpp:57