iMSTK
Interactive Medical Simulation Toolkit
imstkNonLinearSystem.h
1 /*
2 ** This file is part of the Interactive Medical Simulation Toolkit (iMSTK)
3 ** iMSTK is distributed under the Apache License, Version 2.0.
4 ** See accompanying NOTICE for details.
5 */
6 
7 #pragma once
8 
9 #include "imstkMath.h"
10 #include <utility>
11 
12 namespace imstk
13 {
19 template<typename Matrix>
21 {
22 public:
23  using VectorFunctionType = std::function<const Vectord& (const Vectord&, const bool)>;
24  using MatrixFunctionType = std::function<const Matrix& (const Vectord&)>;
25  // using VecMatPair = std::pair<const Vectord&, const Matrix&>;
26  using VecMatPair = std::pair<const Vectord*, const Matrix*>;
27  using VectorMatrixFunctionType = std::function<VecMatPair(const Vectord&, const bool)>;
28  using UpdateFunctionType = std::function<void (const Vectord&, const bool)>;
29  using UpdatePrevStateFunctionType = std::function<void ()>;
30 
31  NonLinearSystem() { }
32  NonLinearSystem(const VectorFunctionType& F, const MatrixFunctionType& dF);
33  NonLinearSystem(const VectorFunctionType& F, const MatrixFunctionType& dF, const VectorMatrixFunctionType& F_dF);
34 
35  virtual ~NonLinearSystem() { }
36 
40  virtual void setFunction(const VectorFunctionType& function);
41 
45  virtual void setJacobian(const MatrixFunctionType& function);
46 
50  virtual const Vectord& evaluateF(const Vectord& x, const bool isSemiImplicit);
51 
55  virtual const Matrix& evaluateJacobian(const Vectord& x);
56 
60  void setUnknownVector(Vectord& v)
61  {
62  m_unknown = &v;
63  }
64 
68  Vectord& getUnknownVector()
69  {
70  return *m_unknown;
71  }
72 
75  /*void setLinearProjectors(std::vector<LinearProjectionConstraint>& f)
76  {
77  m_LinearProjConstraints = &f;
78  }
79 
82  std::vector<LinearProjectionConstraint>& getLinearProjectors()
83  {
84  return *m_LinearProjConstraints;
85  }*/
86 
90  void setUpdateFunction(const UpdateFunctionType& updateFunc)
91  {
92  m_FUpdate = updateFunc;
93  }
94 
98  void setUpdatePreviousStatesFunction(const UpdatePrevStateFunctionType& updateFunc)
99  {
100  m_FUpdatePrevState = updateFunc;
101  }
102 
105 /*void setDynamicLinearProjectors(std::vector<LinearProjectionConstraint>* f)
106  {
107  m_DynamicLinearProjConstraints = f;
108  }
109 
112  std::vector<LinearProjectionConstraint>& getDynamicLinearProjectors()
113  {
114  return *m_DynamicLinearProjConstraints;
115  }*/
116 
117  VectorFunctionType m_F;
118  MatrixFunctionType m_dF;
119  VectorMatrixFunctionType m_F_dF;
120  Vectord* m_unknown = nullptr;
121 
122  UpdateFunctionType m_FUpdate;
123  UpdatePrevStateFunctionType m_FUpdatePrevState;
124  /*std::vector<LinearProjectionConstraint> *m_LinearProjConstraints;
125  std::vector<LinearProjectionConstraint> *m_DynamicLinearProjConstraints;*/
126 };
127 } // namespace imstk
virtual const Vectord & evaluateF(const Vectord &x, const bool isSemiImplicit)
Evaluate function at a given state.
Compound Geometry.
VectorFunctionType m_F
Get the vector denoting the filter.
Base class for a multi-variable nonlinear system.
MatrixFunctionType m_dF
Gradient of the Nonlinear function with respect to the unknown vector.
virtual void setJacobian(const MatrixFunctionType &function)
Set the method that evaluates the gradient of the nonlinear function.
virtual const Matrix & evaluateJacobian(const Vectord &x)
Evaluate gradient of the function at a given state.
void setUpdatePreviousStatesFunction(const UpdatePrevStateFunctionType &updateFunc)
Set the update function.
void setUpdateFunction(const UpdateFunctionType &updateFunc)
Get the vector denoting the filter.
Vectord & getUnknownVector()
Get the vector used to populate the solution.
virtual void setFunction(const VectorFunctionType &function)
Set nonlinear method that evaluates the nonlinear function.