AGX Dynamics  2.35.0.1
BodyContactJacobian.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, is 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_BODYCONTACTJACOBIAN_H
18 #define AGX_BODYCONTACTJACOBIAN_H
19 
20 #include <agx/Jacobian.h>
21 #include <agxSIMD/Jacobian.h>
22 
23 
24 namespace agx
25 {
26  template <typename JacobianElementT> class BodyContactJacobianT;
27  template <typename JacobianElementT> class RollingResistanceJacobianT;
28  template <typename JacobianElementT> class TangentJacobianT;
29 
33 
37 
41 
42 }
43 
45 namespace agxSIMD
46 {
50 
54 
58  #if 0
62 
66 
70 
71  // typedef agx::Jacobian6DOFElement64 Jacobian6DOFElement64;
72  // typedef agx::Jacobian6DOFElement32 Jacobian6DOFElement32;
73  // typedef agx::Jacobian6DOFElement Jacobian6DOFElement;
74  #endif
75 }
77 
78 namespace agx
79 {
80 
81  // Templates for binding non-SIMD arrays as SIMD data
82  template <typename JacobianElementT> struct ComplementaryElementT {};
83 
88 
90 
91  template <typename T>
93  {
94  public:
95  typedef T JacobianElementT;
100 
101  public:
102 
105 
106  JacobianAccessorT(const JacobianElementArrayT& jacobianElements, size_t offset);
107  JacobianAccessorT(const ComplementaryElementArrayT& jacobianElements, size_t offset);
108 
109 #ifndef AGX_DEBUG
110  JacobianAccessorT(const JacobianElementT *jacobianElements, size_t offset);
111 #endif
112 
113  void setup(const JacobianElementArrayT& jacobianElements, size_t offset) const;
114  void setup(const ComplementaryElementArrayT& jacobianElements, size_t offset) const;
115 
116  void setup(JacobianElementArrayT& jacobianElements, size_t offset);
117  void setup(ComplementaryElementArrayT& jacobianElements, size_t offset);
118 
119 
120  JacobianElementT& get(size_t index);
121  const JacobianElementT& get(size_t index) const;
122 
123  template <typename AccessorT>
124  AccessorT get(size_t index);
125 
126  template <typename AccessorT>
127  const AccessorT get(size_t index) const;
128 
129  private:
130  JacobianAccessorT& operator= (const JacobianAccessorT& other);
131 
132  private:
133 #ifdef AGX_DEBUG
134  JacobianElementArrayT m_jacobianElements;
135 #else
136  JacobianElementT *m_jacobianElements;
137 #endif
138  };
139 
140 
142 
143  template <typename JacobianElementT>
144  class TangentJacobianT : public JacobianAccessorT<JacobianElementT>
145  {
146  public:
148  typedef typename BaseT::JacobianElementArrayT JacobianElementArrayT;
149  typedef typename BaseT::ComplementaryElementArrayT ComplementaryElementArrayT;
150 
151  public:
153  TangentJacobianT(const JacobianElementArrayT& jacobianElements, size_t offset);
154  TangentJacobianT(const ComplementaryElementArrayT& jacobianElements, size_t offset);
155 
156  JacobianElementT& u();
157  const JacobianElementT& u() const;
158 
159  JacobianElementT& v();
160  const JacobianElementT& v() const;
161 
162 #ifndef AGX_DEBUG
163  TangentJacobianT(const JacobianElementT *jacobianElements, size_t offset);
164 #endif
165  };
166 
168 
169  template <typename JacobianElementT>
170  class RollingResistanceJacobianT : public JacobianAccessorT<JacobianElementT>
171  {
172  public:
174  typedef typename BaseT::JacobianElementArrayT JacobianElementArrayT;
175  typedef typename BaseT::ComplementaryElementArrayT ComplementaryElementArrayT;
177 
178  public:
180  RollingResistanceJacobianT(const JacobianElementArrayT& jacobianElements, size_t offset);
181  RollingResistanceJacobianT(const ComplementaryElementArrayT& jacobianElements, size_t offset);
182 
183  TangentJacobian tangent();
184  const TangentJacobian tangent() const;
185 
186  JacobianElementT& normal();
187  const JacobianElementT& normal() const;
188 
189 #ifndef AGX_DEBUG
190  RollingResistanceJacobianT(const JacobianElementT *jacobianElements, size_t offset);
191 #endif
192  };
193 
195 
196  template <typename JacobianElementT>
197  class BodyContactJacobianT : public JacobianAccessorT<JacobianElementT>
198  {
199  public:
201  typedef typename BaseT::JacobianElementArrayT JacobianElementArrayT;
202  typedef typename BaseT::ComplementaryElementArrayT ComplementaryElementArrayT;
205 
206  static const bool IsLocal = false;
207 
208  public:
210  BodyContactJacobianT(const JacobianElementArrayT& jacobianElements, size_t offset);
211  BodyContactJacobianT(const ComplementaryElementArrayT& jacobianElements, size_t offset);
212 
213  JacobianElementT& normal();
214  const JacobianElementT& normal() const;
215 
216  TangentJacobian tangent();
217  const TangentJacobian tangent() const;
218 
219  RollingResistanceJacobian rollingResistance();
220  const RollingResistanceJacobian rollingResistance() const;
221 
222 #ifndef AGX_DEBUG
223  BodyContactJacobianT(const JacobianElementT *jacobianElements, size_t offset);
224 #endif
225  };
226 
227 
228 
229 
230 
231  /* Implementation */
232 
234 
235  template <typename JacobianElementT>
237  : m_jacobianElements(nullptr)
238  {
239  }
240 
241  template <typename JacobianElementT>
243 #ifdef AGX_DEBUG
244  m_jacobianElements(reinterpret_cast<const JacobianElementArrayT&>(jacobianElements), IndexRange(offset, jacobianElements.size()))
245 #else
246  m_jacobianElements((JacobianElementT *)jacobianElements.ptr() + offset)
247 #endif
248  {
249  }
250 
251  template <typename JacobianElementT>
253 #ifdef AGX_DEBUG
254  m_jacobianElements(jacobianElements, IndexRange(offset, jacobianElements.size()))
255 #else
256  m_jacobianElements((JacobianElementT *)jacobianElements.ptr() + offset)
257 #endif
258  {
259  }
260 
261 
262  template <typename JacobianElementT>
264  {
265 #ifdef AGX_DEBUG
266  m_jacobianElements = JacobianElementArrayT(reinterpret_cast<JacobianElementArrayT&>(jacobianElements), IndexRange(offset, jacobianElements.size()));
267 #else
268  m_jacobianElements = (JacobianElementT *)jacobianElements.ptr() + offset;
269 #endif
270  }
271 
272  template <typename JacobianElementT>
274  {
275 #ifdef AGX_DEBUG
276  m_jacobianElements = JacobianElementArrayT(jacobianElements, IndexRange(offset, jacobianElements.size()));
277 #else
278  m_jacobianElements = (JacobianElementT *)jacobianElements.ptr() + offset;
279 #endif
280  }
281 
282  template <typename JacobianElementT>
284  {
285  const_cast<JacobianAccessorT *>(this)->setup(const_cast<ComplementaryElementArrayT&>(jacobianElements), offset);
286  }
287 
288  template <typename JacobianElementT>
289  AGX_FORCE_INLINE void JacobianAccessorT<JacobianElementT>::setup(const JacobianElementArrayT& jacobianElements, size_t offset) const
290  {
291  const_cast<JacobianAccessorT *>(this)->setup(const_cast<JacobianElementArrayT&>(jacobianElements), offset);
292  }
293 
294 #ifndef AGX_DEBUG
295  template <typename JacobianElementT>
296  AGX_FORCE_INLINE JacobianAccessorT<JacobianElementT>::JacobianAccessorT(const JacobianElementT *jacobianElements, size_t offset) : m_jacobianElements((JacobianElementT *)jacobianElements + offset)
297  {
298  }
299 #endif
300 
301  template <typename JacobianElementT>
302  AGX_FORCE_INLINE JacobianAccessorT<JacobianElementT>::JacobianAccessorT(const JacobianAccessorT& other) : m_jacobianElements(other.m_jacobianElements)
303  {
304  }
305 
306  template <typename JacobianElementT>
308  {
309  m_jacobianElements = other.m_jacobianElements;
310  return *this;
311  }
312 
313  template <typename JacobianElementT>
315  {
316  return m_jacobianElements[index];
317  }
318 
319  template <typename JacobianElementT>
321  {
322  return m_jacobianElements[index];
323  }
324 
325 
326  template <typename JacobianElementT> template <typename AccessorT>
328  {
329  return AccessorT(m_jacobianElements, index);
330  }
331 
332  template <typename JacobianElementT> template <typename AccessorT>
333  AGX_FORCE_INLINE const AccessorT JacobianAccessorT<JacobianElementT>::get(size_t index) const
334  {
335  return AccessorT(m_jacobianElements, index);
336  }
337 
339 
340  template <typename JacobianElementT>
342  {
343  }
344 
345 
346  template <typename JacobianElementT>
347  AGX_FORCE_INLINE TangentJacobianT<JacobianElementT>::TangentJacobianT(const ComplementaryElementArrayT& jacobianElements, size_t offset) : BaseT(jacobianElements, offset)
348  {
349  }
350 
351  template <typename JacobianElementT>
352  AGX_FORCE_INLINE TangentJacobianT<JacobianElementT>::TangentJacobianT(const JacobianElementArrayT& jacobianElements, size_t offset) : BaseT(jacobianElements, offset)
353  {
354  }
355 
356 #ifndef AGX_DEBUG
357  template <typename JacobianElementT>
358  AGX_FORCE_INLINE TangentJacobianT<JacobianElementT>::TangentJacobianT(const JacobianElementT *jacobianElements, size_t offset) : BaseT(jacobianElements, offset)
359  {
360  }
361 #endif
362 
363  template <typename JacobianElementT>
365  {
366  return this->get(0);
367  }
368 
369  template <typename JacobianElementT>
371  {
372  return this->get(0);
373  }
374 
375 
376  template <typename JacobianElementT>
378  {
379  return this->get(1);
380  }
381 
382  template <typename JacobianElementT>
384  {
385  return this->get(1);
386  }
387 
389 
390  template <typename JacobianElementT>
392  {
393  }
394 
395  template <typename JacobianElementT>
397  {
398  }
399 
400 
401  template <typename JacobianElementT>
403  {
404  }
405 
406 #ifndef AGX_DEBUG
407  template <typename JacobianElementT>
408  AGX_FORCE_INLINE RollingResistanceJacobianT<JacobianElementT>::RollingResistanceJacobianT(const JacobianElementT *jacobianElements, size_t offset) : BaseT(jacobianElements, offset)
409  {
410  }
411 #endif
412 
413  template <typename JacobianElementT>
415  {
416  return this->template get<TangentJacobian>(0);
417  }
418 
419  template <typename JacobianElementT>
421  {
422  return this->template get<TangentJacobian>(0);
423  }
424 
425  template <typename JacobianElementT>
427  {
428  return this->get(2);
429  }
430 
431  template <typename JacobianElementT>
433  {
434  return this->get(2);
435  }
436 
438 
439  template <typename JacobianElementT>
441  {
442  }
443 
444 
445  template <typename JacobianElementT>
447  const ComplementaryElementArrayT& jacobianElements, size_t offset) : BaseT(jacobianElements, offset)
448  {
449  }
450 
451  template <typename JacobianElementT>
453  const JacobianElementArrayT& jacobianElements, size_t offset) : BaseT(jacobianElements, offset)
454  {
455  }
456 
457 #ifndef AGX_DEBUG
458  template <typename JacobianElementT>
460  const JacobianElementT *jacobianElements, size_t offset) : BaseT(jacobianElements, offset)
461  {
462  }
463 #endif
464 
465  template <typename JacobianElementT>
467  {
468  return this->get(0);
469  }
470 
471  template <typename JacobianElementT>
473  {
474  return this->get(0);
475  }
476 
477  template <typename JacobianElementT>
479  {
480  return this->template get<TangentJacobian>(1);
481  }
482 
483  template <typename JacobianElementT>
485  {
486  return this->template get<TangentJacobian>(1);
487  }
488 
489  template <typename JacobianElementT>
491  {
492  return this->template get<RollingResistanceJacobian>(3);
493  }
494 
495  template <typename JacobianElementT>
497  {
498  return this->template get<RollingResistanceJacobian>(3);
499  }
500 
502 
503 }
504 
505 
506 #endif /* AGX_BODYCONTACTJACOBIAN_H */
size_t size() const
Definition: Buffer.h:708
T * ptr()
Definition: Buffer.h:900
JacobianElementT & normal()
BaseT::TangentJacobian TangentJacobian
JacobianAccessorT< JacobianElementT > BaseT
BaseT::JacobianElementArrayT JacobianElementArrayT
BaseT::ComplementaryElementArrayT ComplementaryElementArrayT
BaseT::RollingResistanceJacobian RollingResistanceJacobian
RollingResistanceJacobian rollingResistance()
JacobianAccessorT(const JacobianElementArrayT &jacobianElements, size_t offset)
void setup(const ComplementaryElementArrayT &jacobianElements, size_t offset) const
JacobianElementT & get(size_t index)
JacobianAccessorT(const ComplementaryElementArrayT &jacobianElements, size_t offset)
RollingResistanceJacobianT< JacobianElementT > RollingResistanceJacobian
agxData::Array< typename ComplementaryElementT< JacobianElementT >::Type > ComplementaryElementArrayT
void setup(const JacobianElementArrayT &jacobianElements, size_t offset) const
TangentJacobianT< JacobianElementT > TangentJacobian
const JacobianElementT & get(size_t index) const
agxData::Array< JacobianElementT > JacobianElementArrayT
AccessorT get(size_t index)
void setup(JacobianElementArrayT &jacobianElements, size_t offset)
JacobianAccessorT(const JacobianAccessorT &other)
const AccessorT get(size_t index) const
void setup(ComplementaryElementArrayT &jacobianElements, size_t offset)
BaseT::TangentJacobian TangentJacobian
BaseT::ComplementaryElementArrayT ComplementaryElementArrayT
BaseT::JacobianElementArrayT JacobianElementArrayT
JacobianAccessorT< JacobianElementT > BaseT
JacobianAccessorT< JacobianElementT > BaseT
JacobianElementT & u()
JacobianElementT & v()
BaseT::ComplementaryElementArrayT ComplementaryElementArrayT
BaseT::JacobianElementArrayT JacobianElementArrayT
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:97
#define AGX_DEBUG
Definition: macros.h:26
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:96
#define AGX_FORCE_INLINE
Definition: macros.h:58
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Jacobian6DOFElementT< Vec3f > Jacobian6DOFElement32
Definition: agx/Jacobian.h:272
RollingResistanceJacobianT< Jacobian6DOFElement64 > RollingResistanceJacobian64
RollingResistanceJacobianT< Jacobian6DOFElement > RollingResistanceJacobian
RollingResistanceJacobianT< Jacobian6DOFElement32 > RollingResistanceJacobian32
IndexRangeT< agx::UInt > IndexRange
Definition: IndexRange.h:140
TangentJacobianT< Jacobian6DOFElement32 > TangentJacobian32
BodyContactJacobianT< Jacobian6DOFElement64 > BodyContactJacobian64
TangentJacobianT< Jacobian6DOFElement > TangentJacobian
BodyContactJacobianT< Jacobian6DOFElement32 > BodyContactJacobian32
Jacobian6DOFElementT< Vec3d > Jacobian6DOFElement64
Definition: agx/Jacobian.h:271
TangentJacobianT< Jacobian6DOFElement64 > TangentJacobian64
BodyContactJacobianT< Jacobian6DOFElement > BodyContactJacobian