CEPS  24.01
Cardiac ElectroPhysiology Simulator
CepsMathOperations.hpp
Go to the documentation of this file.
1 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2  This file is part of CEPS.
3 
4  CEPS is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  CEPS is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with CEPS (see file LICENSE at root of project).
16  If not, see <https://www.gnu.org/licenses/>.
17 
18 
19  Copyright 2019-2024 Inria, Universite de Bordeaux
20 
21  Authors, in alphabetical order:
22 
23  Pierre-Elliott BECUE, Florian CARO, Yves COUDIERE(*), Andjela DAVIDOVIC,
24  Charlie DOUANLA-LONTSI, Marc FUENTES, Mehdi JUHOOR, Michael LEGUEBE(*),
25  Pauline MIGERDITICHAN, Valentin PANNETIER(*), Nejib ZEMZEMI.
26  * : currently active authors
27 
28 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
31 #pragma once
33 
41 template <class _Left, class _Right>
43 
48 template <>
50 {
52  static CepsMathScalar
53  plus(const CepsMathScalar& l, const CepsMathScalar& r)
54  {
55  return l + r;
56  }
57 
59  static CepsMathScalar
60  minus(const CepsMathScalar& l, const CepsMathScalar& r)
61  {
62  return l - r;
63  }
64 
66  static CepsMathScalar
67  mult(const CepsMathScalar& l, const CepsMathScalar& r)
68  {
69  return l * r;
70  }
71 
73  static CepsMathScalar
74  div(const CepsMathScalar& l, const CepsMathScalar& r)
75  {
76  return l / r;
77  }
78 };
79 
84 template <>
86 {
88  static CepsMathVertex
89  plus(const CepsMathScalar& l, const CepsMathVertex& r)
90  {
91  return l * CepsMathVertex::Ones() + r;
92  }
93 
95  static CepsMathVertex
96  minus(const CepsMathScalar& l, const CepsMathVertex& r)
97  {
98  return l * CepsMathVertex::Ones() - r;
99  }
100 
102  static CepsMathVertex
103  mult(const CepsMathScalar& l, const CepsMathVertex& r)
104  {
105  return l * r;
106  }
107 
109  static CepsMathVertex
110  div(const CepsMathScalar& l, const CepsMathVertex& r)
111  {
112  CEPS_ABORT("operation scalar/vertex is undefined");
113  return r;
114  }
115 };
116 
121 template <>
123 {
125  static CepsMathTensor
126  plus(const CepsMathScalar& l, const CepsMathTensor& r)
127  {
128  return l * CepsMathTensor::Ones() + r;
129  }
130 
132  static CepsMathTensor
133  minus(const CepsMathScalar& l, const CepsMathTensor& r)
134  {
135  return l * CepsMathTensor::Ones() - r;
136  }
137 
139  static CepsMathTensor
140  mult(const CepsMathScalar& l, const CepsMathTensor& r)
141  {
142  return l * r;
143  }
144 
146  static CepsMathTensor
147  div(const CepsMathScalar& l, const CepsMathTensor& r)
148  {
149  CEPS_ABORT("operation scalar/tensor is undefined");
150  return r;
151  }
152 };
153 
158 template <>
160 {
162  static CepsMathVertex
163  plus(const CepsMathVertex& l, const CepsMathScalar& r)
164  {
165  return l + r * CepsMathVertex::Ones();
166  }
167 
169  static CepsMathVertex
170  minus(const CepsMathVertex& l, const CepsMathScalar& r)
171  {
172  return l - r * CepsMathVertex::Ones();
173  }
174 
176  static CepsMathVertex
177  mult(const CepsMathVertex& l, const CepsMathScalar& r)
178  {
179  return l * r;
180  }
181 
183  static CepsMathVertex
184  div(const CepsMathVertex& l, const CepsMathScalar& r)
185  {
186  return l / r;
187  }
188 };
189 
194 template <>
196 {
198  static CepsMathVertex
199  plus(const CepsMathVertex& l, const CepsMathVertex& r)
200  {
201  return l + r;
202  }
203 
205  static CepsMathVertex
206  minus(const CepsMathVertex& l, const CepsMathVertex& r)
207  {
208  return l - r;
209  }
210 
212  static CepsMathScalar
213  mult(const CepsMathVertex& l, const CepsMathVertex& r)
214  {
215  return l.dot(r);
216  }
217 
219  static CepsMathVertex
220  div(const CepsMathVertex& l, const CepsMathVertex& r)
221  {
222  CEPS_ABORT("operation vertex/vertex is undefined");
223  return r;
224  }
225 };
226 
231 template <>
233 {
235  static CepsMathTensor
236  plus(const CepsMathVertex& l, const CepsMathTensor& r)
237  {
238  CEPS_ABORT("operation vertex+tensor is undefined");
239  return r;
240  }
241 
243  static CepsMathTensor
244  minus(const CepsMathVertex& l, const CepsMathTensor& r)
245  {
246  CEPS_ABORT("operation vertex-tensor is undefined");
247  return r;
248  }
249 
251  static CepsMathVertex
252  mult(const CepsMathVertex& l, const CepsMathTensor& r)
253  {
254  return (l.transpose() * r).transpose();
255  }
256 
258  static CepsMathTensor
259  div(const CepsMathVertex& l, const CepsMathTensor& r)
260  {
261  CEPS_ABORT("operation vertex/tensor is undefined");
262  return r;
263  }
264 };
265 
270 template <>
272 {
274  static CepsMathTensor
275  plus(const CepsMathTensor& l, const CepsMathScalar& r)
276  {
277  return l + r * CepsMathTensor::Ones();
278  }
279 
281  static CepsMathTensor
282  minus(const CepsMathTensor& l, const CepsMathScalar& r)
283  {
284  return l - r * CepsMathTensor::Ones();
285  }
286 
288  static CepsMathTensor
289  mult(const CepsMathTensor& l, const CepsMathScalar& r)
290  {
291  return l * r;
292  }
293 
295  static CepsMathTensor
296  div(const CepsMathTensor& l, const CepsMathScalar& r)
297  {
298  return l / r;
299  }
300 };
301 
306 template <>
308 {
310  static CepsMathTensor
311  plus(const CepsMathTensor& l, const CepsMathVertex& r)
312  {
313  CEPS_ABORT("operation tensor+vertex is undefined");
314  return l;
315  }
316 
318  static CepsMathTensor
319  minus(const CepsMathTensor& l, const CepsMathVertex& r)
320  {
321  CEPS_ABORT("operation tensor-vertex is undefined");
322  return l;
323  }
324 
326  static CepsMathVertex
327  mult(const CepsMathTensor& l, const CepsMathVertex& r)
328  {
329  return l * r;
330  }
331 
333  static CepsMathTensor
334  div(const CepsMathTensor& l, const CepsMathVertex& r)
335  {
336  CEPS_ABORT("operation tensor/vertex is undefined");
337  return l;
338  }
339 };
340 
345 template <>
347 {
349  static CepsMathTensor
350  plus(const CepsMathTensor& l, const CepsMathTensor& r)
351  {
352  return l + r;
353  }
354 
356  static CepsMathTensor
357  minus(const CepsMathTensor& l, const CepsMathTensor& r)
358  {
359  return l - r;
360  }
361 
363  static CepsMathTensor
364  mult(const CepsMathTensor& l, const CepsMathTensor& r)
365  {
366  return l * r;
367  }
368 
370  static CepsMathTensor
371  div(const CepsMathTensor& l, const CepsMathTensor& r)
372  {
373  CEPS_ABORT("operation tensor/tensor is undefined");
374  return r;
375  }
376 };
#define CEPS_ABORT(message)
Stops the execution with a message. If testing is enabled, only throws a runtime_error.
CepsScalar CepsMathScalar
Real numbers.
Definition: CepsTypes.hpp:133
Eigen::Matrix< CepsScalar, 3, 3 > CepsMathTensor
Tensor, eigen format.
Definition: CepsTypes.hpp:137
Eigen::Matrix< CepsScalar, 3, 1 > CepsMathVertex
Vertex, eigen format.
Definition: CepsTypes.hpp:135
static CepsMathScalar div(const CepsMathScalar &l, const CepsMathScalar &r)
scalar/scalar -> scalar
static CepsMathScalar minus(const CepsMathScalar &l, const CepsMathScalar &r)
scalar-scalar -> scalar
static CepsMathScalar plus(const CepsMathScalar &l, const CepsMathScalar &r)
scalar+scalar -> scalar
static CepsMathScalar mult(const CepsMathScalar &l, const CepsMathScalar &r)
scalar*scalar -> scalar
static CepsMathTensor plus(const CepsMathScalar &l, const CepsMathTensor &r)
scalar+tensor -> tensor
static CepsMathTensor minus(const CepsMathScalar &l, const CepsMathTensor &r)
scalar-tensor -> tensor
static CepsMathTensor div(const CepsMathScalar &l, const CepsMathTensor &r)
scalar/tensor -> tensor [undefined]
static CepsMathTensor mult(const CepsMathScalar &l, const CepsMathTensor &r)
scalar*tensor -> tensor
static CepsMathVertex div(const CepsMathScalar &l, const CepsMathVertex &r)
scalar/vertex -> vertex [undefined]
static CepsMathVertex plus(const CepsMathScalar &l, const CepsMathVertex &r)
scalar+vertex -> vertex
static CepsMathVertex minus(const CepsMathScalar &l, const CepsMathVertex &r)
scalar-vertex -> vertex
static CepsMathVertex mult(const CepsMathScalar &l, const CepsMathVertex &r)
scalar*vertex -> vertex
static CepsMathTensor div(const CepsMathTensor &l, const CepsMathScalar &r)
tensor/scalar -> tensor
static CepsMathTensor minus(const CepsMathTensor &l, const CepsMathScalar &r)
tensor-scalar -> tensor
static CepsMathTensor plus(const CepsMathTensor &l, const CepsMathScalar &r)
tensor+scalar -> tensor
static CepsMathTensor mult(const CepsMathTensor &l, const CepsMathScalar &r)
tensor*scalar -> tensor
static CepsMathTensor mult(const CepsMathTensor &l, const CepsMathTensor &r)
tensor*tensor -> tensor
static CepsMathTensor minus(const CepsMathTensor &l, const CepsMathTensor &r)
tensor-scalar -> tensor
static CepsMathTensor plus(const CepsMathTensor &l, const CepsMathTensor &r)
tensor+scalar -> tensor
static CepsMathTensor div(const CepsMathTensor &l, const CepsMathTensor &r)
tensor/tensor -> tensor [undefined]
static CepsMathTensor plus(const CepsMathTensor &l, const CepsMathVertex &r)
tensor+vertex -> tensor [undefined]
static CepsMathTensor minus(const CepsMathTensor &l, const CepsMathVertex &r)
tensor-vertex -> tensor [undefined]
static CepsMathTensor div(const CepsMathTensor &l, const CepsMathVertex &r)
tensor/vertex -> tensor [undefined]
static CepsMathVertex mult(const CepsMathTensor &l, const CepsMathVertex &r)
tensor*vertex -> vertex
static CepsMathVertex mult(const CepsMathVertex &l, const CepsMathScalar &r)
vertex*scalar -> vertex
static CepsMathVertex div(const CepsMathVertex &l, const CepsMathScalar &r)
vertex*scalar -> vertex
static CepsMathVertex minus(const CepsMathVertex &l, const CepsMathScalar &r)
vertex-scalar -> vertex
static CepsMathVertex plus(const CepsMathVertex &l, const CepsMathScalar &r)
vertex+scalar -> vertex
static CepsMathTensor minus(const CepsMathVertex &l, const CepsMathTensor &r)
vertex-tensor -> vertex [undefined]
static CepsMathTensor div(const CepsMathVertex &l, const CepsMathTensor &r)
vertex/tensor -> vertex [undefined]
static CepsMathVertex mult(const CepsMathVertex &l, const CepsMathTensor &r)
vertex*tensor -> vertex (v.t*t).t
static CepsMathTensor plus(const CepsMathVertex &l, const CepsMathTensor &r)
vertex+tensor -> vertex [undefined]
static CepsMathVertex minus(const CepsMathVertex &l, const CepsMathVertex &r)
vertex-vertex -> vertex
static CepsMathVertex plus(const CepsMathVertex &l, const CepsMathVertex &r)
vertex+vertex -> vertex
static CepsMathVertex div(const CepsMathVertex &l, const CepsMathVertex &r)
vertex/vertex -> vertex [undefined]
static CepsMathScalar mult(const CepsMathVertex &l, const CepsMathVertex &r)
vertex*vertex -> scalar
Ceps math operator functor, holds (+,-,*,/) definitions depending on mathematical definitions,...