svZeroDSolver
Loading...
Searching...
No Matches
Integrator.h
Go to the documentation of this file.
1// Copyright (c) Stanford University, The Regents of the University of
2// California, and others.
3//
4// All Rights Reserved.
5//
6// See Copyright-SimVascular.txt for additional details.
7//
8// Permission is hereby granted, free of charge, to any person obtaining
9// a copy of this software and associated documentation files (the
10// "Software"), to deal in the Software without restriction, including
11// without limitation the rights to use, copy, modify, merge, publish,
12// distribute, sublicense, and/or sell copies of the Software, and to
13// permit persons to whom the Software is furnished to do so, subject
14// to the following conditions:
15//
16// The above copyright notice and this permission notice shall be included
17// in all copies or substantial portions of the Software.
18//
19// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
22// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
23// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30/**
31 * @file Integrator.h
32 * @brief Integrator source file
33 */
34#ifndef SVZERODSOLVER_ALGEBRA_INTEGRATOR_HPP_
35#define SVZERODSOLVER_ALGEBRA_INTEGRATOR_HPP_
36
37#include <Eigen/Dense>
38
39#include "Model.h"
40#include "State.h"
41
42/**
43 * @brief Generalized-alpha integrator
44 *
45 * This class handles the time integration scheme for solving 0D blood
46 * flow system using the generalized-\f$\alpha\f$ method \cite JANSEN2000305.
47 *
48 * Mathematical details are available on the <a
49 * href="https://simvascular.github.io/documentation/rom_simulation.html#0d-solver-theory">SimVascular
50 * documentation</a>.
51 */
52
54 private:
55 double alpha_m{0.0};
56 double alpha_f{0.0};
57 double gamma{0.0};
58 double time_step_size{0.0};
59 double ydot_init_coeff{0.0};
60 double y_coeff{0.0};
61 double y_coeff_jacobian{0.0};
62 double atol{0.0};
63 int max_iter{0};
64 int size{0};
65 int n_iter{0};
66 int n_nonlin_iter{0};
67 Eigen::Matrix<double, Eigen::Dynamic, 1> y_af;
68 Eigen::Matrix<double, Eigen::Dynamic, 1> ydot_am;
69 SparseSystem system;
70 Model* model{nullptr};
71
72 public:
73 /**
74 * @brief Construct a new Integrator object
75 *
76 * @param model The model to simulate
77 * @param time_step_size Time step size for generalized-alpha step
78 * @param rho Spectral radius for generalized-alpha step
79 * @param atol Absolut tolerance for non-linear iteration termination
80 * @param max_iter Maximum number of non-linear iterations
81 */
82 Integrator(Model* model, double time_step_size, double rho, double atol,
83 int max_iter);
84
85 /**
86 * @brief Construct a new Integrator object
87 *
88 */
89 Integrator();
90
91 /**
92 * @brief Destroy the Integrator object
93 *
94 */
96
97 /**
98 * @brief Delete dynamically allocated memory (in class member
99 * SparseSystem<double> system).
100 */
101 void clean();
102
103 /**
104 * @brief Update integrator parameter and system matrices with model parameter
105 * updates.
106 *
107 * @param time_step_size Time step size for 0D model
108 */
109 void update_params(double time_step_size);
110
111 /**
112 * @brief Perform a time step
113 *
114 * @param state Current state
115 * @param time Current time
116 * @return New state
117 */
118 State step(const State& state, double time);
119
120 /**
121 * @brief Get average number of nonlinear iterations in all step calls
122 *
123 * @return Average number of nonlinear iterations in all step calls
124 *
125 */
126 double avg_nonlin_iter();
127};
128
129#endif // SVZERODSOLVER_ALGEBRA_INTEGRATOR_HPP_
model::Model source file
State source file.
Generalized-alpha integrator.
Definition Integrator.h:53
State step(const State &state, double time)
Perform a time step.
Definition Integrator.cpp:76
void clean()
Delete dynamically allocated memory (in class member SparseSystem<double> system).
Definition Integrator.cpp:62
double avg_nonlin_iter()
Get average number of nonlinear iterations in all step calls.
Definition Integrator.cpp:136
Integrator()
Construct a new Integrator object.
Definition Integrator.cpp:59
~Integrator()
Destroy the Integrator object.
Definition Integrator.cpp:60
void update_params(double time_step_size)
Update integrator parameter and system matrices with model parameter updates.
Definition Integrator.cpp:68
Model of 0D elements.
Definition Model.h:75
Sparse system.
Definition SparseSystem.h:57
State of the system.
Definition State.h:46