Marine systems simulation
ConstraintSolver.h
1#pragma once
2
3#include <iostream>
4#include <vector>
5
6#include "RigidElement.h"
7#include "SparseMatrixBuilder.h"
8#include "ConjugateGradient.h"
9
14namespace CoRiBoDynamics
15{
16class ConstraintSet;
17
31{
32 friend class ConstraintSet;
33public:
34 explicit ConstraintSolver(double TimeConstant);
35 ConstraintSolver(double TimeConstant,int numThreads, bool no_hyperthreading = false);
36 ConstraintSolver(double TimeConstant, CoreBoundThreadPool* ThreadPool);
37 virtual ~ConstraintSolver();
38
39 void UpdateElements(const double T, const double * const X); // update rigid elements with new states. computes base inertia matrix, and base element forces.
40 void ComputeDynamic(const double T, const double * const X, const Eigen::Matrix<double,Eigen::Dynamic,1>& External_Force);
41 void ComputeDynamic(const double T, const double * const X); // computes constraints, and solves ode dynamics
42 void WriteDynamic(const double * const X,double * const XDot); // writes result of ode dynamics and kinematics to XDot
43 int addRigidElement(RigidElement* element); // adds this RigidElement to system. takes over memory management.
44
45 void SetSymplecticStepSize(double h);
46 double GetSymplecticStepSize();
47 double ComputeKineticEnergy(const double T, const double * const X);
48 int NumElements(){return (int)m_element.size();}
49
50 CoreBoundThreadPool* GetThreadPool();
51 ConjugateGradientSolver* GetCGSolver(){return m_CG_solver;}
52
53 void setConstraintSetPriority(ConstraintSet* constraintSet, int priority);
54
55 void PrintElement(int index);
56
57 SparseMatrixBuilder* GetSparseMatrixBuilder(){return m_MatrixBuilder;}
58
59protected:
60 void Initialize(double TimeConstant);
61 void ComputeDynamicInternal(const double T, const double * const X, const Vector* External_Force);
62 void addConstraintSet(ConstraintSet* constraintSet);
63
64 //std::vector<ConstraintSet*> m_constraint_set; /// list of all constraint sets in the system
65
66 std::vector<RigidElement*> m_element;
67
69
70 void addForceThreadSafe(int element, const vec6& Force);
71
72 std::mutex* m_ForceVectorLocks;
73 Vector m_Force;
74
76 CoreBoundThreadPool* m_ThreadPool;
77
78 std::mutex m_ConstraintPoolLock;
79
80 double m_TimeConstant;
81 double m_symplecticH;
82 bool m_elements_updated;
83
84 ConjugateGradientSolver* m_CG_solver;
85
91 public:
92 explicit ConstraintSetTask();
93 void SetConstraintSet(ConstraintSet* CSet);
94 void SetStates(double T, const double* X);
95 void Execute();
96
97 ConstraintSet* GetConstraintSet();
98 protected:
99 ConstraintSet* m_ConstraintSet;
100 double m_T;
101 const double* m_X;
102 };
103 std::map<int,std::vector<ConstraintSetTask> > m_ConstraintSet;
104 std::map<ConstraintSet*,int> m_priority_index;
105
111 public:
112 void init(int start_index, int end_index, SparseMatrixBuilder* MatrixBuilder, Vector* Force, std::vector<RigidElement*>* element);
113 void ComputeSubDomain(double T, const double * const X);
114 void Execute();
115 protected:
116 int m_ix0;
117 int m_ix1;
118 std::vector<RigidElement*>* m_element;
119 SparseMatrixBuilder* m_MatrixBuilder;
120 Vector* m_Force;
121
122 const double* m_X;
123 double m_T;
124 };
125 std::vector<SubDomainInertiaTask> m_InertiaComputers;
126
132 public:
133 void init(int start_index, int end_index, std::vector<RigidElement*>* element, Vector* SecondDerivatives, double symplecticH, double TimeConstant);
134 void ComputeSubDomain(double * XDot);
135 void Execute();
136 protected:
137 int m_ix0;
138 int m_ix1;
139 std::vector<RigidElement*>* m_element;
140 Vector* m_SecondDerivatives;
141 double* m_XDot;
142 double m_symplecticH;
143 double m_TimeConstant;
144 };
145 std::vector<SubDomainWriteDynamic> m_WriteDynamic;
146
147};
148}
Definition: ConjugateGradient.h:12
Definition: ConstraintSet.h:24
std::vector< RigidElement * > * m_element
end index
Definition: ConstraintSolver.h:118
int m_ix1
start index
Definition: ConstraintSolver.h:117
std::vector< RigidElement * > * m_element
end index
Definition: ConstraintSolver.h:139
int m_ix1
start index
Definition: ConstraintSolver.h:138
Definition: ConstraintSolver.h:31
std::vector< RigidElement * > m_element
adds a constraint set to the global constraint system. Only the constraint sets themselves are allowe...
Definition: ConstraintSolver.h:66
SparseMatrixBuilder * m_MatrixBuilder
F_external - M_dot·V + F_constraint.
Definition: ConstraintSolver.h:75
void addForceThreadSafe(int element, const vec6 &Force)
Computed second derivatives.
void PrintElement(int index)
set computation order priority for this constraint set
Vector m_SecondDerivatives
list of all 6DOF rigid elements in the system
Definition: ConstraintSolver.h:68
Definition: AsynchronousTask.h:20
Definition: AsynchronousTask.h:15
Definition: RigidElement.h:15
Definition: SparseMatrixBuilder.h:34
Definition: CollisionManager.h:6