AGX Dynamics  2.38.0.2
Connector.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 #pragma once
18 
19 #include <agxModel/export.h>
20 
22 #include <agxStream/Serializable.h>
24 #include <agx/List.h>
25 #include <agx/Vector.h>
26 #include <agx/SetVector.h>
27 #include <agxUtil/agxUtil.h>
29 #include <agxPowerLine/Sides.h>
30 #include <agxPowerLine/SubGraph.h>
31 #include <agx/LookupTables.h>
32 
33 namespace agxPowerLine
34 {
35  class Unit;
36  class PowerLine;
37  class PhysicalDimensionMultiBodyConstraintImplementation;
39 
43 
44  // Local typdef to avoid include loop.
47 
53  {
54  public:
55 
59  Connector();
60 
61  virtual void initConstraint();
62 
63  virtual bool addNotification(agxSDK::Simulation* simulation) override;
64 
68  virtual bool removeNotification(agxUtil::ConstraintHolder* holder, agxSDK::Simulation* simulation) override;
69 
73  virtual bool connect(agxPowerLine::Unit* unit);
74 
75  virtual bool connect(
76  agxPowerLine::Side mySide,
77  agxPowerLine::Side unitSide,
78  agxPowerLine::Unit* unit);
79 
86  virtual bool disconnect(agxPowerLine::Unit* unit);
87 
88  virtual bool disconnect();
89 
90 
91  virtual agxPowerLine::Side getSide(const agxPowerLine::Unit* unit) const;
92 
93 
94  agx::Real getPowerOut() const;
95 
96  agx::Real getPowerIn() const;
97 
101  agx::Real calculateEfficiency() const;
102 
106  virtual agx::Real calculateViolation( ) const;
107 
108  bool compareWithInputTypes( PhysicalDimensionRefVector& dimensions ) const;
109 
110  bool compareWithOutputTypes( PhysicalDimensionRefVector& dimensions ) const;
111 
113  const DimensionTypeVector& getInputTypes() const;
114  const DimensionTypeVector& getOutputTypes() const;
116 
117  // Get a hash vector with pointers to all units connected to this connector.
119  bool getInputUnits(UnitPtrSetVector& units, const bool startFromCleanUnitSet = true);
120  bool getOutputUnits(UnitPtrSetVector& units, const bool startFromCleanUnitSet = true);
121  bool getUnits(UnitPtrSetVector& units, agxPowerLine::Side side, const bool startFromCleanUnitSet = true);
122  bool getUnits(UnitPtrSetVector& units, const bool startFromCleanUnitSet = true);
123 
124 
125  // Get a hash vector with pointers to all units connected to this connector.
126  bool getInputUnits(UnitConstPtrSetVector& units, const bool startFromCleanUnitSet = true) const;
127  bool getOutputUnits(UnitConstPtrSetVector& units, const bool startFromCleanUnitSet = true) const;
128  bool getUnits(UnitConstPtrSetVector& units, agxPowerLine::Side side, const bool startFromCleanUnitSet = true) const;
129  bool getUnits(UnitConstPtrSetVector& units, const bool startFromCleanUnitSet = true) const;
130 
131  static PhysicalDimension* getDimension(const ConnectionRefVector& connections, const PhysicalDimension::Type dimensionType);
132  PhysicalDimension* getInputDimension(const PhysicalDimension::Type dimensionType) const;
133  PhysicalDimension* getOutputDimension(const PhysicalDimension::Type dimensionType) const;
134 
138  void setNumPossibleInputConnections( int num );
139 
143  void setNumPossibleOutputConnections( int num );
144 
148  int getNumPossibleInputConnections() const;
149 
153  int getNumPossibleOutputConnections() const;
154 
155 
156  int getNumInputConnections() const;
157  int getNumOutputConnections() const;
158  int getNumConnections(agxPowerLine::Side side) const;
159  int getNumConnections() const;
160 
161  // All of these return -1 when the any number of connections is allowed.
162  int getNumFreeInputConnections() const;
163  int getNumFreeOutputConnections() const;
164  int getNumFreeConnections(agxPowerLine::Side side) const;
165  int getNumFreeConnections() const;
166 
167  bool hasFreeInputConnection() const;
168  bool hasFreeOutputConnection() const;
169  bool hasFreeConnection(agxPowerLine::Side side) const;
170  bool hasFreeConnection() const;
171 
175  bool hasInputConnection(Connection* connection);
176 
180  bool hasOutputConnection(Connection* connection);
181 
182 
186  const agxPowerLine::Connection* getInputConnection(size_t index) const;
187 
191  const agxPowerLine::Connection* getOutputConnection(size_t index) const;
192 
196  agxPowerLine::Connection* getInputConnection(size_t index);
197 
201  agxPowerLine::Connection* getOutputConnection(size_t index);
202 
203  agxPowerLine::Connection* findInputConnection(const agxPowerLine::Unit* unit);
204  agxPowerLine::Connection* findOutputConnection(const agxPowerLine::Unit* unit);
205  agxPowerLine::Connection* findConnection(const agxPowerLine::Unit* unit, agxPowerLine::Side side);
206 
207 
208  const agxPowerLine::Connection* findInputConnection(const agxPowerLine::Unit* unit) const;
209  const agxPowerLine::Connection* findOutputConnection(const agxPowerLine::Unit* unit) const;
210  const agxPowerLine::Connection* findConnection(const agxPowerLine::Unit* unit, agxPowerLine::Side side) const;
211 
215  const agxPowerLine::ConnectionRefVector& getOutputConnections() const;
216 
220  const agxPowerLine::ConnectionRefVector& getInputConnections() const;
221 
225  agxPowerLine::ConnectionRefVector& getOutputConnections();
226 
230  agxPowerLine::ConnectionRefVector& getInputConnections();
231 
232  const agxPowerLine::ConnectionRefVector& getConnections(agxPowerLine::Side side) const;
233 
243 
244 
248 
254 
259 
264  agxPowerLine::ElementaryPhysicalDimensionConstraint* getElementaryConstraint() const;
265 
269  virtual bool isOutput( Connection* connection ) const;
270 
274  virtual bool isOutput(const agxPowerLine::PhysicalDimension* dimension ) const;
275 
281  virtual bool isInput(const agxPowerLine::PhysicalDimension* dimension) const;
282 
286  void setDamping(agx::Real damping);
287  agx::Real getDamping() const;
288 
289 
290  agx::Real getRatio() const;
291  agx::Real getRatioDerivative() const;
292 
293  virtual agx::Real getRatio(agx::Real x) const;
294  virtual agx::Real getRatioDerivative(agx::Real x) const;
295 
299  virtual agx::RegularizationParameters::VariableType calculateComplianceAndDamping(const agx::Real /*timeStep*/, agx::Real& /*compliance*/, agx::Real& /*damping*/);
300 
301 
305  virtual bool postStore( agxStream::StorageStream& str ) const;
306  virtual bool postRestore(agxStream::StorageStream& str);
307 
311  virtual agx::Real getViolation() const;
312 
313  void setPowerLine(agxPowerLine::PowerLine* powerLine);
314 
315  agxPowerLine::PowerLine* getPowerLine() const;
316 
317  bool connectDimensions(Unit* unit, agxPowerLine::Side mySide, agxPowerLine::Side unitSide);
318 
323  bool connect(agxPowerLine::PhysicalDimension* dimension,
324  agxPowerLine::Side connectorSide,
325  agxPowerLine::Side dimensionSide);
326 
327  virtual bool connect(agxPowerLine::PhysicalDimension* inputDimension,
328  agxPowerLine::Side inputSide,
329  agxPowerLine::Side outputSide,
330  agxPowerLine::PhysicalDimension* outputDimension);
331 
332  bool disconnect(agxPowerLine::PhysicalDimension* dimension,
333  agxPowerLine::Side connectorSide,
334  agxPowerLine::Side dimensionSide);
335 
336 
337  bool isConstraintValid() const;
338 
339  virtual bool vetoConnect(agxPowerLine::Unit* unit) const;
340 
344  virtual bool store(agxStream::StorageStream& str) const override;
345 
349  virtual bool restore(agxStream::StorageStream& str) override;
350 
351  bool getIgnoreForStoreRestoreStream() const;
352  void setIgnoreForStoreRestoreStream(bool ignore);
353 
355  virtual void store(agxStream::OutputArchive& out) const override;
356  virtual void restore(agxStream::InputArchive& in) override;
357 
358  protected:
359 
363  void setRatio(agx::Real ratio);
364  void setRatioDerivative(agx::Real ratioDerivative);
365 
366  bool getUnits(UnitPtrSetVector& units, ConnectionRefVector& connections, const bool startFromCleanUnitSet = true);
367  bool getUnits(UnitConstPtrSetVector& units, const ConnectionRefVector& connections, const bool startFromCleanUnitSet = true) const;
368 
369  bool hasNonValidInputConnection() const;
370  bool hasNonValidOutputConnection() const;
371 
372 // Swig tries to generate bindings to this protected connect member function
373 // which leads to compiler errors since the function is protected.
374 #ifndef SWIG
376  virtual bool connect(
377  agxPowerLine::Unit* inputUnit, agxPowerLine::Side inputUnitSide,
378  agxPowerLine::Side outputUnitSide, agxPowerLine::Unit* outputUnit);
379 #endif
380 
381  void uninitialize();
382  virtual ~Connector();
383 
384  protected:
391 
393 
397 
399  };
400 
403 
408 
409 }
410 
agxPowerLine::Connector::m_ignoreMeForStoreRestoreStream
bool m_ignoreMeForStoreRestoreStream
Definition: Connector.h:398
agxPowerLine::Connector::m_outputTypes
DimensionTypeVector m_outputTypes
Definition: Connector.h:390
agxPowerLine::ElementaryPhysicalDimensionConstraint
Pure virtual function.
Definition: PowerLineConstraints.h:37
agx::Real
double Real
Definition: Real.h:42
agxPowerLine::Side
Side
Definition: Sides.h:28
Vector.h
agxData::getTypes
const TypeTable & getTypes()
agx::RegularizationParameters::VariableType
VariableType
Definition: RegularizationParameters.h:32
agxPowerLine::SubGraph
Definition: SubGraph.h:58
agx::Vector< PhysicalDimension::Type >
agxStream::out
OutputRef< Serializable > out(const char *name, const Serializable *obj)
Return an object that contain the name and the object that should be serialized to an archive.
Definition: OutputArchive.h:412
agxPowerLine::Connector::m_numPossibleOutputs
int m_numPossibleOutputs
Definition: Connector.h:386
export.h
DOXYGEN_END_INTERNAL_BLOCK
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:97
LookupTables.h
PowerLineUtils.h
agxUtil::ConstraintHolder
Utility class to hold custom implementations of constraints.
Definition: agxUtil.h:463
agxPowerLine::PhysicalDimensionMultiBodyConstraintImplementation
Constraint implementation for constraining a number of physical dimensions of the same type.
Definition: PowerLineConstraints.h:149
DOXYGEN_START_INTERNAL_BLOCK
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:96
agxStream::StorageStream
Abstract base class for storing/restoring a line/drums with version control.
Definition: StorageStream.h:48
agxPowerLine::Connector::m_ratioDerivative
agx::Real m_ratioDerivative
Definition: Connector.h:395
AGXSTREAM_DECLARE_ABSTRACT_SERIALIZABLE
#define AGXSTREAM_DECLARE_ABSTRACT_SERIALIZABLE(T)
Use this in a pure abstract Serializable class to add the required methods Important: Use full namesp...
Definition: Serializable.h:221
agxPowerLine::Connector::m_damping
agx::Real m_damping
Definition: Connector.h:392
agxPowerLine::Connector::m_numPossibleInputs
int m_numPossibleInputs
Definition: Connector.h:385
agxPowerLine::detail::ConnectionOperations
Definition: ConnectionOperations.h:38
agxPowerLine::DimensionTypeVector
agx::Vector< PhysicalDimension::Type > DimensionTypeVector
Definition: Connector.h:42
agxPowerLine::PhysicalDimension
Pure virtual class.
Definition: PhysicalDimension.h:92
agxPowerLine::PhysicalDimension::Type
int Type
Definition: PhysicalDimension.h:95
agxPowerLine::Connector::m_ratio
agx::Real m_ratio
Definition: Connector.h:394
agxPowerLine::UnitPtrSetVector
agx::SetVector< Unit * > UnitPtrSetVector
Definition: Connector.h:38
agxStream::in
InputRef< T > in(const char *name, T &obj)
Create an object with a name and a reference to the object that should be restored (usually a pointer...
Definition: InputArchive.h:399
agxPowerLine::Unit
Pure virtual class.
Definition: Unit.h:71
agx::ref_ptr
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:29
agxSDK::Simulation
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:125
agx::SetVector
This class is a combined container which has the find complexity of a HashTable, deterministic iterat...
Definition: SetVector.h:37
agxPowerLine::detail::ConnectionOperations::connect
static bool connect(agxPowerLine::Unit *unit1, agxPowerLine::Side side1, agxPowerLine::Side side2, agxPowerLine::Unit *unit2)
Connect Unit->Unit.
agxPowerLine::UnitRef
agx::ref_ptr< Unit > UnitRef
Definition: Connector.h:45
agxPowerLine::UnitRefVector
agx::Vector< UnitRef > UnitRefVector
Definition: Connector.h:46
agxPowerLine::UnitConstPtrSetVector
agx::SetVector< const Unit * > UnitConstPtrSetVector
Definition: Connector.h:41
agxPowerLine::PowerLine
PowerLine is the base class for a system of power transfer integrated into the rigid body simulation.
Definition: PowerLine.h:65
agxPowerLine::ConnectorPtrSetVector
agx::SetVector< Connector * > ConnectorPtrSetVector
Definition: Connector.h:402
agxPowerLine::ConnectorRefVector
agx::Vector< ConnectorRef > ConnectorRefVector
Definition: Connector.h:405
agxPowerLine::Connector::m_outputConnections
ConnectionRefVector m_outputConnections
Definition: Connector.h:388
agxPowerLine::ConnectorRef
agx::ref_ptr< Connector > ConnectorRef
Definition: Connector.h:404
agxStream::OutputArchive
Class for writing serialized data in binary format to a stream.
Definition: OutputArchive.h:56
Serializable.h
agxPowerLine::Connector::m_inputTypes
DimensionTypeVector m_inputTypes
Definition: Connector.h:389
agxStream::InputArchive
Class for reading a binary stream of serialized data.
Definition: InputArchive.h:50
agxPowerLine
agxPowerLine contains a collection of connected components that transport power across a system.
Definition: MotorUnit.h:23
agxPowerLine::Connector
Links two connections together.
Definition: Connector.h:52
SubGraph.h
AGXMODEL_EXPORT
#define AGXMODEL_EXPORT
Definition: agxModel/export.h:42
agxPowerLine::Connector::m_inputConnections
ConnectionRefVector m_inputConnections
Definition: Connector.h:387
agxFMI2::Export::Constraint::setDamping
AGXFMI_EXPORT InputVariable_Real * setDamping(agx::Constraint *constraint)
agxPowerLine::Connector::m_constraint
PhysicalDimensionMultiBodyConstraintImplementation * m_constraint
Definition: Connector.h:396
Sides.h
agxPowerLine::Connection
Definition: PowerLineUtils.h:257
agxPowerLine::ConnectorPtrVector
agx::Vector< Connector * > ConnectorPtrVector
Definition: Connector.h:401
agxPowerLine::ConnectorObserverVector
agx::Vector< ConnectorObserver > ConnectorObserverVector
Definition: Connector.h:407
StorageStream.h
List.h
SetVector.h
agxUtil.h
PhysicalDimension.h
agxPowerLine::ConnectorRefSet
agx::SetVector< ConnectorRef > ConnectorRefSet
Definition: Connector.h:406