svZeroDSolver
Loading...
Searching...
No Matches
SparseSystem.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 SparseSystem.h
32 * @brief SparseSystem source file
33 */
34#ifndef SVZERODSOLVER_ALGREBRA_SPARSESYSTEM_HPP_
35#define SVZERODSOLVER_ALGREBRA_SPARSESYSTEM_HPP_
36
37#include <Eigen/Sparse>
38#include <Eigen/SparseLU>
39#include <iostream>
40#include <memory>
41
42// Forward declaration of Model
43class Model;
44
45/**
46 * @brief Sparse system
47 *
48 * This class contains all attributes and methods to create, modify, and
49 * solve sparse systems.
50 *
51 * Mathematical details related to setting up the governing system of
52 * equations are available on the <a
53 * href="https://simvascular.github.io/documentation/rom_simulation.html#0d-solver-theory">SimVascular
54 * documentation</a>.
55 *
56 */
58 public:
59 /**
60 * @brief Construct a new Sparse System object
61 *
62 */
64
65 /**
66 * @brief Construct a new Sparse System object
67 *
68 * @param n Size of the system
69 */
70 SparseSystem(int n);
71
72 /**
73 * @brief Destroy the Sparse System object
74 *
75 */
77
78 Eigen::SparseMatrix<double> F; ///< System matrix F
79 Eigen::SparseMatrix<double> E; ///< System matrix E
80 Eigen::SparseMatrix<double> dC_dy; ///< System matrix dC/dy
81 Eigen::SparseMatrix<double> dC_dydot; ///< System matrix dC/dydot
82 Eigen::Matrix<double, Eigen::Dynamic, 1> C; ///< System vector C
83
84 Eigen::SparseMatrix<double> jacobian; ///< Jacobian of the system
85 Eigen::Matrix<double, Eigen::Dynamic, 1>
86 residual; ///< Residual of the system
87 Eigen::Matrix<double, Eigen::Dynamic, 1>
88 dydot; ///< Solution increment of the system
89
90 std::shared_ptr<Eigen::SparseLU<Eigen::SparseMatrix<double>>> solver =
91 std::shared_ptr<Eigen::SparseLU<Eigen::SparseMatrix<double>>>(
92 new Eigen::SparseLU<Eigen::SparseMatrix<double>>()); ///< Linear
93 ///< solver
94
95 /**
96 * @brief Reserve memory in system matrices based on number of triplets
97 *
98 * @param model The model to reserve space for in the system
99 */
100 void reserve(Model *model);
101
102 /**
103 * @brief Update the residual of the system
104 *
105 * @param y Vector of current solution quantities
106 * @param ydot Derivate of y
107 */
108 void update_residual(Eigen::Matrix<double, Eigen::Dynamic, 1> &y,
109 Eigen::Matrix<double, Eigen::Dynamic, 1> &ydot);
110
111 /**
112 * @brief Update the jacobian of the system
113 *
114 * @param time_coeff_ydot Coefficent ydot-dependent part of jacobian
115 * @param time_coeff_y Coefficent ydot-dependent part of jacobian
116 */
117 void update_jacobian(double time_coeff_ydot, double time_coeff_y);
118
119 /**
120 * @brief Solve the system
121 */
122 void solve();
123
124 /**
125 * @brief Delete dynamically allocated memory (class member
126 * Eigen::SparseLU<Eigen::SparseMatrix> *solver)
127 */
128 void clean();
129};
130
131#endif // SVZERODSOLVER_ALGREBRA_SPARSESYSTEM_HPP_
Model of 0D elements.
Definition Model.h:75
Sparse system.
Definition SparseSystem.h:57
Eigen::SparseMatrix< double > dC_dy
System matrix dC/dy.
Definition SparseSystem.h:80
void reserve(Model *model)
Reserve memory in system matrices based on number of triplets.
Definition SparseSystem.cpp:57
void clean()
Delete dynamically allocated memory (class member Eigen::SparseLU<Eigen::SparseMatrix> *solver)
Definition SparseSystem.cpp:51
Eigen::SparseMatrix< double > E
System matrix E.
Definition SparseSystem.h:79
Eigen::SparseMatrix< double > dC_dydot
System matrix dC/dydot.
Definition SparseSystem.h:81
Eigen::Matrix< double, Eigen::Dynamic, 1 > C
System vector C.
Definition SparseSystem.h:82
Eigen::Matrix< double, Eigen::Dynamic, 1 > residual
Residual of the system.
Definition SparseSystem.h:86
SparseSystem()
Construct a new Sparse System object.
Definition SparseSystem.cpp:35
void solve()
Solve the system.
Definition SparseSystem.cpp:101
Eigen::SparseMatrix< double > F
System matrix F.
Definition SparseSystem.h:78
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:85
void update_jacobian(double time_coeff_ydot, double time_coeff_y)
Update the jacobian of the system.
Definition SparseSystem.cpp:94
Eigen::Matrix< double, Eigen::Dynamic, 1 > dydot
Solution increment of the system.
Definition SparseSystem.h:88
~SparseSystem()
Destroy the Sparse System object.
Definition SparseSystem.cpp:49
Eigen::SparseMatrix< double > jacobian
Jacobian of the system.
Definition SparseSystem.h:84
std::shared_ptr< Eigen::SparseLU< Eigen::SparseMatrix< double > > > solver
Definition SparseSystem.h:90