svZeroDSolver
Loading...
Searching...
No Matches
Integrator.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Stanford University, The Regents of the
2// University of California, and others. SPDX-License-Identifier: BSD-3-Clause
3/**
4 * @file Integrator.h
5 * @brief Integrator source file
6 */
7#ifndef SVZERODSOLVER_ALGEBRA_INTEGRATOR_HPP_
8#define SVZERODSOLVER_ALGEBRA_INTEGRATOR_HPP_
9
10#include <Eigen/Dense>
11
12#include "Model.h"
13#include "State.h"
14
15/**
16 * @brief Generalized-alpha integrator
17 *
18 * This class handles the time integration scheme for solving 0D blood
19 * flow system using the generalized-\f$\alpha\f$ method \cite JANSEN2000305.
20 *
21 * Mathematical details are available on the <a
22 * href="https://simvascular.github.io/documentation/rom_simulation.html#0d-solver-theory">SimVascular
23 * documentation</a>.
24 */
25
27 private:
28 double alpha_m{0.0};
29 double alpha_f{0.0};
30 double gamma{0.0};
31 double time_step_size{0.0};
32 double ydot_init_coeff{0.0};
33 double y_coeff{0.0};
34 double y_coeff_jacobian{0.0};
35 double atol{0.0};
36 int max_iter{0};
37 bool max_iter_error_to_warning{false};
38 int size{0};
39 int n_iter{0};
40 int n_nonlin_iter{0};
41 Eigen::Matrix<double, Eigen::Dynamic, 1> y_af;
42 Eigen::Matrix<double, Eigen::Dynamic, 1> ydot_am;
43 SparseSystem system;
44 Model* model{nullptr};
45
46 public:
47 /**
48 * @brief Construct a new Integrator object
49 *
50 * @param model The model to simulate
51 * @param time_step_size Time step size for generalized-alpha step
52 * @param rho Spectral radius for generalized-alpha step
53 * @param atol Absolut tolerance for non-linear iteration termination
54 * @param max_iter Maximum number of non-linear iterations
55 * @param max_iter_error_to_warning If true, print a warning instead of throwing error
56 * when maximum iterations is reached
57 */
58 Integrator(Model* model, double time_step_size, double rho, double atol,
59 int max_iter, bool max_iter_error_to_warning = false);
60
61 /**
62 * @brief Construct a new Integrator object
63 *
64 */
65 Integrator();
66
67 /**
68 * @brief Destroy the Integrator object
69 *
70 */
72
73 /**
74 * @brief Delete dynamically allocated memory (in class member
75 * SparseSystem<double> system).
76 */
77 void clean();
78
79 /**
80 * @brief Update integrator parameter and system matrices with model parameter
81 * updates.
82 *
83 * @param time_step_size Time step size for 0D model
84 */
85 void update_params(double time_step_size);
86
87 /**
88 * @brief Perform a time step
89 *
90 * @param state Current state
91 * @param time Current time
92 * @return New state
93 */
94 State step(const State& state, double time);
95
96 /**
97 * @brief Get average number of nonlinear iterations in all step calls
98 *
99 * @return Average number of nonlinear iterations in all step calls
100 *
101 */
102 double avg_nonlin_iter();
103};
104
105#endif // SVZERODSOLVER_ALGEBRA_INTEGRATOR_HPP_
model::Model source file
State source file.
State step(const State &state, double time)
Perform a time step.
Definition Integrator.cpp:50
void clean()
Delete dynamically allocated memory (in class member SparseSystem<double> system).
Definition Integrator.cpp:36
double avg_nonlin_iter()
Get average number of nonlinear iterations in all step calls.
Definition Integrator.cpp:115
Integrator()
Construct a new Integrator object.
Definition Integrator.cpp:33
~Integrator()
Destroy the Integrator object.
Definition Integrator.cpp:34
Integrator(Model *model, double time_step_size, double rho, double atol, int max_iter, bool max_iter_error_to_warning=false)
Construct a new Integrator object.
Definition Integrator.cpp:6
void update_params(double time_step_size)
Update integrator parameter and system matrices with model parameter updates.
Definition Integrator.cpp:42
Model of 0D elements.
Definition Model.h:55
Sparse system.
Definition SparseSystem.h:30
State of the system.
Definition State.h:19