improve CG performance using CSR matrix format
This commit is contained in:
		| @@ -107,10 +107,10 @@ enum b3MassType | ||||
| //  | ||||
| struct b3MassContact | ||||
| { | ||||
| 	u32 j; | ||||
| 	b3Vec3 n, t1, t2; | ||||
| 	float32 Fn, Ft1, Ft2; | ||||
| 	u32 j; | ||||
| 	bool lockOnSurface, slideOnSurface; | ||||
| 	bool lockN, lockT1, lockT2; | ||||
| }; | ||||
|  | ||||
| // Time step statistics | ||||
| @@ -186,7 +186,7 @@ protected: | ||||
| 	// Update contacts.  | ||||
| 	// This is where some contacts might be initiated or terminated. | ||||
| 	void UpdateContacts(); | ||||
| 	 | ||||
|  | ||||
| 	b3StackAllocator* m_allocator; | ||||
|  | ||||
| 	b3Mesh* m_mesh; | ||||
| @@ -252,7 +252,7 @@ inline void b3SpringCloth::SetType(u32 i, b3MassType type) | ||||
| 		m_v[i].SetZero(); | ||||
| 		m_y[i].SetZero(); | ||||
| 		 | ||||
| 		m_contacts[i].lockOnSurface = false; | ||||
| 		m_contacts[i].lockN = false; | ||||
| 	} | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -25,6 +25,9 @@ | ||||
| class b3SpringCloth; | ||||
| class b3StackAllocator; | ||||
|  | ||||
| struct b3DenseVec3; | ||||
| struct b3SparseMat33; | ||||
|  | ||||
| struct b3MassContact; | ||||
| struct b3Spring; | ||||
|  | ||||
| @@ -43,25 +46,25 @@ public: | ||||
|  | ||||
| 	~b3SpringSolver(); | ||||
|  | ||||
| 	void Solve(b3Vec3* constraintForces); | ||||
| 	void Solve(b3DenseVec3& extraForces); | ||||
|  | ||||
| 	u32 GetIterations() const; | ||||
| private: | ||||
| 	// Apply internal forces and store their unique derivatives. | ||||
| 	void InitializeSpringForces(); | ||||
| 	void ApplySpringForces(); | ||||
|  | ||||
| 	// Initialize b, from Ax = b | ||||
| 	void Compute_b(b3Vec3* b) const; | ||||
| 	// Compute A and b in Ax = b | ||||
| 	void Compute_A_b(b3SparseMat33& A, b3DenseVec3& b) const; | ||||
|  | ||||
| 	// Solve Ax = b using the Modified Conjugate Gradient (MCG).  | ||||
| 	// Output x and the residual error f. | ||||
| 	void Solve_MCG(b3Vec3* x, b3Vec3* f, u32& iterations, const b3Vec3* b) const; | ||||
| 	void Solve_MCG(b3DenseVec3& x, const b3SparseMat33& A, b3DenseVec3& f, u32& iterations, const b3DenseVec3& b) const; | ||||
|  | ||||
| 	// Solve Ax = b using MCG with Jacobi preconditioning. | ||||
| 	// Output x and the residual error f. | ||||
| 	// This method is slower than MCG because we have to compute the preconditioning  | ||||
| 	// matrix P, but it can improve convergence. | ||||
| 	void Solve_MPCG(b3Vec3* x, b3Vec3* f, u32& iterations, const b3Vec3* b) const; | ||||
| 	void Solve_MPCG(b3DenseVec3& x, const b3SparseMat33& A, b3DenseVec3& f, u32& iterations, const b3DenseVec3& b) const; | ||||
|  | ||||
| 	b3SpringCloth * m_cloth; | ||||
| 	float32 m_h; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user