svZeroDSolver
Loading...
Searching...
No Matches
SparseSystem.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 SparseSystem.h
5 * @brief SparseSystem source file
6 */
7#ifndef SVZERODSOLVER_ALGREBRA_SPARSESYSTEM_HPP_
8#define SVZERODSOLVER_ALGREBRA_SPARSESYSTEM_HPP_
9
10#include <Eigen/Sparse>
11#include <Eigen/SparseLU>
12#include <iostream>
13#include <memory>
14
15// Forward declaration of Model
16class Model;
17
18/**
19 * @brief Sparse system
20 *
21 * This class contains all attributes and methods to create, modify, and
22 * solve sparse systems.
23 *
24 * Mathematical details related to setting up the governing system of
25 * equations are available on the <a
26 * href="https://simvascular.github.io/documentation/rom_simulation.html#0d-solver-theory">SimVascular
27 * documentation</a>.
28 *
29 */
31 public:
32 /**
33 * @brief Construct a new Sparse System object
34 *
35 */
37
38 /**
39 * @brief Construct a new Sparse System object
40 *
41 * @param n Size of the system
42 */
43 SparseSystem(int n);
44
45 /**
46 * @brief Destroy the Sparse System object
47 *
48 */
50
51 Eigen::SparseMatrix<double> F; ///< System matrix F
52 Eigen::SparseMatrix<double> E; ///< System matrix E
53 Eigen::SparseMatrix<double> dC_dy; ///< System matrix dC/dy
54 Eigen::SparseMatrix<double> dC_dydot; ///< System matrix dC/dydot
55 Eigen::Matrix<double, Eigen::Dynamic, 1> C; ///< System vector C
56
57 Eigen::SparseMatrix<double> jacobian; ///< Jacobian of the system
58 Eigen::Matrix<double, Eigen::Dynamic, 1>
59 residual; ///< Residual of the system
60 Eigen::Matrix<double, Eigen::Dynamic, 1>
61 dydot; ///< Solution increment of the system
62
63 std::shared_ptr<Eigen::SparseLU<Eigen::SparseMatrix<double>>> solver =
64 std::shared_ptr<Eigen::SparseLU<Eigen::SparseMatrix<double>>>(
65 new Eigen::SparseLU<Eigen::SparseMatrix<double>>()); ///< Linear
66 ///< solver
67
68 /**
69 * @brief Reserve memory in system matrices based on number of triplets
70 *
71 * @param model The model to reserve space for in the system
72 */
73 void reserve(Model *model);
74
75 /**
76 * @brief Update the residual of the system
77 *
78 * @param y Vector of current solution quantities
79 * @param ydot Derivate of y
80 */
81 void update_residual(Eigen::Matrix<double, Eigen::Dynamic, 1> &y,
82 Eigen::Matrix<double, Eigen::Dynamic, 1> &ydot);
83
84 /**
85 * @brief Update the jacobian of the system
86 *
87 * @param time_coeff_ydot Coefficent ydot-dependent part of jacobian
88 * @param time_coeff_y Coefficent ydot-dependent part of jacobian
89 */
90 void update_jacobian(double time_coeff_ydot, double time_coeff_y);
91
92 /**
93 * @brief Solve the system
94 */
95 void solve();
96
97 /**
98 * @brief Delete dynamically allocated memory (class member
99 * Eigen::SparseLU<Eigen::SparseMatrix> *solver)
100 */
101 void clean();
102};
103
104#endif // SVZERODSOLVER_ALGREBRA_SPARSESYSTEM_HPP_
Model of 0D elements.
Definition Model.h:48
Eigen::SparseMatrix< double > dC_dy
System matrix dC/dy.
Definition SparseSystem.h:53
void reserve(Model *model)
Reserve memory in system matrices based on number of triplets.
Definition SparseSystem.cpp:30
void clean()
Delete dynamically allocated memory (class member Eigen::SparseLU<Eigen::SparseMatrix> *solver)
Definition SparseSystem.cpp:24
Eigen::SparseMatrix< double > E
System matrix E.
Definition SparseSystem.h:52
Eigen::SparseMatrix< double > dC_dydot
System matrix dC/dydot.
Definition SparseSystem.h:54
Eigen::Matrix< double, Eigen::Dynamic, 1 > C
System vector C.
Definition SparseSystem.h:55
Eigen::Matrix< double, Eigen::Dynamic, 1 > residual
Residual of the system.
Definition SparseSystem.h:59
SparseSystem()
Construct a new Sparse System object.
Definition SparseSystem.cpp:8
void solve()
Solve the system.
Definition SparseSystem.cpp:74
Eigen::SparseMatrix< double > F
System matrix F.
Definition SparseSystem.h:51
void update_residual(Eigen::Matrix< double, Eigen::Dynamic, 1 > &y, Eigen::Matrix< double, Eigen::Dynamic, 1 > &ydot)
Update the residual of the system.
Definition SparseSystem.cpp:58
void update_jacobian(double time_coeff_ydot, double time_coeff_y)
Update the jacobian of the system.
Definition SparseSystem.cpp:67
Eigen::Matrix< double, Eigen::Dynamic, 1 > dydot
Solution increment of the system.
Definition SparseSystem.h:61
~SparseSystem()
Destroy the Sparse System object.
Definition SparseSystem.cpp:22
Eigen::SparseMatrix< double > jacobian
Jacobian of the system.
Definition SparseSystem.h:57
std::shared_ptr< Eigen::SparseLU< Eigen::SparseMatrix< double > > > solver
Definition SparseSystem.h:63