iMSTK
Interactive Medical Simulation Toolkit
imstkLinearSystem.h
1 /*=========================================================================
2 
3  Library: iMSTK
4 
5  Copyright (c) Kitware, Inc. & Center for Modeling, Simulation,
6  & Imaging in Medicine, Rensselaer Polytechnic Institute.
7 
8  Licensed under the Apache License, Version 2.0 (the "License");
9  you may not use this file except in compliance with the License.
10  You may obtain a copy of the License at
11 
12  http://www.apache.org/licenses/LICENSE-2.0.txt
13 
14  Unless required by applicable law or agreed to in writing, software
15  distributed under the License is distributed on an "AS IS" BASIS,
16  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  See the License for the specific language governing permissions and
18  limitations under the License.
19 
20 =========================================================================*/
21 
22 #pragma once
23 
24 #include "imstkNonLinearSystem.h"
25 
26 namespace imstk
27 {
33 template<typename SystemMatrixType>
34 class LinearSystem : public NonLinearSystem<SystemMatrixType>
35 {
36 public:
41  LinearSystem() = delete;
42  LinearSystem(const SystemMatrixType& matrix, const Vectord& b) : m_A(matrix), m_b(b)
43  {
44  /*if (m_A.size() == m_b.size())
45  {
46  m_A = &matrix;
47  m_b = &b;
48  }
49  else
50  {
51  LOG(ERROR) << "LinearSystem::LinearSystem: The size of the matrix and the r.h.s doesn't match.";
52  }*/
53 
54  /*this->F = [this](const Vectord& x) -> Vectord&
55  {
56  this->m_f = this->m_A * x;
57  return this->m_f;
58  };*/
59  }
60 
61  ~LinearSystem() override { }
62 
66  LinearSystem(const LinearSystem&) = delete;
67  LinearSystem(const LinearSystem&&) = delete;
68  LinearSystem& operator=(const LinearSystem&) = delete;
69  LinearSystem& operator=(const LinearSystem&&) = delete;
70 
74  const Vectord& getRHSVector() const
75  {
76  return m_b;
77  }
78 
82  void setRHSVector(const Vectord& newRhs)
83  {
84  m_b = newRhs;
85  }
86 
90  const SystemMatrixType& getMatrix() const
91  {
92  return m_A;
93  }
94 
98  void setMatrix(const SystemMatrixType& newMatrix)
99  {
100  m_A = newMatrix;
101  }
102 
106  void computeResidual(const Vectord& x, Vectord& r) const
107  {
108  r = m_b - m_A * x;
109  }
110 
114  Eigen::TriangularView<SystemMatrixType, Eigen::Lower> getLowerTriangular() const;
115 
119  Eigen::TriangularView<SystemMatrixType, Eigen::StrictlyLower> getStrictLowerTriangular() const;
120 
124  Eigen::TriangularView<SystemMatrixType, Eigen::Upper> getUpperTrianglular() const;
125 
129  Eigen::TriangularView<SystemMatrixType, Eigen::StrictlyUpper> getStrictUpperTriangular() const;
130 
134  Vectord& getFunctionValue();
135 
139  size_t getSize();
140 
141 private:
142  const SystemMatrixType& m_A;
143  const Vectord& m_b;
144 
145  Vectord m_f;
146 };
147 } // namespace imstk
const SystemMatrixType & getMatrix() const
Returns reference to local matrix.
Eigen::TriangularView< SystemMatrixType, Eigen::Lower > getLowerTriangular() const
Returns template expression for the lower triangular part of A.
Compound Geometry.
Base class for a multi-variable nonlinear system.
LinearSystem()=delete
Constructor/destructor(s). This class can&#39;t be constructed without a matrix and rhs.
Vectord & getFunctionValue()
Get the value of the function F.
Eigen::TriangularView< SystemMatrixType, Eigen::StrictlyUpper > getStrictUpperTriangular() const
Returns template expression for the strict upper triangular part of A.
const Vectord & getRHSVector() const
Returns a reference to local right hand side vector.
void setRHSVector(const Vectord &newRhs)
Set the system rhs corresponding to this system.
Represents the linear system of the form .
void setMatrix(const SystemMatrixType &newMatrix)
Set the system matrix corresponding to this ODE system.
void computeResidual(const Vectord &x, Vectord &r) const
Compute the residual as .
Eigen::TriangularView< SystemMatrixType, Eigen::Upper > getUpperTrianglular() const
Returns template expression for the upper triangular part of A.
Eigen::TriangularView< SystemMatrixType, Eigen::StrictlyLower > getStrictLowerTriangular() const
Returns template expression for the strict lower triangular part of A.
size_t getSize()
Returns the size of the system.