AGX Dynamics  2.37.2.0
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 
251 
258  void setUse32bitGranularBodySolver(bool flag);
259 
260 
265  void setCalculateIterationResiduals(bool flag);
266 
270  bool getCalculateIterationResiduals() const;
271 
275  const agxData::Buffer* getIterationResiduals() const;
276 
280  agx::RealVector getIterationResidualsVector() const;
281 
285  agx::Real getGlobalRelativeResidual() const;
286 
292  void enableNlSolveDataH5( const agx::String& filename );
293 
297  void disableNlSolveDataH5();
298 
302  agx::Bool getEnableNlSolveDataH5() const;
303 
305  agx::INlSolveDataH5* getNlSolveDataH5() const;
306 
307  MobilitySolver* getMobilitySolver();
308  MobilitySolver* getMobilityReferenceSolver();
309  const SolveKernelRefVector& getKernels() const;
310 
311  SolveKernel* getStoreContactForcesKernel();
312  SolveKernel* getCommitDirectVelocitiesKernel();
313 
314  SolveKernel* getPrepareDirectSolverKernel();
315  SolveKernel* getDirectRhsKernel();
316 
317  SolveKernel* getDirectSolverKernel();
318  SolveKernel* getSynchronizeIterativeSolverKernel();
319  SolveKernel* getUpdateBoundsSolverKernel();
320  SolveKernel* getSynchronizeDirectSolverKernel();
321 
322  SolveKernel* getUpdateIterationCountKernel();
323 
324  void addKernel(SolveKernel* kernel);
325  void removeKernel(SolveKernel* kernel);
326 
327 
328  void generateSolveJobs(
329  agx::Physics::SolveIslandData& solveIsland,
330  agx::Physics::SolveGroupData& solveGroup,
331  agxSDK::Simulation* simulation,
332  agx::Physics::HierarchicalGrid::ContactZoneData& zone,
333  agx::Physics::HierarchicalGrid::ContactZoneDependencyData& zoneDependency,
334  agx::Physics::HierarchicalGrid::ContactZonePtr& iterationStartZone,
335  agx::Physics::HierarchicalGrid::ContactZonePtr& iterationEndZone,
336  UInt numTiers
337  );
338 
339  agx::Physics::SolveIslandData& getIslands();
340  bool hasIslands() const;
341 
342  DirectSolverData* getSharedSolverData(Physics::SolveIslandPtr island);
343  void registerDirectSolverData(Physics::SolveIslandPtr island, DirectSolverData* data);
344  void clearDirectSolverData();
345  DirectSolverData* getDirectSolverData(Physics::SolveIslandPtr island);
346 
348 
349  void setSimulation(agxSDK::Simulation* simulation);
350  agxSDK::Simulation* getSimulation();
351 
352  Task* getGranularVelocityIntegrationKernel();
353 
354  void reset();
355 
356  void setEnableMobilitySolverDataSharing(bool flag);
357  bool getEnableMobilitySolverDataSharing() const;
358 
360 
361  protected:
362  virtual ~Solver();
363 
364  private:
365  friend class agxSDK::Simulation;
366  void applyCustomParticlePipeline();
367 
368  private:
369  void prepareKernels();
370  void commitKernels();
371  void updateImpactSpeedThreshold();
372 
373  public:
375 
376  struct ParallelPGS
377  {
379  class IterationStart : public Job
380  {
381  public:
382  IterationStart();
383  virtual ~IterationStart();
384 
385  void reset();
386  Timer& getTimer();
387 
388  virtual void implementation() override;
389 
390  private:
391  UInt m_currentIteration;
392  Timer m_timer;
393  };
394 
396  class IterationEnd : public Job
397  {
398  public:
399  IterationEnd(Solver* solver, Physics::SolveIslandPtr island, IterationStart* iterationStart);
400  virtual ~IterationEnd();
401 
402  void setNumIterations(UInt numIterations);
403  void setExit(Job* exitJob);
404 
405  virtual void implementation() override;
406 
407  void printResidual();
408  void verifyIteration();
409  void verifyGranularBodyConstraints(const Path& path);
410  Real calculateComputeCost();
411 
412  private:
413  Solver* m_solver;
414  Physics::SolveIslandPtr m_island;
415  UInt m_numIterations;
416  UInt m_currentIteration;
417  // UInt64 m_totNumTicks;
418  IterationStart* m_iterationStart;
419  Job* m_exitJob;
420  };
421 
423  class JobGraphInstaller : public Job
424  {
425  public:
426  JobGraphInstaller(Job* startJob, Job* endJob);
427  virtual ~JobGraphInstaller();
428  virtual void implementation();
429 
430  Job exit;
431 
432  private:
433  Job* m_startJob;
434  Job* m_endJob;
435  };
436 
437  class IterationLoopInstaller : public Job
438  {
439  public:
440  IterationLoopInstaller(Solver* solver, IterationStart* startJob, IterationEnd* endJob, UInt numIterations);
441  virtual ~IterationLoopInstaller();
442  virtual void implementation();
443 
444  Job exit;
445 
446  private:
447  void initIterationCounters(const Path& path);
448  void initIterationCounters();
449 
450  private:
451  Solver* m_solver;
452  IterationStart* m_startJob;
453  IterationEnd* m_endJob;
454  UInt m_numIterations;
455  };
456 
458  AGX_DECLARE_POINTER_TYPES(JobGraph);
459  class JobGraph : public Referenced
460  {
461  public:
462  Job* rhsStart;
463  Job* rhsEnd;
464 
465  Job* storeContactForcesStart;
466  Job* storeContactForcesEnd;
467 
468  IterationStart* iterationStart;
469  IterationEnd* iterationEnd;
470  JobGroup* serialIterationJob;
471 
472  Job* residualStart;
473  Job* residualEnd;
474 
475  Solver* solver;
476 
477  public:
478 
479  JobGraph(Solver* solver_, agx::Physics::SolveIslandPtr island);
480  void init(agx::Physics::SolveIslandPtr island);
481 
482 
483  void createZoneIndependentJobs(
484  agx::Physics::HierarchicalGrid::ContactZoneData& zone,
485  agx::Physics::SolveIslandPtr solveIsland,
486  JobGroup*& groupIt,
487  SolveJob*& jobIt,
488  SolveKernel* particleParticleKernel,
489  SolveKernel* particleGeometryKernel,
490  SolveKernel* geometryGeometryKernel,
491  Job* preJob,
492  Job* postJob
493  );
494 
495  void createZoneRhsJobs(
496  agx::Physics::HierarchicalGrid::ContactZoneData& zone,
497  agx::Physics::SolveIslandPtr solveIsland,
498  JobGroup*& groupIt,
499  SolveJob*& jobIt,
500  SolveKernel* particleParticleKernel,
501  SolveKernel* particleGeometryKernel,
502  SolveKernel* geometryGeometryKernel
503  );
504 
505  void createZoneStoreContactForcesJobs(
506  agx::Physics::HierarchicalGrid::ContactZoneData& zone,
507  agx::Physics::SolveIslandPtr solveIsland,
508  JobGroup*& groupIt,
509  SolveJob*& jobIt,
510  SolveKernel* particleParticleKernel,
511  SolveKernel* particleGeometryKernel,
512  SolveKernel* geometryGeometryKernel
513  );
514 
515  void createZoneResidualJobs(
516  agx::Physics::HierarchicalGrid::ContactZoneData& zone,
517  agx::Physics::SolveIslandPtr solveIsland,
518  JobGroup*& groupIt,
519  SolveJob*& jobIt,
520  SolveKernel* particleParticleKernel,
521  SolveKernel* particleGeometryKernel,
522  SolveKernel* geometryGeometryKernel
523  );
524 
525 
526  void createIslandRhsJobs(
527  agx::Physics::SolveIslandPtr solveIsland,
528  SolveJob*& jobIt
529  );
530 
531 
532  void createIslandStoreContactForcesJobs(
533  agx::Physics::SolveIslandPtr solveIsland,
534  SolveJob*& jobIt
535  );
536 
537  void createZoneIterationJobs(
538  agx::Physics::HierarchicalGrid::ContactZoneData& zone,
539  agx::Physics::HierarchicalGrid::ContactZoneDependencyData& zoneDependency,
540  agx::Physics::SolveIslandPtr solveIsland,
541  JobGroup*& groupIt,
542  SolveJob*& jobIt,
543  UInt numTiers,
544  SolveKernel* particleParticleKernel,
545  SolveKernel* particleGeometryKernel,
546  SolveKernel* geometryGeometryKernel
547  );
548 
549  void createIslandIterationJobs(
550  agx::Physics::SolveIslandPtr solveIsland,
551  SolveJob *& jobIt
552  );
553 
554 
555  protected:
556  virtual ~JobGraph();
557 
558  private:
559  agxData::IndexArray m_geometryGeometryContactConstraints;
560  agxData::IndexArray m_particleGeometryContactConstraints;
561  agxData::IndexArray m_binaryConstraints;
562  agxData::IndexArray m_manyBodyConstraints;
563  agxData::IndexArray m_directBodies;
564  agxData::BufferRef m_indexListBuffer;
565  Physics::SolveGroupPtr m_solveGroupPtrs[4];
566  };
567 
568  };
569 
571 
572 
573 
574 
575  ParallelPGS::JobGraph* generateParallelPgsJobGraph(
576  agx::Physics::SolveIslandPtr solveIsland,
577  agxSDK::Simulation* simulation,
578  agx::Physics::HierarchicalGrid::ContactZoneData& zone,
579  agx::Physics::HierarchicalGrid::ContactZoneDependencyData& zoneDependency,
582  agx::UInt numTiers
583  );
584 
585  ParallelPGS::JobGraph* getParallelPgsJobGraph();
586  void addJobGraphInstaller(Job* loopInstaller);
587 
588 
589  private:
590 
591  struct SolveJobContext
592  {
593  agx::Physics::SolveIslandData* solveIsland;
594  agx::Physics::SolveGroupData* solveGroup;
595  agxSDK::Simulation* simulation;
596  agx::Physics::HierarchicalGrid::ContactZoneData* zone;
597  agx::Physics::HierarchicalGrid::ContactZoneDependencyData* zoneDependency;
600  agx::UInt numTiers;
601  };
602 
603  SolveJobContext m_solveJobContext;
604 
605  private:
606  SolveKernelRefVector m_kernels;
607 
608  agxData::ValueRefT<UInt> m_numImpactIterations;
609  agxData::ValueRefT<UInt> m_numRestingIterations;
610  agxData::ValueRefT<UInt> m_numPPGSRestingIterations;
611  agxData::ValueRefT<UInt> m_numDryFrictionIterations;
612  agxData::ValueRefT<Bool> m_forceIterative;
613  agxData::ValueRefT<Real> m_impactSpeedThreshold;
614  agxData::ValueRefT<Bool> m_stabilityReportEnable;
615  bool m_impactSpeedExplicitlySet;
616 
617  NlMcpConfig m_nlMcpConfig;
618 
619  agxData::BufferRef m_iterationResiduals;
620  bool m_calculateIterationResiduals;
621 
622  SolveKernelRef m_storeContactForcesKernel;
623  SolveKernelRef m_commitDirectVelocitiesKernel;
624 
625  SolveKernelRef m_directRhsKernel;
626 
627  SolveKernelRef m_prepareDirectSolverKernel;
628  SolveKernelRef m_directSolverKernel;
629  SolveKernelRef m_synchronizeIterativeSolverKernel;
630  SolveKernelRef m_updateDirectBounds;
631  SolveKernelRef m_synchronizeDirectSolverKernel;
632  SolveKernelRef m_iterationCountKernel;
633 
634  HashSet<Job* > m_visitedJobs;
635  bool m_useParallelPGS;
636  bool m_use32bitGranularSolver;
637  bool m_useGranularWarmStarting;
638  bool m_gatherStatistics;
639  bool m_enableMobilitySolverDataSharing;
640 
641  ParallelPGS::JobGraphRef m_parallelPgsJobGraph;
642  agx::Vector<Job* > m_jobGraphInstallers;
643 
644  MobilitySolverRefVector m_mobilitySolvers;
645  UInt m_numActiveMobilitySolvers;
646 
647  agxData::BufferRef m_solveJobBuffer;
648  agxData::BufferRef m_solveWrapperJobBuffer;
649 
650  agxData::BufferRef m_pgsSolveJobBuffer;
651  agxData::BufferRef m_pgsSolveWrapperJobBuffer;
652 
653  typedef agx::Vector<ref_ptr<Referenced> > DirectSolverDataTable;
654  DirectSolverDataTable m_directSolverDataTable;
655 
656  agxSDK::Simulation* m_simulation;
657 
658  agx::TaskRef m_granularIntegrateVelocitiesKernel;
659  JobPtrVector m_jobStack;
660  agx::Physics::SolveIslandData* m_islands;
661 
662  ref_ptr<Referenced> m_nlSolveDataH5;
663  };
664 
665 
666  //---------------------------------------------------------------
667 
668  class AGXPHYSICS_EXPORT MobilitySolver : public Solver
669  {
670  public:
671  MobilitySolver(Solver* masterSolver, bool isReference);
672 
673  Solver* getMasterSolver();
674  bool isReferenceSolver() const;
675 
676  void addKernelCopy(SolveKernel* kernel);
677  void removeKernelCopy(SolveKernel* kernel);
678 
679  SolveKernel* getMobilityKernel(SolveKernel* kernel);
680 
681  void prepare();
682  void verify();
683  void copyToMaster();
684  void copyFromMaster();
685 
686  agxData::EntityStorage* getRigidBodyStorage();
687 
688  protected:
689  virtual ~MobilitySolver();
690 
691  private:
692  void copy(bool import);
693 
694  void preSolve(Task* task);
695  void postSolve(Task* task);
696  agxData::EntityStorage* setupRigidBodyStorage();
697  agxData::EntityStorage* setupConstraintRowStorage(const Path& storagePath);
698 
699  void setupSynchronizedBuffer(agxData::EntityStorage* masterStorage, agxData::EntityStorage* localStorage, agxData::Attribute* attribute);
700 
701  struct BufferSynchronization
702  {
703  agxData::EntityStorageRef masterStorage;
704  agxData::EntityStorageRef localStorage;
705  agxData::AttributeRef attribute;
706  };
707 
708  private:
709  Solver* m_masterSolver;
710  bool m_isReference;
711  agxData::EntityStorageRef m_rigidBodyStorage;
712  agxData::EntityStorageRef m_contactConstraintRowStorage;
713  agxData::EntityStorageRef m_binaryConstraintRowStorage;
714  agxData::EntityStorageRef m_manyBodyConstraintRowStorage;
715  TaskRef m_preSolveTask;
716  TaskRef m_postSolveTask;
717  Task::ExecutionEvent::CallbackType m_preSolveCallback;
718  Task::ExecutionEvent::CallbackType m_postSolveCallback;
719 
720  typedef HashTable<SolveKernel *, SolveKernel *> KernelTable;
721  KernelTable m_kernelTable;
722 
723  Vector<BufferSynchronization> m_bufferSynchronizations;
724  };
725 
726 
727  //---------------------------------------------------------------
728 
729  AGX_DECLARE_POINTER_TYPES(SolveModel);
730  AGX_DECLARE_VECTOR_TYPES(SolveModel);
731  typedef HashTable<String, SolveModel* > SolveModelTable;
732 
733  class SolveModel : public Object
734  {
735  public:
736  enum SolveType
737  {
738  INVALID_SOLVE_TYPE = -1,
739  ITERATIVE = (1<<0),
740  DIRECT_AND_ITERATIVE = (1<<1),
741  DIRECT = (1<<2),
742  SPLIT = (1<<3)
743  };
744 
745  enum ConstraintType
746  {
747  INVALID_CONSTRAINT_TYPE = -1,
748  CONTACT_CONSTRAINT,
752  };
753 
754  static agx::Model* ClassModel();
755  static SolveModel::SolveType toSolveType( const agx::String& str );
756  static SolveModel::ConstraintType toConstraintType( const agx::String& str );
757  static SolveModel* load(TiXmlElement* eModel, agx::Device* device);
758  void configure(TiXmlElement* eModel);
759 
760  public:
761  SolveModel(const Name& name, SolveType solveType, ConstraintType constraintType);
762 
763  bool isDirect() const;
764  SolveType getSolveType() const;
765  ConstraintType getConstraintType() const;
766  agx::UInt32 getId() const;
767 
768  SolveKernel* getPrepareDirectSolveKernel();
769  SolveKernel* getIterativeSolveKernel();
770  SolveKernel* getInternalZoneBeginKernel();
771  SolveKernel* getInternalZoneEndKernel();
772  SolveKernel* getIntegrateVelocitiesKernel();
773  SolveKernel* getUpdateRhsKernel();
774  SolveKernel* getResidualKernel();
775  SolveKernel* getSynchronizeIterativeKernel();
776  SolveKernel* getSynchronizeDirectKernel();
777  SolveKernel* getStoreContactForcesKernel();
778 
779  void setPrepareDirectSolveKernel(SolveKernel* kernel);
780  void setIterativeSolveKernel(SolveKernel* kernel);
781  void setIntegrateVelocitiesKernel(SolveKernel* kernel);
782  void setUpdateRhsKernel(SolveKernel* kernel);
783  void setResidualKernel(SolveKernel* kernel);
784  void setSynchronizeIterativeKernel(SolveKernel* kernel);
785  void setSynchronizeDirectKernel(SolveKernel* kernel);
786 
787 
788  const SolveKernelRefVector& getKernels() const;
789 
790  void setId(agx::UInt32 id);
791  protected:
792  virtual ~SolveModel();
793 
794  private:
795  UInt32 m_id;
796  SolveType m_solveType;
797  ConstraintType m_constraintType;
798  SolveKernelRef m_prepareDirectSolverKernel;
799  SolveKernelRef m_iterativeSolveKernel;
800  SolveKernelRef m_internalZoneBeginKernel;
801  SolveKernelRef m_internalZoneEndKernel;
802  SolveKernelRef m_integrateVelocitiesKernel;
803  SolveKernelRef m_updateRhsKernel;
804  SolveKernelRef m_residualKernel;
805  SolveKernelRef m_storeContactForcesKernel;
806  SolveKernelRef m_synchronizeIterativeKernel;
807  SolveKernelRef m_synchronizeDirectKernel;
808  SolveKernelRefVector m_kernels;
809  };
810 
811  AGXPHYSICS_EXPORT Physics::SolveGroupPtr getSolveGroup(Physics::SolveIslandPtr island, const String& name);
812 
813  //---------------------------------------------------------------
814 
815  struct AGXPHYSICS_EXPORT SolveContext
816  {
817  typedef agx::Physics::HierarchicalGrid::ContactZoneInstance ContactZoneInstance;
818 
819  SolveContext();
820  SolveContext(
821  agxData::IndexArray interactions_, Physics::SolveIslandPtr island_, Physics::SolveGroupPtr group_,
822  ContactZoneInstance contactZone_ = ContactZoneInstance());
823 
824 
825  agxData::IndexArray interactions;
826  Physics::SolveIslandPtr island;
827  Physics::SolveGroupPtr group;
828  ContactZoneInstance contactZone;
829  };
830 
831  //---------------------------------------------------------------
832 
833  class AGXPHYSICS_EXPORT SolveJob : public Job
834  {
835  public:
836  typedef Callback1<SolveContext> SolveCallback;
837 
838  public:
839  SolveJob();
840  SolveJob(const SolveCallback& callback, SolveContext context, agx::UInt32 cost);
841  virtual ~SolveJob();
842 
843  void init(const SolveCallback& callback, SolveContext context, agx::UInt32 cost);
844 
845  SolveContext& getContext();
846 
847  protected:
848  virtual void implementation() override;
849 
850  private:
851  // void dispatch();
852 
853  protected:
854  SolveCallback m_solveCallback;
855  SolveContext m_context;
856  };
857 
858  //---------------------------------------------------------------
859 
860  template <class T>
861  class SolveJobT : public SolveJob
862  {
863  public:
864  SolveJobT();
865  SolveJobT(SolveContext context, agx::UInt32 cost);
866  virtual ~SolveJobT();
867 
868  protected:
869  virtual void implementation() override;
870 
871  };
872 
873  //---------------------------------------------------------------
874 
875  class AGXPHYSICS_EXPORT SolveKernel : public CpuKernel
876  {
877  public:
878  typedef SolveJob::SolveCallback SolveDispatch;
879 
880  public:
881  SolveKernel(const Name& name, SolveDispatch dispatch);
882 
883  const SolveDispatch& getDispatch() const;
884 
885  virtual void constructJob(SolveJob* job) = 0;
886  protected:
887  virtual ~SolveKernel();
888 
889  private:
890  SolveDispatch m_dispatch;
891  };
892 
894 
895  //---------------------------------------------------------------
896 
897  /* Implementation */
898  AGX_FORCE_INLINE UInt Solver::getNumImpactIterations() const { return m_numImpactIterations->get(); }
899  AGX_FORCE_INLINE UInt Solver::getNumRestingIterations() const { return m_numRestingIterations->get(); }
900  AGX_FORCE_INLINE UInt Solver::getNumPPGSRestingIterations() const { return m_numPPGSRestingIterations->get(); }
901  AGX_FORCE_INLINE UInt Solver::getNumDryFrictionIterations() const { return m_numDryFrictionIterations->get(); }
902  AGX_FORCE_INLINE bool Solver::isForceIterative() const { return m_forceIterative->get(); }
903  AGX_FORCE_INLINE const SolveKernelRefVector& Solver::getKernels() const { return m_kernels; }
904 
905  AGX_FORCE_INLINE SolveKernel* Solver::getStoreContactForcesKernel() { return m_storeContactForcesKernel; }
906  AGX_FORCE_INLINE SolveKernel* Solver::getCommitDirectVelocitiesKernel() { return m_commitDirectVelocitiesKernel; }
907 
908  AGX_FORCE_INLINE SolveKernel* Solver::getDirectRhsKernel() { return m_directRhsKernel; }
909 
910 
911  AGX_FORCE_INLINE SolveKernel* Solver::getPrepareDirectSolverKernel() { return m_prepareDirectSolverKernel; }
912  AGX_FORCE_INLINE SolveKernel* Solver::getDirectSolverKernel() { return m_directSolverKernel; }
913  AGX_FORCE_INLINE SolveKernel* Solver::getSynchronizeIterativeSolverKernel() { return m_synchronizeIterativeSolverKernel; }
914  AGX_FORCE_INLINE SolveKernel* Solver::getUpdateBoundsSolverKernel() { return m_updateDirectBounds; }
915  AGX_FORCE_INLINE SolveKernel* Solver::getSynchronizeDirectSolverKernel() { return m_synchronizeDirectSolverKernel; }
916  AGX_FORCE_INLINE SolveKernel* Solver::getUpdateIterationCountKernel() { return m_iterationCountKernel; }
917 
918  AGX_FORCE_INLINE DirectSolverData* Solver::getDirectSolverData(Physics::SolveIslandPtr island)
919  {
920  return (DirectSolverData *)m_directSolverDataTable[island.getId()].get();
921  }
922 
923 
924  //-----------------------------------------------------------------------------------------------------
925 
926  AGX_FORCE_INLINE bool SolveModel::isDirect() const { return m_solveType > ITERATIVE; }
927  AGX_FORCE_INLINE SolveModel::SolveType SolveModel::getSolveType() const { return m_solveType; }
928  AGX_FORCE_INLINE SolveModel::ConstraintType SolveModel::getConstraintType() const { return m_constraintType; }
929  AGX_FORCE_INLINE agx::UInt32 SolveModel::getId() const { return m_id; }
930  AGX_FORCE_INLINE SolveKernel* SolveModel::getPrepareDirectSolveKernel() { return m_prepareDirectSolverKernel; }
931  AGX_FORCE_INLINE SolveKernel* SolveModel::getIterativeSolveKernel() { return m_iterativeSolveKernel; }
932  AGX_FORCE_INLINE SolveKernel* SolveModel::getInternalZoneBeginKernel() { return m_internalZoneBeginKernel; }
933  AGX_FORCE_INLINE SolveKernel* SolveModel::getInternalZoneEndKernel() { return m_internalZoneEndKernel; }
934  AGX_FORCE_INLINE SolveKernel* SolveModel::getIntegrateVelocitiesKernel() { return m_integrateVelocitiesKernel; }
935  AGX_FORCE_INLINE SolveKernel* SolveModel::getUpdateRhsKernel() { return m_updateRhsKernel; }
936  AGX_FORCE_INLINE SolveKernel* SolveModel::getResidualKernel() { return m_residualKernel; }
937  AGX_FORCE_INLINE SolveKernel* SolveModel::getStoreContactForcesKernel() { return m_storeContactForcesKernel; }
938  AGX_FORCE_INLINE SolveKernel* SolveModel::getSynchronizeIterativeKernel() { return m_synchronizeIterativeKernel; }
939  AGX_FORCE_INLINE SolveKernel* SolveModel::getSynchronizeDirectKernel() { return m_synchronizeDirectKernel; }
940 
941  AGX_FORCE_INLINE const SolveKernelRefVector& SolveModel::getKernels() const { return m_kernels; }
942 
943  //-----------------------------------------------------------------------------------------------------
944 
945  AGX_FORCE_INLINE SolveContext::SolveContext() {}
946  AGX_FORCE_INLINE SolveContext::SolveContext(
947  agxData::IndexArray interactions_,
948  Physics::SolveIslandPtr island_,
949  Physics::SolveGroupPtr group_,
950  ContactZoneInstance contactZone_)
951  : interactions(interactions_)
952  , island(island_)
953  , group(group_)
954  , contactZone(contactZone_)
955  {}
956 
957  //-----------------------------------------------------------------------------------------------------
958 
959  AGX_FORCE_INLINE SolveJob::SolveJob() // : Job(Callback(&SolveJob::dispatch, this))
960  {
961  }
962 
963  AGX_FORCE_INLINE SolveJob::SolveJob(const SolveCallback& callback, SolveContext context, agx::UInt32 cost) // : Job(Callback(&SolveJob::dispatch, this))
964  {
965  this->init(callback, context, cost);
966  }
967 
968  AGX_FORCE_INLINE void SolveJob::init(const SolveCallback& callback, SolveContext context, agx::UInt32 cost)
969  {
970  m_context = context;
971  m_solveCallback = callback;
972 
973  // Job::init(Callback(&SolveJob::dispatch, this), cost);
974  Job::init(Job::Callback(), cost);
975  }
976 
977 
978  AGX_FORCE_INLINE SolveContext& SolveJob::getContext() { return m_context; }
979 
980  //-----------------------------------------------------------------------------------------------------
981 
982  template <class T>
983  SolveJobT<T>::SolveJobT() : SolveJob()
984  {
985  }
986 
987  template <class T>
988  SolveJobT<T>::SolveJobT(SolveContext context, agx::UInt32 cost) : SolveJob(SolveCallback(), context, cost)
989  {
990  }
991 
992  template <class T>
993  SolveJobT<T>::~SolveJobT()
994  {
995  }
996 
997  template <class T>
998  void SolveJobT<T>::implementation()
999  {
1000  agxAssert(dynamic_cast<T*>(m_task));
1001  static_cast<T*>(m_task)->dispatch(m_context);
1002  }
1003 
1004 
1005  AGX_FORCE_INLINE const SolveKernel::SolveDispatch& SolveKernel::getDispatch() const { return m_dispatch; }
1006 }
1007 
1008 AGX_TYPE_BINDING(agx::SolveJob, "SolveJob")
1009 
1010 #ifdef _MSC_VER
1011 # pragma warning(pop)
1012 #endif
1013 
1014 #endif /* AGX_SOLVER_H */
Pointer to a entity instance of type Physics.HierarchicalGrid.ContactZone.
agx::ref_ptr< Task > TaskRef
Definition: Task.h:42
void AGXPHYSICS_EXPORT init()
Initialize AGX Dynamics API including thread resources and must be executed before using the AGX API...
bool Bool
Definition: Integer.h:48
Data storage for a collection of entity instances of a specified EntityModel.
Definition: EntityStorage.h:72
A model is an abstract representation of the class of an agx::Object.
Definition: Model.h:40
#define AGX_TYPE_BINDING(_Type, _Name)
Definition: Type.h:179
#define AGXPHYSICS_EXPORT
AgXString< std::string > String
Definition: String.h:427
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
#define AGX_FORCE_INLINE
Definition: Object.h:59
Pointer to a entity instance of type Physics.SolveIsland.
VectorPOD< class Job * > JobPtrVector
Definition: Job.h:51
Templated vector class.
Definition: Vector.h:52
uint32_t UInt
Definition: Integer.h:34
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
An abstract attribute description, part of an Entity.
Definition: Attribute.h:57
Abstract representation of a data buffer.
Definition: Buffer.h:55
#define agxAssert(expr)
Definition: debug.h:143
#define CALLABLE
Definition: Object.h:73
#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
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Definition: Serializable.h:44
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:126
double Real
Definition: Real.h:42
#define AGX_DECLARE_VECTOR_TYPES(type)
Definition: Vector.h:34
void init(const Callback &callback=Callback(), agx::UInt32 costEstimate=100)
Initialize the job.
Definition: Job.h:558
An agx::Device is an abstract representation of a device on which data can be stored and processed...
Definition: Device.h:57
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:30
uint32_t UInt32
Definition: Integer.h:40
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: Object.h:98
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: Object.h:97