Program listing for file kernel/src/simulationTools/Topology.hpp

Program listing for file kernel/src/simulationTools/Topology.hpp#

  1#ifndef TOPOLOGY_H
  2#define TOPOLOGY_H
  3
  4#include "SiconosConst.hpp"
  5#include "SimulationTypeDef.hpp"
  6#include "SimulationGraphs.hpp"
  7
  8
  9class Topology : public std::enable_shared_from_this<Topology>
 10{
 11public:
 12
 13
 14
 15private:
 16  ACCEPT_SERIALIZATION(Topology);
 17
 18
 19  std::vector<SP::DynamicalSystemsGraph> _DSG;
 20
 21
 22  std::vector<SP::InteractionsGraph> _IG;
 23
 24
 25  bool _hasChanged = true;
 26
 27
 28  unsigned int _numberOfConstraints = 0;
 29
 30
 31  bool _symmetric = false;
 32
 33
 34  struct SetupFromNslaw;
 35  friend struct Topology::SetupFromNslaw;
 36
 37
 38
 39
 40  std::pair<DynamicalSystemsGraph::EDescriptor, InteractionsGraph::VDescriptor>
 41  __addInteractionInIndexSet0(SP::Interaction inter, SP::DynamicalSystem ds1, SP::DynamicalSystem ds2 = SP::DynamicalSystem());
 42
 43
 44  void __removeInteractionFromIndexSet(SP::Interaction inter);
 45
 46
 47  void __removeDynamicalSystemFromIndexSet(SP::DynamicalSystem ds);
 48
 49
 50  Topology(const Topology&) = delete;
 51  Topology& operator=(const Topology&) = delete;
 52
 53public:
 54
 55
 56
 57
 58  Topology();
 59
 60
 61  ~Topology();
 62
 63
 64
 65
 66  bool hasDynamicalSystem(SP::DynamicalSystem ds) const;
 67
 68
 69  bool hasInteraction(SP::Interaction inter) const;
 70
 71
 72  void removeInteraction(SP::Interaction inter);
 73
 74
 75  void insertDynamicalSystem(SP::DynamicalSystem ds);
 76
 77
 78  void removeDynamicalSystem(SP::DynamicalSystem ds);
 79
 80
 81  void setName(SP::DynamicalSystem ds, const std::string& name);
 82
 83
 84  std::string name(SP::DynamicalSystem ds);
 85
 86
 87  void setName(SP::Interaction inter, const std::string& name);
 88
 89
 90  std::string name(SP::Interaction inter);
 91
 92
 93  void setOSI(SP::DynamicalSystem ds, SP::OneStepIntegrator OSI);
 94
 95
 96  std::pair<DynamicalSystemsGraph::EDescriptor, InteractionsGraph::VDescriptor>
 97  link(SP::Interaction inter, SP::DynamicalSystem ds, SP::DynamicalSystem ds2 = SP::DynamicalSystem());
 98
 99
100  void setControlProperty(SP::Interaction inter,
101                          const bool isControlInteraction);
102
103
104  inline SP::InteractionsGraph indexSet0() const
105  {
106    return _IG[0];
107  }
108
109  SP::InteractionProperties interaction_properties(unsigned int index, SP::Interaction inter)
110  {
111    InteractionsGraph::VDescriptor ui = indexSet(index)->descriptor(inter);
112    SP::InteractionProperties inter_prop(new InteractionProperties(indexSet(index)->properties(ui)));
113    return inter_prop;
114  };
115
116
117  SP::InteractionsGraph indexSet(unsigned int num) const;
118
119
120  inline size_t numberOfIndexSet() const
121  {
122    return _IG.size();
123  };
124
125
126  inline void resetIndexSetPtr(unsigned int num)
127  {
128    assert(num < _IG.size()) ;
129
130
131
132
133
134
135    _IG[num].reset(new InteractionsGraph());
136
137    _IG[num]->properties().symmetric = _symmetric;
138    _IG[num]->update_vertices_indices();
139    _IG[num]->update_edges_indices();
140
141  };
142
143
144  inline SP::DynamicalSystemsGraph dSG(unsigned int num) const
145  {
146    assert(num < _DSG.size()) ;
147    return _DSG[num];
148  };
149
150
151  inline size_t indexSetsSize() const
152  {
153    return _IG.size();
154  };
155
156
157  inline size_t indexSetSize(unsigned int level) const
158  {
159    return _IG[level]->size();
160  };
161
162
163  inline void indexSetsResize(unsigned int newSize)
164  {
165    _IG.resize(newSize);
166  };
167
168
169
170
171
172  inline void setHasChanged(const bool val)
173  {
174    _hasChanged = val;
175  }
176
177
178  inline bool hasChanged() const
179  {
180    return _hasChanged;
181  }
182
183
184  inline unsigned int numberOfConstraints() const
185  {
186    return _numberOfConstraints;
187  };
188
189  void clear();
190
191
192  void setSymmetric(bool val)
193  {
194    _symmetric = val;
195  }
196
197
198  void setProperties();
199
200
201  SP::DynamicalSystem getDynamicalSystem(unsigned int requiredNumber) const;
202
203
204  void displayDynamicalSystems() const;
205
206
207  SP::DynamicalSystem getDynamicalSystem(std::string name) const;
208
209
210  SP::Interaction getInteraction(unsigned int requiredNumber) const;
211
212
213  SP::Interaction getInteraction(std::string name) const;
214
215
216  std::vector<SP::Interaction> interactionsForDS(SP::DynamicalSystem) const;
217
218
219  std::vector<SP::Interaction> interactionsForPairOfDS(
220    SP::DynamicalSystem ds1,
221    SP::DynamicalSystem ds2=SP::DynamicalSystem()) const;
222
223
224  std::vector<SP::DynamicalSystem>
225    dynamicalSystemsForInteraction(SP::Interaction) const;
226
227
228  DynamicalSystemsGraph::VDescriptor getDSG0Descriptor(SP::DynamicalSystem ds)
229  {
230    return _DSG[0]->descriptor(ds);
231  }
232
233
234  unsigned int numberOfInvolvedDS(unsigned int inumber);
235
236
237};
238
239DEFINE_SPTR(Topology)
240
241#endif