AGX Dynamics  2.37.2.0
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 #ifndef AGXPOWERLINE_CONNECTOR_H
18 #define AGXPOWERLINE_CONNECTOR_H
19 
20 #include <agxModel/export.h>
21 
23 #include <agxStream/Serializable.h>
25 #include <agx/List.h>
26 #include <agx/Vector.h>
27 #include <agx/SetVector.h>
28 #include <agxUtil/agxUtil.h>
30 #include <agxPowerLine/Sides.h>
31 #include <agxPowerLine/SubGraph.h>
32 #include <agx/LookupTables.h>
33 
34 namespace agxPowerLine
35 {
36  class Unit;
37  class PowerLine;
38  class PhysicalDimensionMultiBodyConstraintImplementation;
40 
44 
45  // Local typdef to avoid include loop.
48 
54  {
55  public:
56 
60  Connector();
61 
62  virtual void initConstraint();
63 
64  virtual bool addNotification(agxSDK::Simulation* simulation) override;
65 
69  virtual bool removeNotification(agxUtil::ConstraintHolder* holder, agxSDK::Simulation* simulation) override;
70 
74  virtual bool connect(agxPowerLine::Unit* unit);
75 
76  virtual bool connect(
77  agxPowerLine::Side mySide,
78  agxPowerLine::Side unitSide,
79  agxPowerLine::Unit* unit);
80 
87  virtual bool disconnect(agxPowerLine::Unit* unit);
88 
89  virtual bool disconnect();
90 
91 
92  virtual agxPowerLine::Side getSide(const agxPowerLine::Unit* unit) const;
93 
94 
95  agx::Real getPowerOut() const;
96 
97  agx::Real getPowerIn() const;
98 
102  agx::Real calculateEfficiency() const;
103 
107  virtual agx::Real calculateViolation( ) const;
108 
109  bool compareWithInputTypes( PhysicalDimensionRefVector& dimensions ) const;
110 
111  bool compareWithOutputTypes( PhysicalDimensionRefVector& dimensions ) const;
112 
114  const DimensionTypeVector& getInputTypes() const;
115  const DimensionTypeVector& getOutputTypes() const;
116  const DimensionTypeVector& getTypes(agxPowerLine::Side side) const;
117 
118  // Get a hash vector with pointers to all units connected to this connector.
120  bool getInputUnits(UnitPtrSetVector& units, const bool startFromCleanUnitSet = true);
121  bool getOutputUnits(UnitPtrSetVector& units, const bool startFromCleanUnitSet = true);
122  bool getUnits(UnitPtrSetVector& units, agxPowerLine::Side side, const bool startFromCleanUnitSet = true);
123  bool getUnits(UnitPtrSetVector& units, const bool startFromCleanUnitSet = true);
124 
125 
126  // Get a hash vector with pointers to all units connected to this connector.
127  bool getInputUnits(UnitConstPtrSetVector& units, const bool startFromCleanUnitSet = true) const;
128  bool getOutputUnits(UnitConstPtrSetVector& units, const bool startFromCleanUnitSet = true) const;
129  bool getUnits(UnitConstPtrSetVector& units, agxPowerLine::Side side, const bool startFromCleanUnitSet = true) const;
130  bool getUnits(UnitConstPtrSetVector& units, const bool startFromCleanUnitSet = true) const;
131 
132  static PhysicalDimension* getDimension(const ConnectionRefVector& connections, const PhysicalDimension::Type dimensionType);
133  PhysicalDimension* getInputDimension(const PhysicalDimension::Type dimensionType) const;
134  PhysicalDimension* getOutputDimension(const PhysicalDimension::Type dimensionType) const;
135 
139  void setNumPossibleInputConnections( int num );
140 
144  void setNumPossibleOutputConnections( int num );
145 
149  int getNumPossibleInputConnections() const;
150 
154  int getNumPossibleOutputConnections() const;
155 
156 
157  int getNumInputConnections() const;
158  int getNumOutputConnections() const;
159  int getNumConnections(agxPowerLine::Side side) const;
160  int getNumConnections() const;
161 
162  // All of these return -1 when the any number of connections is allowed.
163  int getNumFreeInputConnections() const;
164  int getNumFreeOutputConnections() const;
165  int getNumFreeConnections(agxPowerLine::Side side) const;
166  int getNumFreeConnections() const;
167 
168  bool hasFreeInputConnection() const;
169  bool hasFreeOutputConnection() const;
170  bool hasFreeConnection(agxPowerLine::Side side) const;
171  bool hasFreeConnection() const;
172 
176  bool hasInputConnection(Connection* connection);
177 
181  bool hasOutputConnection(Connection* connection);
182 
183 
187  const agxPowerLine::Connection* getInputConnection(size_t index) const;
188 
192  const agxPowerLine::Connection* getOutputConnection(size_t index) const;
193 
197  agxPowerLine::Connection* getInputConnection(size_t index);
198 
202  agxPowerLine::Connection* getOutputConnection(size_t index);
203 
204  agxPowerLine::Connection* findInputConnection(const agxPowerLine::Unit* unit);
205  agxPowerLine::Connection* findOutputConnection(const agxPowerLine::Unit* unit);
206  agxPowerLine::Connection* findConnection(const agxPowerLine::Unit* unit, agxPowerLine::Side side);
207 
208 
209  const agxPowerLine::Connection* findInputConnection(const agxPowerLine::Unit* unit) const;
210  const agxPowerLine::Connection* findOutputConnection(const agxPowerLine::Unit* unit) const;
211  const agxPowerLine::Connection* findConnection(const agxPowerLine::Unit* unit, agxPowerLine::Side side) const;
212 
216  const agxPowerLine::ConnectionRefVector& getOutputConnections() const;
217 
221  const agxPowerLine::ConnectionRefVector& getInputConnections() const;
222 
226  agxPowerLine::ConnectionRefVector& getOutputConnections();
227 
231  agxPowerLine::ConnectionRefVector& getInputConnections();
232 
233  const agxPowerLine::ConnectionRefVector& getConnections(agxPowerLine::Side side) const;
234 
244 
245 
249 
255 
260 
265  agxPowerLine::ElementaryPhysicalDimensionConstraint* getElementaryConstraint() const;
266 
270  virtual bool isOutput( Connection* connection ) const;
271 
275  virtual bool isOutput(const agxPowerLine::PhysicalDimension* dimension ) const;
276 
282  virtual bool isInput(const agxPowerLine::PhysicalDimension* dimension) const;
283 
287  void setDamping(agx::Real damping);
288  agx::Real getDamping() const;
289 
290 
291  agx::Real getRatio() const;
292  agx::Real getRatioDerivative() const;
293 
294  virtual agx::Real getRatio(agx::Real x) const;
295  virtual agx::Real getRatioDerivative(agx::Real x) const;
296 
300  virtual agx::RegularizationParameters::VariableType calculateComplianceAndDamping(const agx::Real /*timeStep*/, agx::Real& /*compliance*/, agx::Real& /*damping*/);
301 
302 
306  virtual bool postStore( agxStream::StorageStream& str ) const;
307  virtual bool postRestore(agxStream::StorageStream& str);
308 
312  virtual agx::Real getViolation() const;
313 
314  void setPowerLine(agxPowerLine::PowerLine* powerLine);
315 
316  agxPowerLine::PowerLine* getPowerLine() const;
317 
318  bool connectDimensions(Unit* unit, agxPowerLine::Side mySide, agxPowerLine::Side unitSide);
319 
324  bool connect(agxPowerLine::PhysicalDimension* dimension,
325  agxPowerLine::Side connectorSide,
326  agxPowerLine::Side dimensionSide);
327 
328  virtual bool connect(agxPowerLine::PhysicalDimension* inputDimension,
329  agxPowerLine::Side inputSide,
330  agxPowerLine::Side outputSide,
331  agxPowerLine::PhysicalDimension* outputDimension);
332 
333  bool disconnect(agxPowerLine::PhysicalDimension* dimension,
334  agxPowerLine::Side connectorSide,
335  agxPowerLine::Side dimensionSide);
336 
337 
338  bool isConstraintValid() const;
339 
340  virtual bool vetoConnect(agxPowerLine::Unit* unit) const;
341 
345  virtual bool store(agxStream::StorageStream& str) const override;
346 
350  virtual bool restore(agxStream::StorageStream& str) override;
351 
352  bool getIgnoreForStoreRestoreStream() const;
353  void setIgnoreForStoreRestoreStream(bool ignore);
354 
356  virtual void store(agxStream::OutputArchive& out) const override;
357  virtual void restore(agxStream::InputArchive& in) override;
358 
359  protected:
360 
364  void setRatio(agx::Real ratio);
365  void setRatioDerivative(agx::Real ratioDerivative);
366 
367  bool getUnits(UnitPtrSetVector& units, ConnectionRefVector& connections, const bool startFromCleanUnitSet = true);
368  bool getUnits(UnitConstPtrSetVector& units, const ConnectionRefVector& connections, const bool startFromCleanUnitSet = true) const;
369 
370  bool hasNonValidInputConnection() const;
371  bool hasNonValidOutputConnection() const;
372 
373 // Swig tries to generate bindings to this protected connect member function
374 // which leads to compiler errors since the function is protected.
375 #ifndef SWIG
377  virtual bool connect(
378  agxPowerLine::Unit* inputUnit, agxPowerLine::Side inputUnitSide,
379  agxPowerLine::Side outputUnitSide, agxPowerLine::Unit* outputUnit);
380 #endif
381 
382  void uninitialize();
383  virtual ~Connector();
384 
385  protected:
390  DimensionTypeVector m_inputTypes;
391  DimensionTypeVector m_outputTypes;
392 
394 
398 
400  };
401 
404 
409 
410 }
411 
412 #endif // AGXMODEL_POWER_LINE_UTILS_H
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:400
Links two connections together.
Definition: Connector.h:53
Utility class to hold custom implementations of constraints.
Definition: agxUtil.h:463
ConnectionRefVector m_inputConnections
Definition: Connector.h:388
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...
const TypeTable & getTypes()
Constraint implementation for constraining a number of physical dimensions of the same type...
Pure virtual class.
Definition: Unit.h:72
agx::Vector< PhysicalDimension::Type > DimensionTypeVector
Definition: Connector.h:43
agxPowerLine contains a collection of connected components that transport power across a system...
Definition: MotorUnit.h:23
agx::Vector< Connector * > ConnectorPtrVector
Definition: Connector.h:402
agx::Vector< UnitRef > UnitRefVector
agx::ref_ptr< Unit > UnitRef
agx::SetVector< const Unit * > UnitConstPtrSetVector
Definition: Connector.h:42
agx::Vector< ConnectorRef > ConnectorRefVector
Definition: Connector.h:406
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:29
agx::SetVector< Connector * > ConnectorPtrSetVector
Definition: Connector.h:403
bool m_ignoreMeForStoreRestoreStream
Definition: Connector.h:399
Class for reading a binary stream of serialized data.
Definition: InputArchive.h:51
ConnectionRefVector m_outputConnections
Definition: Connector.h:389
Abstract base class for storing/restoring a line/drums with version control.
Definition: StorageStream.h:48
DimensionTypeVector m_outputTypes
Definition: Connector.h:391
DimensionTypeVector m_inputTypes
Definition: Connector.h:390
AGXFMI_EXPORT InputVariable_Real * setDamping(agx::Constraint *constraint)
static bool connect(agxPowerLine::Unit *unit1, agxPowerLine::Side side1, agxPowerLine::Side side2, agxPowerLine::Unit *unit2)
Connect Unit->Unit.
Class for writing serialized data in binary format to a stream.
Definition: OutputArchive.h:56
agx::ref_ptr< Connector > ConnectorRef
Definition: Connector.h:405
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:126
#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
#define AGXMODEL_EXPORT
agx::SetVector< ConnectorRef > ConnectorRefSet
Definition: Connector.h:407
double Real
Definition: Real.h:42
PowerLine is the base class for a system of power transfer integrated into the rigid body simulation...
Definition: PowerLine.h:70
agx::SetVector< Unit * > UnitPtrSetVector
Definition: Connector.h:39
PhysicalDimensionMultiBodyConstraintImplementation * m_constraint
Definition: Connector.h:397
agx::Vector< ConnectorObserver > ConnectorObserverVector
Definition: Connector.h:408
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: Object.h:98
This class is a combined container which has the find complexity of a HashTable, deterministic iterat...
Definition: SetVector.h:37
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: Object.h:97
agx::Real m_ratioDerivative
Definition: Connector.h:396