AGXDynamics  2.35.0.3
WindAndWaterAlgorithms.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2022. 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 AGXMODEL_WINDANDWATERALGORITHMS_H
18 #define AGXMODEL_WINDANDWATERALGORITHMS_H
19 
21 
22 namespace agxModel {
23  template< typename T >
24  void triangleIterator( const T* obj, WindAndWaterController::ObjectData& objectData, const GlobalTriangleData::Container& trianglePool )
25  {
26  if( objectData.getRigidBody() == nullptr )
27  return;
28 
29  auto triangleUpdate = [ & ] ( const agx::RangeJob& job )
30  {
31  agx::Vec3 force;
32  agx::Vec3 torque;
33  for( size_t k = job.range().begin(); k < job.range().end(); ++k ) {
34  size_t i = k + objectData.getStartIndexT();
35  const GlobalTriangleData& tData = trianglePool[ i ];
36  if( tData.isClipped() )
37  for( agx::UInt j = 0; j < tData.clipped.size(); ++j )
38  obj->calculate( tData.clipped[ j ], objectData, force, torque );
39  else
40  obj->calculate( tData, objectData, force, torque );
41  }
42  objectData.lock();
43  objectData.force() += force;
44  objectData.torque() += torque;
45  objectData.unLock();
46  };
47 
48  auto sizeCallback = [ & ] ()
49  {
50  return objectData.getNumTriangles();
51  };
52 
53  if( objectData.getNumTriangles() > 500 ) {
54  agx::LambdaKernelRef computeKernel = new agx::LambdaKernel( "ComputeKernel", triangleUpdate, sizeCallback );
55  computeKernel->execute();
56  } else {
57  agx::RangeJob range;
58  range.init( agx::IndexRange( 0, objectData.getNumTriangles() ) );
59  triangleUpdate( range );
60  }
61  }
62 
63  class AGXMODEL_EXPORT BuoyancyAlgorithm : public agxModel::WindAndWaterController::Algorithm
64  {
65  public:
67 
68  virtual void updateInteraction( agxModel::WindAndWaterController::ObjectData& objectData, const GlobalTriangleData::Container& container ) override { triangleIterator( this, objectData, container ); }
69 
70  void calculate( const agxModel::TriangleData& tData, agxModel::WindAndWaterController::ObjectData& objectData, agx::Vec3& force, agx::Vec3& torque ) const;
71 
72  void pre( agxModel::WindAndWaterController* ) override;
73 
74  protected:
75  virtual ~BuoyancyAlgorithm();
76 
78 
79  // Used for scaling buoyancy forces for primitive shapes.
80  class VolumeScalingDataContainer {
81  public:
82  agx::Real getVolumeScaling( const agxCollide::Shape* shape,
84 
85  void garbageCollect();
86 
87  private:
88  struct Data
89  {
90  Data( agx::Real volumeScaling, agx::UInt32 modifiedCount,
92  : volumeScaling( volumeScaling ), modifiedCount( modifiedCount ), tessellation( tessellation ), shape( shape )
93  {
94  }
95 
96  agx::Real volumeScaling;
97  agx::UInt32 modifiedCount;
100  };
101 
103  Container m_data;
104  std::mutex m_mutex;
105  };
106 
108 
109  mutable VolumeScalingDataContainer m_volumeScaling;
110  };
111 
113  {
114  public:
116 
117  virtual void updateInteraction( agxModel::WindAndWaterController::ObjectData& objectData, const GlobalTriangleData::Container& container ) override { triangleIterator( this, objectData, container ); }
118 
119  void calculate( const agxModel::TriangleData& tData, agxModel::WindAndWaterController::ObjectData& objectData, agx::Vec3& force, agx::Vec3& torque ) const;
120 
121  protected:
122  virtual ~PressureDragForceAlgorithm();
123  };
124 
125  class AGXMODEL_EXPORT LiftForceAlgorithm : public agxModel::WindAndWaterController::Algorithm
126  {
127  public:
129 
130  virtual void updateInteraction( agxModel::WindAndWaterController::ObjectData& objectData, const GlobalTriangleData::Container& container ) override { triangleIterator( this, objectData, container ); }
131 
132  void calculate( const agxModel::TriangleData& tData, agxModel::WindAndWaterController::ObjectData& objectData, agx::Vec3& force, agx::Vec3& torque ) const;
133 
134  protected:
135  virtual ~LiftForceAlgorithm();
136  };
137 
138  class AGXMODEL_EXPORT ViscousDragForceAlgorithm : public agxModel::WindAndWaterController::Algorithm
139  {
140  public:
142 
143  virtual void updateInteraction( agxModel::WindAndWaterController::ObjectData& objectData, const GlobalTriangleData::Container& container ) override { triangleIterator( this, objectData, container ); }
144 
145  void calculate( const agxModel::TriangleData& tData, agxModel::WindAndWaterController::ObjectData& objectData, agx::Vec3& force, agx::Vec3& torque ) const;
146 
147  protected:
148  virtual ~ViscousDragForceAlgorithm();
149  };
150 
151  class AGXMODEL_EXPORT AddedMassAlgorithm : public agxModel::WindAndWaterController::Algorithm
152  {
153  public:
155 
156  virtual void updateInteraction( agxModel::WindAndWaterController::ObjectData& objectData, const GlobalTriangleData::Container& container ) override;
157 
158  protected:
159  virtual ~AddedMassAlgorithm();
160  };
161 }
162 
163 #endif // AGXMODEL_WINDANDWATERALGORITHMS_H
agxModel::BuoyancyAlgorithm::updateInteraction
virtual void updateInteraction(agxModel::WindAndWaterController::ObjectData &objectData, const GlobalTriangleData::Container &container) override
Definition: WindAndWaterAlgorithms.h:68
agxModel::WindAndWaterController::ObjectData
Static data for a shape.
Definition: WindAndWaterController.h:189
agxModel::WindAndWaterController::ObjectData::getStartIndexT
agx::UInt getStartIndexT() const
agxModel::ViscousDragForceAlgorithm
Definition: WindAndWaterAlgorithms.h:138
agx::Task::execute
void execute()
Execute the task.
agx::Real
double Real
Definition: Real.h:42
agxModel::WindAndWaterController::ObjectData::getRigidBody
const agx::RigidBody * getRigidBody() const
agxModel
Contain classes for higher level modeling primitives, such as Tree, Terrain etc.
Definition: FlowUnit.h:36
agx::Vector< GlobalTriangleData >
agx::Container::size
size_t size() const
Definition: Container.h:134
DOXYGEN_END_INTERNAL_BLOCK
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:97
agx::LambdaKernel
Definition: Kernel.h:173
agxModel::ViscousDragForceAlgorithm::updateInteraction
virtual void updateInteraction(agxModel::WindAndWaterController::ObjectData &objectData, const GlobalTriangleData::Container &container) override
Definition: WindAndWaterAlgorithms.h:143
DOXYGEN_START_INTERNAL_BLOCK
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:96
agxModel::AddedMassAlgorithm
Definition: WindAndWaterAlgorithms.h:151
agxModel::GlobalTriangleData
Global triangle data (mapped with agxCollide::Mesh object) holding vertex indices.
Definition: WindAndWaterUtils.h:101
agx::observer_ptr< const Shape >
agxModel::LiftForceAlgorithm
Definition: WindAndWaterAlgorithms.h:125
agx::IndexRangeT< agx::UInt >
agxModel::WindAndWaterController::ObjectData::unLock
void unLock() const
Perform a mutex unlock for this ObjectData.
Definition: WindAndWaterController.h:335
agx::ref_ptr< LambdaKernel >
agxModel::WindAndWaterController
Controller that collects relevant data and executes algorithms (probably mostly aero- and hydrodynami...
Definition: WindAndWaterController.h:45
agxCollide::Shape
Base class for a shape.
Definition: Shape.h:53
agx::RangeJob::init
void init(const RangeCallback &callback, const IndexRange &range, agx::UInt32 costPerElement=1)
Definition: Job.h:635
agxModel::WindAndWaterController::ObjectData::force
agx::Vec3 & force()
Access force vector (in world coordinate system).
agx::RangeJob
A range job executes a kernel implementation on a subset of the data.
Definition: Job.h:283
agxModel::WindAndWaterController::ObjectData::getNumTriangles
agx::UInt getNumTriangles() const
agxModel::BuoyancyAlgorithm
Definition: WindAndWaterAlgorithms.h:63
agxModel::WindAndWaterParameters::ShapeTessellation
ShapeTessellation
Tessellation levels of native, non-mesh shapes, e.g, sphere, capsule and cylinder.
Definition: WindAndWaterParameters.h:35
WindAndWaterController.h
agx::UInt
uint32_t UInt
Definition: Integer.h:34
agxModel::TriangleData::isClipped
agx::Bool isClipped() const
Definition: WindAndWaterUtils.h:199
AGXMODEL_EXPORT
#define AGXMODEL_EXPORT
Definition: agxModel/export.h:42
agxModel::PressureDragForceAlgorithm
Definition: WindAndWaterAlgorithms.h:112
agxModel::triangleIterator
void triangleIterator(const T *obj, WindAndWaterController::ObjectData &objectData, const GlobalTriangleData::Container &trianglePool)
Definition: WindAndWaterAlgorithms.h:24
agx::Vec3T< Real >
agxModel::WindAndWaterController::ObjectData::lock
void lock() const
Perform a mutex lock for this ObjectData.
Definition: WindAndWaterController.h:330
agx::UInt32
uint32_t UInt32
Definition: Integer.h:40
agxModel::PressureDragForceAlgorithm::updateInteraction
virtual void updateInteraction(agxModel::WindAndWaterController::ObjectData &objectData, const GlobalTriangleData::Container &container) override
Definition: WindAndWaterAlgorithms.h:117
agxModel::TriangleData
Triangle data for a normal or a clipped triangle.
Definition: WindAndWaterUtils.h:54
agx::HashVector
This class is a combined container which has the find complexity of a HashTable, deterministic iterat...
Definition: HashVector.h:40
agxModel::GlobalTriangleData::clipped
agxModel::TriangleData::Container clipped
Container with clipped triangles if this global triangle has been clipped.
Definition: WindAndWaterUtils.h:106
agxModel::LiftForceAlgorithm::updateInteraction
virtual void updateInteraction(agxModel::WindAndWaterController::ObjectData &objectData, const GlobalTriangleData::Container &container) override
Definition: WindAndWaterAlgorithms.h:130
agxModel::WindAndWaterController::ObjectData::torque
agx::Vec3 & torque()
Access torque vector (in world coordinate system).