AGX Dynamics  2.38.0.2
Solver.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 #ifndef AGX_SOLVER_H
18 #define AGX_SOLVER_H
19 
20 #include <agx/Task.h>
21 #include <agx/Kernel.h>
22 // #include <agx/DirectSolverData.h>
23 
32 #include <agx/agx_vector_types.h>
33 #include <agxStream/Serializable.h>
34 
35 namespace agxSDK
36 {
37  class Simulation;
38 }
39 
40 #ifdef _MSC_VER
41 # pragma warning(push)
42 # pragma warning(disable:4355) // Disable warnings about passing the 'this' pointer to base class constructors.
43 # pragma warning( disable : 4251 ) // class X needs to have dll-interface to be used by clients of class Y
44 #endif
45 
46 
47 namespace agx
48 {
49 
50  AGX_DECLARE_POINTER_TYPES(SolveKernel);
51  AGX_DECLARE_VECTOR_TYPES(SolveKernel);
53  AGX_DECLARE_POINTER_TYPES(MobilitySolver);
54  AGX_DECLARE_VECTOR_TYPES(MobilitySolver);
55 
56  class SolveJob;
57  class DirectSolverData;
58  class INlSolveDataH5;
59 
63  class CALLABLE AGXPHYSICS_EXPORT Solver : public TaskGroup, public virtual agxStream::Serializable
64  {
65  public:
66  static agx::Model* ClassModel();
67 
68  enum JobTag
69  {
70  ITERATION = 0x1,
71  STORE_CONTACT_FORCES = 0x2,
72  RHS_UPDATE = 0x3,
73  IMPACT_ITERATION = 0x4,
74  DIRECT_SOLVE = 0x5,
75  SYNCHRONIZE_ITERATIVE = 0x6,
76 
77  JOB_TYPE_MASK = 0xFF,
78  ITERATION_INDEX_SHIFT = 8
79  };
80 
82 
83  static UInt32 getInteractionTag(const String& name);
84  static const String& getTagName(UInt32 id);
86 
87  public:
88  enum McpAlgoritmType
89  {
90  BLOCK_PIVOT,
91  KELLER,
92  HYBRID_PIVOT,
93  NUM_MCP_ALGORITHMS
94  };
95 
99  struct AGXPHYSICS_EXPORT NlMcpConfig
100  {
104  static agx::Solver::NlMcpConfig createDefault();
105 
106  agx::Solver::McpAlgoritmType mcpAlgorithmType;
107  agx::UInt numMcpIterations;
108  agx::UInt numOuterIterations;
109  agx::Real mcpTolerance;
110  agx::Real outerTolerance;
112  bool indexSetWarmStarting;
114  private:
115  // Use createDefault() instead.
116  NlMcpConfig();
117  };
118 
122  static agx::String getDescription( agx::Solver::McpAlgoritmType mcpAlgorithm );
123 
124  public:
125  Solver();
126 
130  UInt getNumRestingIterations() const;
131 
135  void setNumRestingIterations(UInt numIterations);
136 
140  UInt getNumPPGSRestingIterations() const;
141 
145  void setNumPPGSRestingIterations(UInt numPPGSIterations);
146 
150  UInt getNumDryFrictionIterations() const;
151 
155  void setNumDryFrictionIterations(UInt numIterations);
156 
161  UInt getNumImpactIterations() const;
162 
167  void setNumImpactIterations(UInt numIterations);
168 
172  bool isForceIterative() const;
173 
177  void setForceIterative(bool flag);
178 
182  agx::Solver::NlMcpConfig& getNlMcpConfig();
183 
187  agx::Solver::NlMcpConfig getNlMcpConfig() const;
188 
193  void setMcpAlgorithmType( agx::Solver::McpAlgoritmType mcpType );
194 
198  agx::Solver::McpAlgoritmType getMcpAlgorithmType() const;
199 
203  void setImpactSpeedThreshold(agx::Real threshold);
204 
208  Real getImpactSpeedThreshold() const;
209 
213  agx::Bool isStabilityReportEnable() const;
214 
218  void setStabilityReportEnable( agx::Bool enable );
219 
220 
221  void setSolverStatiticsEnable(bool enable);
222  bool getSolverStatisticsEnable() const;
223 
229  void setUseParallelPgs(bool flag);
230 
234  bool useParallelPgs() const;
235 
239  void setUseGranularWarmStarting(bool flag);
240 
244  bool useGranularWarmStarting() const;
245 
249  bool use32bitGranularBodySolver() const;
250 
254  void setEnableComplexImpactStage(bool enable);
255 
259  bool getEnableComplexImpactStage() const;
260 
267  void setUse32bitGranularBodySolver(bool flag);
268 
273  void setCalculateIterationResiduals(bool flag);
274 
278  bool getCalculateIterationResiduals() const;
279 
283  const agxData::Buffer* getIterationResiduals() const;
284 
288  agx::RealVector getIterationResidualsVector() const;
289 
293  agx::Real getGlobalRelativeResidual() const;
294 
300  void enableNlSolveDataH5( const agx::String& filename );
301 
305  void disableNlSolveDataH5();
306 
310  agx::Bool getEnableNlSolveDataH5() const;
311 
313  agx::INlSolveDataH5* getNlSolveDataH5() const;
314 
315  MobilitySolver* getMobilitySolver();
316  MobilitySolver* getMobilityReferenceSolver();
317  const SolveKernelRefVector& getKernels() const;
318 
319  SolveKernel* getStoreContactForcesKernel();
320  SolveKernel* getCommitDirectVelocitiesKernel();
321 
322  SolveKernel* getPrepareDirectSolverKernel();
323  SolveKernel* getDirectRhsKernel();
324 
325  SolveKernel* getDirectSolverKernel();
326  SolveKernel* getSynchronizeIterativeSolverKernel();
327  SolveKernel* getUpdateBoundsSolverKernel();
328  SolveKernel* getSynchronizeDirectSolverKernel();
329 
330  SolveKernel* getUpdateIterationCountKernel();
331 
332  void addKernel(SolveKernel* kernel);
333  void removeKernel(SolveKernel* kernel);
334 
335 
336  void generateSolveJobs(
337  agx::Physics::SolveIslandData& solveIsland,
338  agx::Physics::SolveGroupData& solveGroup,
339  agxSDK::Simulation* simulation,
340  agx::Physics::HierarchicalGrid::ContactZoneData& zone,
341  agx::Physics::HierarchicalGrid::ContactZoneDependencyData& zoneDependency,
342  agx::Physics::HierarchicalGrid::ContactZonePtr& iterationStartZone,
343  agx::Physics::HierarchicalGrid::ContactZonePtr& iterationEndZone,
344  UInt numTiers
345  );
346 
347  agx::Physics::SolveIslandData& getIslands();
348  bool hasIslands() const;
349 
350  DirectSolverData* getSharedSolverData(Physics::SolveIslandPtr island);
351  void registerDirectSolverData(Physics::SolveIslandPtr island, DirectSolverData* data);
352  void clearDirectSolverData();
353  DirectSolverData* getDirectSolverData(Physics::SolveIslandPtr island);
354 
356 
357  void setSimulation(agxSDK::Simulation* simulation);
358  agxSDK::Simulation* getSimulation();
359 
360  Task* getGranularVelocityIntegrationKernel();
361 
362  void reset();
363 
364  void setEnableMobilitySolverDataSharing(bool flag);
365  bool getEnableMobilitySolverDataSharing() const;
366 
368 
369  protected:
370  virtual ~Solver();
371 
372  private:
373  friend class agxSDK::Simulation;
374  void applyCustomParticlePipeline();
375 
376  private:
377  void prepareKernels();
378  void commitKernels();
379  void updateImpactSpeedThreshold();
380 
381  public:
383 
384  struct ParallelPGS
385  {
387  class IterationStart : public Job
388  {
389  public:
390  IterationStart();
391  virtual ~IterationStart();
392 
393  void reset();
394  Timer& getTimer();
395 
396  virtual void implementation() override;
397 
398  private:
399  UInt m_currentIteration;
400  Timer m_timer;
401  };
402 
404  class IterationEnd : public Job
405  {
406  public:
407  IterationEnd(Solver* solver, Physics::SolveIslandPtr island, IterationStart* iterationStart);
408  virtual ~IterationEnd();
409 
410  void setNumIterations(UInt numIterations);
411  void setExit(Job* exitJob);
412 
413  virtual void implementation() override;
414 
415  void printResidual();
416  void verifyIteration();
417  void verifyGranularBodyConstraints(const Path& path);
418  Real calculateComputeCost();
419 
420  private:
421  Solver* m_solver;
422  Physics::SolveIslandPtr m_island;
423  UInt m_numIterations;
424  UInt m_currentIteration;
425  // UInt64 m_totNumTicks;
426  IterationStart* m_iterationStart;
427  Job* m_exitJob;
428  };
429 
431  class JobGraphInstaller : public Job
432  {
433  public:
434  JobGraphInstaller(Job* startJob, Job* endJob);
435  virtual ~JobGraphInstaller();
436  virtual void implementation();
437 
438  Job exit;
439 
440  private:
441  Job* m_startJob;
442  Job* m_endJob;
443  };
444 
445  class IterationLoopInstaller : public Job
446  {
447  public:
448  IterationLoopInstaller(Solver* solver, IterationStart* startJob, IterationEnd* endJob, UInt numIterations);
449  virtual ~IterationLoopInstaller();
450  virtual void implementation();
451 
452  Job exit;
453 
454  private:
455  void initIterationCounters(const Path& path);
456  void initIterationCounters();
457 
458  private:
459  Solver* m_solver;
460  IterationStart* m_startJob;
461  IterationEnd* m_endJob;
462  UInt m_numIterations;
463  };
464 
466  AGX_DECLARE_POINTER_TYPES(JobGraph);
467  class JobGraph : public Referenced
468  {
469  public:
470  Job* rhsStart;
471  Job* rhsEnd;
472 
473  Job* storeContactForcesStart;
474  Job* storeContactForcesEnd;
475 
476  IterationStart* iterationStart;
477  IterationEnd* iterationEnd;
478  JobGroup* serialIterationJob;
479 
480  Job* residualStart;
481  Job* residualEnd;
482 
483  Solver* solver;
484 
485  public:
486 
487  JobGraph(Solver* solver_, agx::Physics::SolveIslandPtr island);
488  void init(agx::Physics::SolveIslandPtr island);
489 
490 
491  void createZoneIndependentJobs(
492  agx::Physics::HierarchicalGrid::ContactZoneData& zone,
493  agx::Physics::SolveIslandPtr solveIsland,
494  JobGroup*& groupIt,
495  SolveJob*& jobIt,
496  SolveKernel* particleParticleKernel,
497  SolveKernel* particleGeometryKernel,
498  SolveKernel* geometryGeometryKernel,
499  Job* preJob,
500  Job* postJob
501  );
502 
503  void createZoneRhsJobs(
504  agx::Physics::HierarchicalGrid::ContactZoneData& zone,
505  agx::Physics::SolveIslandPtr solveIsland,
506  JobGroup*& groupIt,
507  SolveJob*& jobIt,
508  SolveKernel* particleParticleKernel,
509  SolveKernel* particleGeometryKernel,
510  SolveKernel* geometryGeometryKernel
511  );
512 
513  void createZoneStoreContactForcesJobs(
514  agx::Physics::HierarchicalGrid::ContactZoneData& zone,
515  agx::Physics::SolveIslandPtr solveIsland,
516  JobGroup*& groupIt,
517  SolveJob*& jobIt,
518  SolveKernel* particleParticleKernel,
519  SolveKernel* particleGeometryKernel,
520  SolveKernel* geometryGeometryKernel
521  );
522 
523  void createZoneResidualJobs(
524  agx::Physics::HierarchicalGrid::ContactZoneData& zone,
525  agx::Physics::SolveIslandPtr solveIsland,
526  JobGroup*& groupIt,
527  SolveJob*& jobIt,
528  SolveKernel* particleParticleKernel,
529  SolveKernel* particleGeometryKernel,
530  SolveKernel* geometryGeometryKernel
531  );
532 
533 
534  void createIslandRhsJobs(
535  agx::Physics::SolveIslandPtr solveIsland,
536  SolveJob*& jobIt
537  );
538 
539 
540  void createIslandStoreContactForcesJobs(
541  agx::Physics::SolveIslandPtr solveIsland,
542  SolveJob*& jobIt
543  );
544 
545  void createZoneIterationJobs(
546  agx::Physics::HierarchicalGrid::ContactZoneData& zone,
547  agx::Physics::HierarchicalGrid::ContactZoneDependencyData& zoneDependency,
548  agx::Physics::SolveIslandPtr solveIsland,
549  JobGroup*& groupIt,
550  SolveJob*& jobIt,
551  UInt numTiers,
552  SolveKernel* particleParticleKernel,
553  SolveKernel* particleGeometryKernel,
554  SolveKernel* geometryGeometryKernel
555  );
556 
557  void createIslandIterationJobs(
558  agx::Physics::SolveIslandPtr solveIsland,
559  SolveJob *& jobIt
560  );
561 
562 
563  protected:
564  virtual ~JobGraph();
565 
566  private:
567  agxData::IndexArray m_geometryGeometryContactConstraints;
568  agxData::IndexArray m_particleGeometryContactConstraints;
569  agxData::IndexArray m_binaryConstraints;
570  agxData::IndexArray m_manyBodyConstraints;
571  agxData::IndexArray m_directBodies;
572  agxData::BufferRef m_indexListBuffer;
573  Physics::SolveGroupPtr m_solveGroupPtrs[4];
574  };
575 
576  };
577 
579 
580 
581 
582 
583  ParallelPGS::JobGraph* generateParallelPgsJobGraph(
584  agx::Physics::SolveIslandPtr solveIsland,
585  agxSDK::Simulation* simulation,
586  agx::Physics::HierarchicalGrid::ContactZoneData& zone,
587  agx::Physics::HierarchicalGrid::ContactZoneDependencyData& zoneDependency,
590  agx::UInt numTiers
591  );
592 
593  ParallelPGS::JobGraph* getParallelPgsJobGraph();
594  void addJobGraphInstaller(Job* loopInstaller);
595 
596 
597  private:
598 
599  struct SolveJobContext
600  {
601  agx::Physics::SolveIslandData* solveIsland;
602  agx::Physics::SolveGroupData* solveGroup;
603  agxSDK::Simulation* simulation;
604  agx::Physics::HierarchicalGrid::ContactZoneData* zone;
605  agx::Physics::HierarchicalGrid::ContactZoneDependencyData* zoneDependency;
608  agx::UInt numTiers;
609  };
610 
611  SolveJobContext m_solveJobContext;
612 
613  private:
614  SolveKernelRefVector m_kernels;
615 
616  agxData::ValueRefT<UInt> m_numImpactIterations;
617  agxData::ValueRefT<UInt> m_numRestingIterations;
618  agxData::ValueRefT<UInt> m_numPPGSRestingIterations;
619  agxData::ValueRefT<UInt> m_numDryFrictionIterations;
620  agxData::ValueRefT<Bool> m_forceIterative;
621  agxData::ValueRefT<Real> m_impactSpeedThreshold;
622  agxData::ValueRefT<Bool> m_stabilityReportEnable;
623  bool m_impactSpeedExplicitlySet;
624  agxData::ValueRefT<Bool> m_enableComplexImpactStage;
625 
626  NlMcpConfig m_nlMcpConfig;
627 
628  agxData::BufferRef m_iterationResiduals;
629  bool m_calculateIterationResiduals;
630 
631  SolveKernelRef m_storeContactForcesKernel;
632  SolveKernelRef m_commitDirectVelocitiesKernel;
633 
634  SolveKernelRef m_directRhsKernel;
635 
636  SolveKernelRef m_prepareDirectSolverKernel;
637  SolveKernelRef m_directSolverKernel;
638  SolveKernelRef m_synchronizeIterativeSolverKernel;
639  SolveKernelRef m_updateDirectBounds;
640  SolveKernelRef m_synchronizeDirectSolverKernel;
641  SolveKernelRef m_iterationCountKernel;
642 
643  HashSet<Job* > m_visitedJobs;
644  bool m_useParallelPGS;
645  bool m_use32bitGranularSolver;
646  bool m_useGranularWarmStarting;
647  bool m_gatherStatistics;
648  bool m_enableMobilitySolverDataSharing;
649 
650  ParallelPGS::JobGraphRef m_parallelPgsJobGraph;
651  agx::Vector<Job* > m_jobGraphInstallers;
652 
653  MobilitySolverRefVector m_mobilitySolvers;
654  UInt m_numActiveMobilitySolvers;
655 
656  agxData::BufferRef m_solveJobBuffer;
657  agxData::BufferRef m_solveWrapperJobBuffer;
658 
659  agxData::BufferRef m_pgsSolveJobBuffer;
660  agxData::BufferRef m_pgsSolveWrapperJobBuffer;
661 
662  typedef agx::Vector<ref_ptr<Referenced> > DirectSolverDataTable;
663  DirectSolverDataTable m_directSolverDataTable;
664 
665  agxSDK::Simulation* m_simulation;
666 
667  agx::TaskRef m_granularIntegrateVelocitiesKernel;
668  JobPtrVector m_jobStack;
669  agx::Physics::SolveIslandData* m_islands;
670 
671  ref_ptr<Referenced> m_nlSolveDataH5;
672  };
673 
674 
675  //---------------------------------------------------------------
676 
677  class AGXPHYSICS_EXPORT MobilitySolver : public Solver
678  {
679  public:
680  MobilitySolver(Solver* masterSolver, bool isReference);
681 
682  Solver* getMasterSolver();
683  bool isReferenceSolver() const;
684 
685  void addKernelCopy(SolveKernel* kernel);
686  void removeKernelCopy(SolveKernel* kernel);
687 
688  SolveKernel* getMobilityKernel(SolveKernel* kernel);
689 
690  void prepare();
691  void verify();
692  void copyToMaster();
693  void copyFromMaster();
694 
695  agxData::EntityStorage* getRigidBodyStorage();
696 
697  protected:
698  virtual ~MobilitySolver();
699 
700  private:
701  void copy(bool import);
702 
703  void preSolve(Task* task);
704  void postSolve(Task* task);
705  agxData::EntityStorage* setupRigidBodyStorage();
706  agxData::EntityStorage* setupConstraintRowStorage(const Path& storagePath);
707 
708  void setupSynchronizedBuffer(agxData::EntityStorage* masterStorage, agxData::EntityStorage* localStorage, agxData::Attribute* attribute);
709 
710  struct BufferSynchronization
711  {
712  agxData::EntityStorageRef masterStorage;
713  agxData::EntityStorageRef localStorage;
714  agxData::AttributeRef attribute;
715  };
716 
717  private:
718  Solver* m_masterSolver;
719  bool m_isReference;
720  agxData::EntityStorageRef m_rigidBodyStorage;
721  agxData::EntityStorageRef m_contactConstraintRowStorage;
722  agxData::EntityStorageRef m_binaryConstraintRowStorage;
723  agxData::EntityStorageRef m_manyBodyConstraintRowStorage;
724  TaskRef m_preSolveTask;
725  TaskRef m_postSolveTask;
726  Task::ExecutionEvent::CallbackType m_preSolveCallback;
727  Task::ExecutionEvent::CallbackType m_postSolveCallback;
728 
729  typedef HashTable<SolveKernel *, SolveKernel *> KernelTable;
730  KernelTable m_kernelTable;
731 
732  Vector<BufferSynchronization> m_bufferSynchronizations;
733  };
734 
735 
736  //---------------------------------------------------------------
737 
738  AGX_DECLARE_POINTER_TYPES(SolveModel);
739  AGX_DECLARE_VECTOR_TYPES(SolveModel);
740  typedef HashTable<String, SolveModel* > SolveModelTable;
741 
742  class SolveModel : public Object
743  {
744  public:
745  enum SolveType
746  {
747  INVALID_SOLVE_TYPE = -1,
748  ITERATIVE = (1<<0),
749  DIRECT_AND_ITERATIVE = (1<<1),
750  DIRECT = (1<<2),
751  SPLIT = (1<<3)
752  };
753 
754  enum ConstraintType
755  {
756  INVALID_CONSTRAINT_TYPE = -1,
757  CONTACT_CONSTRAINT,
761  };
762 
763  static agx::Model* ClassModel();
764  static SolveModel::SolveType toSolveType( const agx::String& str );
765  static SolveModel::ConstraintType toConstraintType( const agx::String& str );
766  static SolveModel* load(TiXmlElement* eModel, agx::Device* device);
767  void configure(TiXmlElement* eModel);
768 
769  public:
770  SolveModel(const Name& name, SolveType solveType, ConstraintType constraintType);
771 
772  bool isDirect() const;
773  SolveType getSolveType() const;
774  ConstraintType getConstraintType() const;
775  agx::UInt32 getId() const;
776 
777  SolveKernel* getPrepareDirectSolveKernel();
778  SolveKernel* getIterativeSolveKernel();
779  SolveKernel* getInternalZoneBeginKernel();
780  SolveKernel* getInternalZoneEndKernel();
781  SolveKernel* getIntegrateVelocitiesKernel();
782  SolveKernel* getUpdateRhsKernel();
783  SolveKernel* getResidualKernel();
784  SolveKernel* getSynchronizeIterativeKernel();
785  SolveKernel* getSynchronizeDirectKernel();
786  SolveKernel* getStoreContactForcesKernel();
787 
788  void setPrepareDirectSolveKernel(SolveKernel* kernel);
789  void setIterativeSolveKernel(SolveKernel* kernel);
790  void setIntegrateVelocitiesKernel(SolveKernel* kernel);
791  void setUpdateRhsKernel(SolveKernel* kernel);
792  void setResidualKernel(SolveKernel* kernel);
793  void setSynchronizeIterativeKernel(SolveKernel* kernel);
794  void setSynchronizeDirectKernel(SolveKernel* kernel);
795 
796 
797  const SolveKernelRefVector& getKernels() const;
798 
799  void setId(agx::UInt32 id);
800  protected:
801  virtual ~SolveModel();
802 
803  private:
804  UInt32 m_id;
805  SolveType m_solveType;
806  ConstraintType m_constraintType;
807  SolveKernelRef m_prepareDirectSolverKernel;
808  SolveKernelRef m_iterativeSolveKernel;
809  SolveKernelRef m_internalZoneBeginKernel;
810  SolveKernelRef m_internalZoneEndKernel;
811  SolveKernelRef m_integrateVelocitiesKernel;
812  SolveKernelRef m_updateRhsKernel;
813  SolveKernelRef m_residualKernel;
814  SolveKernelRef m_storeContactForcesKernel;
815  SolveKernelRef m_synchronizeIterativeKernel;
816  SolveKernelRef m_synchronizeDirectKernel;
817  SolveKernelRefVector m_kernels;
818  };
819 
820  AGXPHYSICS_EXPORT Physics::SolveGroupPtr getSolveGroup(Physics::SolveIslandPtr island, const String& name);
821 
822  //---------------------------------------------------------------
823 
824  struct AGXPHYSICS_EXPORT SolveContext
825  {
826  typedef agx::Physics::HierarchicalGrid::ContactZoneInstance ContactZoneInstance;
827 
828  SolveContext();
829  SolveContext(
830  agxData::IndexArray interactions_, Physics::SolveIslandPtr island_, Physics::SolveGroupPtr group_,
831  ContactZoneInstance contactZone_ = ContactZoneInstance());
832 
833 
834  agxData::IndexArray interactions;
835  Physics::SolveIslandPtr island;
836  Physics::SolveGroupPtr group;
837  ContactZoneInstance contactZone;
838  };
839 
840  //---------------------------------------------------------------
841 
842  class AGXPHYSICS_EXPORT SolveJob : public Job
843  {
844  public:
845  typedef Callback1<SolveContext> SolveCallback;
846 
847  public:
848  SolveJob();
849  SolveJob(const SolveCallback& callback, SolveContext context, agx::UInt32 cost);
850  virtual ~SolveJob();
851 
852  void init(const SolveCallback& callback, SolveContext context, agx::UInt32 cost);
853 
854  SolveContext& getContext();
855 
856  protected:
857  virtual void implementation() override;
858 
859  private:
860  // void dispatch();
861 
862  protected:
863  SolveCallback m_solveCallback;
864  SolveContext m_context;
865  };
866 
867  //---------------------------------------------------------------
868 
869  template <class T>
870  class SolveJobT : public SolveJob
871  {
872  public:
873  SolveJobT();
874  SolveJobT(SolveContext context, agx::UInt32 cost);
875  virtual ~SolveJobT();
876 
877  protected:
878  virtual void implementation() override;
879 
880  };
881 
882  //---------------------------------------------------------------
883 
884  class AGXPHYSICS_EXPORT SolveKernel : public CpuKernel
885  {
886  public:
887  typedef SolveJob::SolveCallback SolveDispatch;
888 
889  public:
890  SolveKernel(const Name& name, SolveDispatch dispatch);
891 
892  const SolveDispatch& getDispatch() const;
893 
894  virtual void constructJob(SolveJob* job) = 0;
895  protected:
896  virtual ~SolveKernel();
897 
898  private:
899  SolveDispatch m_dispatch;
900  };
901 
903 
904  //---------------------------------------------------------------
905 
906  /* Implementation */
907  AGX_FORCE_INLINE UInt Solver::getNumImpactIterations() const { return m_numImpactIterations->get(); }
908  AGX_FORCE_INLINE UInt Solver::getNumRestingIterations() const { return m_numRestingIterations->get(); }
909  AGX_FORCE_INLINE UInt Solver::getNumPPGSRestingIterations() const { return m_numPPGSRestingIterations->get(); }
910  AGX_FORCE_INLINE UInt Solver::getNumDryFrictionIterations() const { return m_numDryFrictionIterations->get(); }
911  AGX_FORCE_INLINE bool Solver::isForceIterative() const { return m_forceIterative->get(); }
912  AGX_FORCE_INLINE const SolveKernelRefVector& Solver::getKernels() const { return m_kernels; }
913 
914  AGX_FORCE_INLINE SolveKernel* Solver::getStoreContactForcesKernel() { return m_storeContactForcesKernel; }
915  AGX_FORCE_INLINE SolveKernel* Solver::getCommitDirectVelocitiesKernel() { return m_commitDirectVelocitiesKernel; }
916 
917  AGX_FORCE_INLINE SolveKernel* Solver::getDirectRhsKernel() { return m_directRhsKernel; }
918 
919 
920  AGX_FORCE_INLINE SolveKernel* Solver::getPrepareDirectSolverKernel() { return m_prepareDirectSolverKernel; }
921  AGX_FORCE_INLINE SolveKernel* Solver::getDirectSolverKernel() { return m_directSolverKernel; }
922  AGX_FORCE_INLINE SolveKernel* Solver::getSynchronizeIterativeSolverKernel() { return m_synchronizeIterativeSolverKernel; }
923  AGX_FORCE_INLINE SolveKernel* Solver::getUpdateBoundsSolverKernel() { return m_updateDirectBounds; }
924  AGX_FORCE_INLINE SolveKernel* Solver::getSynchronizeDirectSolverKernel() { return m_synchronizeDirectSolverKernel; }
925  AGX_FORCE_INLINE SolveKernel* Solver::getUpdateIterationCountKernel() { return m_iterationCountKernel; }
926 
927  AGX_FORCE_INLINE DirectSolverData* Solver::getDirectSolverData(Physics::SolveIslandPtr island)
928  {
929  return (DirectSolverData *)m_directSolverDataTable[island.getId()].get();
930  }
931 
932 
933  //-----------------------------------------------------------------------------------------------------
934 
935  AGX_FORCE_INLINE bool SolveModel::isDirect() const { return m_solveType > ITERATIVE; }
936  AGX_FORCE_INLINE SolveModel::SolveType SolveModel::getSolveType() const { return m_solveType; }
937  AGX_FORCE_INLINE SolveModel::ConstraintType SolveModel::getConstraintType() const { return m_constraintType; }
938  AGX_FORCE_INLINE agx::UInt32 SolveModel::getId() const { return m_id; }
939  AGX_FORCE_INLINE SolveKernel* SolveModel::getPrepareDirectSolveKernel() { return m_prepareDirectSolverKernel; }
940  AGX_FORCE_INLINE SolveKernel* SolveModel::getIterativeSolveKernel() { return m_iterativeSolveKernel; }
941  AGX_FORCE_INLINE SolveKernel* SolveModel::getInternalZoneBeginKernel() { return m_internalZoneBeginKernel; }
942  AGX_FORCE_INLINE SolveKernel* SolveModel::getInternalZoneEndKernel() { return m_internalZoneEndKernel; }
943  AGX_FORCE_INLINE SolveKernel* SolveModel::getIntegrateVelocitiesKernel() { return m_integrateVelocitiesKernel; }
944  AGX_FORCE_INLINE SolveKernel* SolveModel::getUpdateRhsKernel() { return m_updateRhsKernel; }
945  AGX_FORCE_INLINE SolveKernel* SolveModel::getResidualKernel() { return m_residualKernel; }
946  AGX_FORCE_INLINE SolveKernel* SolveModel::getStoreContactForcesKernel() { return m_storeContactForcesKernel; }
947  AGX_FORCE_INLINE SolveKernel* SolveModel::getSynchronizeIterativeKernel() { return m_synchronizeIterativeKernel; }
948  AGX_FORCE_INLINE SolveKernel* SolveModel::getSynchronizeDirectKernel() { return m_synchronizeDirectKernel; }
949 
950  AGX_FORCE_INLINE const SolveKernelRefVector& SolveModel::getKernels() const { return m_kernels; }
951 
952  //-----------------------------------------------------------------------------------------------------
953 
954  AGX_FORCE_INLINE SolveContext::SolveContext() {}
955  AGX_FORCE_INLINE SolveContext::SolveContext(
956  agxData::IndexArray interactions_,
957  Physics::SolveIslandPtr island_,
958  Physics::SolveGroupPtr group_,
959  ContactZoneInstance contactZone_)
960  : interactions(interactions_)
961  , island(island_)
962  , group(group_)
963  , contactZone(contactZone_)
964  {}
965 
966  //-----------------------------------------------------------------------------------------------------
967 
968  AGX_FORCE_INLINE SolveJob::SolveJob() // : Job(Callback(&SolveJob::dispatch, this))
969  {
970  }
971 
972  AGX_FORCE_INLINE SolveJob::SolveJob(const SolveCallback& callback, SolveContext context, agx::UInt32 cost) // : Job(Callback(&SolveJob::dispatch, this))
973  {
974  this->init(callback, context, cost);
975  }
976 
977  AGX_FORCE_INLINE void SolveJob::init(const SolveCallback& callback, SolveContext context, agx::UInt32 cost)
978  {
979  m_context = context;
980  m_solveCallback = callback;
981 
982  // Job::init(Callback(&SolveJob::dispatch, this), cost);
983  Job::init(Job::Callback(), cost);
984  }
985 
986 
987  AGX_FORCE_INLINE SolveContext& SolveJob::getContext() { return m_context; }
988 
989  //-----------------------------------------------------------------------------------------------------
990 
991  template <class T>
992  SolveJobT<T>::SolveJobT() : SolveJob()
993  {
994  }
995 
996  template <class T>
997  SolveJobT<T>::SolveJobT(SolveContext context, agx::UInt32 cost) : SolveJob(SolveCallback(), context, cost)
998  {
999  }
1000 
1001  template <class T>
1002  SolveJobT<T>::~SolveJobT()
1003  {
1004  }
1005 
1006  template <class T>
1007  void SolveJobT<T>::implementation()
1008  {
1009  agxAssert(dynamic_cast<T*>(m_task));
1010  static_cast<T*>(m_task)->dispatch(m_context);
1011  }
1012 
1013 
1014  AGX_FORCE_INLINE const SolveKernel::SolveDispatch& SolveKernel::getDispatch() const { return m_dispatch; }
1015 }
1016 
1017 AGX_TYPE_BINDING(agx::SolveJob, "SolveJob")
1018 
1019 #ifdef _MSC_VER
1020 # pragma warning(pop)
1021 #endif
1022 
1023 #endif /* AGX_SOLVER_H */
ContactZoneEntity.h
agx::UInt
uint64_t UInt
Definition: Integer.h:27
Kernel.h
agx::Real
double Real
Definition: Real.h:42
agx::Physics::SolveIslandPtr
Pointer to a entity instance of type Physics.SolveIsland.
Definition: SolveIslandEntity.h:185
agx::Vector
Templated vector class.
Definition: Vector.h:52
GeometryContactEntity.h
agx::Job::init
void init(const Callback &callback=Callback(), agx::UInt32 costEstimate=100)
Initialize the job.
Definition: Job.h:558
agxStream::Serializable
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Definition: Serializable.h:44
CALLABLE
#define CALLABLE
Definition: macros.h:72
Task.h
DOXYGEN_END_INTERNAL_BLOCK
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:97
DOXYGEN_START_INTERNAL_BLOCK
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:96
ParticleGeometryContactEntity.h
agxAssert
#define agxAssert(expr)
Definition: debug.h:143
SolveIslandEntity.h
agxData::EntityStorage
Data storage for a collection of entity instances of a specified EntityModel.
Definition: EntityStorage.h:72
agx::Callback::Callback
Callback()
Definition: Callback.h:268
agx::EventT< Callback1< Task * > >::CallbackType
Callback1< Task * > CallbackType
Definition: Event.h:37
AGXSTREAM_DECLARE_SERIALIZABLE
#define AGXSTREAM_DECLARE_SERIALIZABLE(T)
Use this in a Serializable class to add the required methods Important: Use full namespace in the dec...
Definition: Serializable.h:207
agx::VectorPOD< Real >
agx
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Definition: AddedMassInteraction.h:22
AGXPHYSICS_EXPORT
#define AGXPHYSICS_EXPORT
agx::Model
A model is an abstract representation of the class of an agx::Object.
Definition: Model.h:40
agxData::Array< agx::Index >
BinaryConstraintEntity.h
AGX_DECLARE_VECTOR_TYPES
#define AGX_DECLARE_VECTOR_TYPES(type)
Definition: Vector.h:34
agx::Physics::HierarchicalGrid::ContactZonePtr
Pointer to a entity instance of type Physics.HierarchicalGrid.ContactZone.
Definition: ContactZoneEntity.h:241
agx::ref_ptr< Buffer >
agxSDK::Simulation
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:125
SolveGroupEntity.h
ContactZoneDependencyEntity.h
agxData::Buffer
Abstract representation of a data buffer.
Definition: Buffer.h:55
agx::TaskRef
agx::ref_ptr< Task > TaskRef
Definition: Task.h:42
Serializable.h
agx::JobPtrVector
VectorPOD< class Job * > JobPtrVector
Definition: Job.h:51
AGX_DECLARE_POINTER_TYPES
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
agx::GraphNode::BINARY_CONSTRAINT
@ BINARY_CONSTRAINT
Definition: GraphNode.h:34
agx::Bool
bool Bool
Definition: Integer.h:40
agx::GraphNode::MANY_BODY_CONSTRAINT
@ MANY_BODY_CONSTRAINT
Definition: GraphNode.h:35
agxData::ValueRefT< UInt >
agx::Device
An agx::Device is an abstract representation of a device on which data can be stored and processed.
Definition: Device.h:57
agx::AgXString
Definition: String.h:31
AGX_TYPE_BINDING
#define AGX_TYPE_BINDING(_Type, _Name)
Definition: Type.h:179
agxSDK
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:30
agx::init
void AGXPHYSICS_EXPORT init()
Initialize AGX Dynamics API including thread resources and must be executed before using the AGX API.
agx::String
AgXString< std::string > String
Definition: String.h:427
agx::GraphNode::STRONG_INTERACTION
@ STRONG_INTERACTION
Definition: GraphNode.h:36
agxData::Attribute
An abstract attribute description, part of an Entity.
Definition: Attribute.h:57
agx::UInt32
uint32_t UInt32
Definition: Integer.h:32
agx_vector_types.h
AGX_FORCE_INLINE
#define AGX_FORCE_INLINE
Definition: macros.h:58
ManyBodyConstraintEntity.h