You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -40,6 +40,9 @@ Initially, matrix `J` is empty and should be filled with non-zero elements.
40
40
{: .note }
41
41
The type of vector `x` in the class definition above is `daecpp::state_vector`, which is an alias of `std::vector<float_type>` type. See [`dae-cpp` types](https://dae-cpp.github.io/prerequisites.html#dae-cpp-types) section for more information.
42
42
43
+
{: .important }
44
+
The Jacobian Matrix class must not be used to save or post-process the solution vector `x` and time `t`. For this purpose, use the [Solution Manager](solution-manager.html) class.
45
+
43
46
## Examples
44
47
45
48
Consider the following vector function $$\mathbf{f}(\mathbf{x}, t)$$ from the [Vector Function class](vector-function.html#examples) section:
Copy file name to clipboardExpand all lines: docs/solution-manager.md
+72-2Lines changed: 72 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,9 +9,79 @@ Work in progress
9
9
10
10
# Solution Manager class
11
11
12
-
The Solution Manager class can serve as a solution observer and/or as an event function that stops computation when a certain event occurs. Solution Manager functor will be called every time step, providing the time `t` and the corresponding solution `x` for further post-processing. If the functor returns an integer which is not equal to `0` (i.e., `true`), the computation will immediately stop.
12
+
The Solution Manager class can serve as a solution observer and/or as an event function that stops computation when a certain event occurs. Solution Manager functor will be called every time step, providing the time `t` and the corresponding solution `x` for the user for further post-processing. If the functor returns an integer which is not equal to `0` (i.e., `true`), the computation will immediately stop.
13
13
14
-
The solver provides a derived from the Solution Manager class called `daecpp::Solution`, which writes the solution vector `x` and time `t` every time step or every specific time defined by the user into the [solution holder](#solution-holder) object. The user can access this object for further post-processing, printing the solution on the screen or writing it to a file.
14
+
The solver provides a derived from the Solution Manager class called [`daecpp::Solution`](#solution-class), which writes the solution vector `x` and time `t` every time step or every specific time defined by the user into the [solution holder](#solution-holder) object. The user can access this object for further post-processing, printing the solution on the screen or writing it to a file.
15
+
16
+
{: .important }
17
+
By default, the DAE solver does nothing with the solution, i.e., it does not print it on the screen or save it anywhere. It is the user's responsibility to define a Solution Manager object that processes the solution (saves it to a vector, to a file, etc.). The solver, however, provides a basic Solution Manager called [`daecpp::Solution`](#solution-class).
18
+
19
+
## Solution Manager definition
20
+
21
+
The Solution Manager class `daecpp::SolutionManager` is a virtual class that provides an interface to define the Solution Manager.
22
+
In order to make use of this class, the user should inherit it and overload the `()` operator:
int operator()(const daecpp::state_vector &x, const double t)
29
+
{
30
+
// Solution Manager definition
31
+
32
+
return 0; // Returns 0 by default or an integer != 0 to stop the computation
33
+
}
34
+
};
35
+
```
36
+
37
+
The operator `()` will be called every time step, providing the user with the current state `x` and the corresponding time `t`.
38
+
If the functor returns non-zero integer, the computation will stop.
39
+
The user is free to define the solution container and save the solution within the Solution Manager class. The solver provides [`SolutionHolder`](#solution-holder) helper class that stores solution vectors `x` and the corresponding times `t`.
40
+
41
+
{: .note }
42
+
The type of vector `x` in the class definition above is `daecpp::state_vector`, which is an alias of `std::vector<float_type>` type. See [`dae-cpp` types](https://dae-cpp.github.io/prerequisites.html#dae-cpp-types) section for more information.
43
+
44
+
## Example
45
+
46
+
In the following example, we define a custom Solution Manager that performs the following 3 tasks:
47
+
48
+
- writes the element `x[0]` of the solution `x` and time `t` into `std::vector` every time step,
49
+
- prints time `t` and `x[0]` on the screen every time step,
int operator()(const daecpp::state_vector &x, const double t)
63
+
{
64
+
const auto x_0 = x[0]; // Solution element of interest
65
+
66
+
m_x_sol.push_back(x_0); // Writes x[0] every time step
67
+
m_t_sol.push_back(t); // Writes time t every time step
68
+
69
+
std::cout << t << '\t' << x_0 << '\n'; // Prints t and x[0] on screen
70
+
71
+
if (x_0 < 0.0)
72
+
{
73
+
return -1; // Stops computation if x[0] is negative
74
+
}
75
+
76
+
return 0;
77
+
}
78
+
};
79
+
```
80
+
81
+
{: .warning }
82
+
Vectors `x_sol` and `t_sol` should be defined before calling the `UserDefinedSolutionManager` constructor and must live until the end of the computation. They shouldn't be passed to the constructor as temporary objects and must **not** go out of scope before finishing the system solving (otherwise, this will lead to dangling references `&m_x_sol` and `&m_t_sol` in the class definition above).
83
+
84
+
Similar to the mass matrix, vector function, Jacobian matrix definitions, inhereting the `daecpp::SolutionManager` class is a good practice (it serves as a blueprint), but it is not necessary. The user is allowed to define custom Solution Managers without inhereting `daecpp::SolutionManager`.
Copy file name to clipboardExpand all lines: docs/vector-function.md
+4-1Lines changed: 4 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ nav_order: 4
7
7
8
8
# Vector Function class
9
9
10
-
Vector function class defines the (nonlinear) vector function (the RHS) $$\mathbf{f}(\mathbf{x}, t)$$ of the DAE system written in the matrix-vector form:
10
+
The Vector function class defines the (nonlinear) vector function (the RHS) $$\mathbf{f}(\mathbf{x}, t)$$ of the DAE system written in the matrix-vector form:
@@ -36,6 +36,9 @@ The elements of vectors `x` and `f` can be accessed using square brackets `[]`.
36
36
{: .note }
37
37
The type of vectors `f` and `x` is `daecpp::state_type`, which is an alias of [`autodiff`](https://autodiff.github.io/)'s type used to perform automatic (algorithmic) differentiation of the vector function `f`. See [`dae-cpp` types](https://dae-cpp.github.io/prerequisites.html#dae-cpp-types) section.
38
38
39
+
{: .important }
40
+
The Vector Function class must not be used to save or post-process the solution vector `x` and time `t`. For this purpose, use the [Solution Manager](solution-manager.html) class.
41
+
39
42
## Examples
40
43
41
44
Consider the following vector function $$\mathbf{f}(\mathbf{x}, t)$$, where $$\mathbf{x} = \{x,y,z\}$$, as an example:
0 commit comments