-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathvector-function.hpp
More file actions
76 lines (65 loc) · 2.27 KB
/
Copy pathvector-function.hpp
File metadata and controls
76 lines (65 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
* Vector function classes.
* Define the RHS `f` of the DAE system `M dx/dt = f`.
* This class is abstract and must be inherited.
*
* This file is part of dae-cpp.
*
* dae-cpp is licensed under the MIT license.
* A copy of the license can be found in the LICENSE file.
*
* Copyright (c) 2024-2025 Ivan Korotkin
*/
#ifndef DAECPP_VECTOR_FUNCTION_H
#define DAECPP_VECTOR_FUNCTION_H
#include "typedefs.hpp"
namespace daecpp_namespace_name
{
/*
* Vector function class.
* This class is abstract and must be inherited.
*/
class VectorFunction
{
public:
/*
* Defines the RHS (vector function) `f` of the DAE system `M dx/dt = f`.
* Takes vector `x` and time `t` and returns the RHS vector `f`.
* Vector `f` is already pre-allocated with f.size() == x.size().
* This function is pure virtual and must be overriden.
*/
virtual void operator()(state_type &f, const state_type &x, const double t) const = 0;
virtual ~VectorFunction() {}
};
/*
* Vector function class used for automatic Jacobian computed from the user-defined Jacobian shape.
* Used to define the vector function (the RHS) element-by-element (equation-by-equation).
* Should be used together with `JacobianMatrixShape` class for the Jacobian matrix.
* This class is abstract and must be inherited.
*/
class VectorFunctionElements
{
public:
/*
* Defines the RHS (vector function) `f` of the DAE system `M dx/dt = f`.
* Vector `f` is already pre-allocated with f.size() == x.size().
*/
void operator()(state_type &f, const state_type &x, const double t) const
{
const int_type size = static_cast<int_type>(x.size()); // System size
for (int_type i = 0; i < size; ++i)
{
f[i] = equations(x, t, i);
}
}
/*
* All RHS functions `f_i` for each equation `i` in the system.
* Takes vector `x`, time `t`, index `i`, and returns the RHS value `f_i` for the given equation `i`.
* I.e., it returns the i-th element of the vector function.
* This function is pure virtual and must be overriden.
*/
virtual state_value equations(const state_type &x, const double t, const int_type i) const = 0;
virtual ~VectorFunctionElements() {}
};
} // namespace daecpp_namespace_name
#endif // DAECPP_VECTOR_FUNCTION_H