KratosMultiphysics
KRATOS Multiphysics (Kratos) is a framework for building parallel, multi-disciplinary simulation software, aiming at modularity, extensibility, and high performance. Kratos is written in C++, and counts with an extensive Python interface.
flags.h
Go to the documentation of this file.
1 // | / |
2 // ' / __| _` | __| _ \ __|
3 // . \ | ( | | ( |\__ `
4 // _|\_\_| \__,_|\__|\___/ ____/
5 // Multi-Physics
6 //
7 // License: BSD License
8 // Kratos default license: kratos/license.txt
9 //
10 // Main authors: Pooyan Dadvand
11 // Riccardo Rossi
12 //
13 //
14 
15 #if !defined(KRATOS_FLAGS_H_INCLUDED )
16 #define KRATOS_FLAGS_H_INCLUDED
17 
18 
19 
20 // System includes
21 #include <string>
22 #include <iostream>
23 
24 
25 // External includes
26 
27 
28 // Project includes
29 #include "includes/define.h"
30 
31 namespace Kratos
32 {
33 
36 
40 
44 
48 
52 
54 
56 class Serializer;
57 class KRATOS_API(KRATOS_CORE) Flags
58 {
59 public:
62 
65 
66 #ifdef _WIN32 // work around for windows int64_t error
67  typedef __int64 int64_t;
68 #endif
69 
70  typedef int64_t BlockType;
71 
72  typedef int64_t FlagType;
73 
74  typedef std::size_t IndexType;
75 
76  enum FlagsList
77  {
78  Flag0 = BlockType(1),
79  Flag1 = BlockType(1) << 1,
80  Flag2 = BlockType(1) << 2,
81  Flag3 = BlockType(1) << 3,
82  Flag4 = BlockType(1) << 4,
83  Flag5 = BlockType(1) << 5,
84  Flag6 = BlockType(1) << 6,
85  Flag7 = BlockType(1) << 7,
86  Flag8 = BlockType(1) << 8,
87  Flag9 = BlockType(1) << 9,
88 
89  Flag10 = BlockType(1) << 10,
90  Flag11 = BlockType(1) << 11,
91  Flag12 = BlockType(1) << 12,
92  Flag13 = BlockType(1) << 13,
93  Flag14 = BlockType(1) << 14,
94  Flag15 = BlockType(1) << 15,
95  Flag16 = BlockType(1) << 16,
96  Flag17 = BlockType(1) << 17,
97  Flag18 = BlockType(1) << 18,
98  Flag19 = BlockType(1) << 19,
99 
100  Flag20 = BlockType(1) << 20,
101  Flag21 = BlockType(1) << 21,
102  Flag22 = BlockType(1) << 22,
103  Flag23 = BlockType(1) << 23,
104  Flag24 = BlockType(1) << 24,
105  Flag25 = BlockType(1) << 25,
106  Flag26 = BlockType(1) << 26,
107  Flag27 = BlockType(1) << 27,
108  Flag28 = BlockType(1) << 28,
109  Flag29 = BlockType(1) << 29,
110 
111  Flag30 = BlockType(1) << 30//,
112  };
113 
117 
119  Flags() : mIsDefined(BlockType()), mFlags(BlockType()) {}
120 
122  Flags(Flags const& rOther) : mIsDefined(rOther.mIsDefined), mFlags(rOther.mFlags)
123  {
124  }
125 
126 // Flags(BlockType rOther) : mIsDefined(rOther), mFlags(rOther)
127 // {
128 // }
129 
130 // template<class TFlagsType>
131 // Flags(TFlagsType rOther) : mIsDefined(static_cast<BlockType>(rOther)), mFlags(static_cast<BlockType>(rOther))
132 // {
133 // }
134 
136  virtual ~Flags() {}
137 
138  static Flags Create(IndexType ThisPosition, bool Value=true)
139  {
140  Flags flags;
141  flags.SetPosition(ThisPosition, Value);
142  return flags;
143  }
144 
145 
149 
151  Flags& operator=(Flags const& rOther)
152  {
153  mIsDefined = rOther.mIsDefined;
154  mFlags = rOther.mFlags;
155  return *this;
156  }
157 
158 
159  operator bool() const
160  {
161  return mFlags;
162  }
163 
164  Flags operator~() const
165  {
166  Flags results(*this);
167  results.mFlags = ~mFlags;
168  return results;
169  }
170 
171  bool operator!() const
172  {
173  Flags results(*this);
174  results.mFlags = !mFlags;
175  return results;
176  }
177 
178 
179  void AssignFlags(Flags const& rOther)
180  {
181  mIsDefined = rOther.mIsDefined;
182  mFlags = rOther.mFlags;
183  }
184 
188 
189  void Set(const Flags ThisFlag);
190 
191  void Set(const Flags ThisFlag, bool Value);
192 
193  void Reset(const Flags ThisFlag)
194  {
195  mIsDefined &= (~ThisFlag.mIsDefined);
196  mFlags &= (~ThisFlag.mIsDefined); // I want to put to zero the ones are set regardless to their value. Pooyan.
197  }
198 
199  void Flip(const Flags ThisFlag)
200  {
201  mIsDefined |= ThisFlag.mIsDefined;
202  mFlags ^= (ThisFlag.mIsDefined); // I want to flip the ones are set in this flags regardless to their value. Pooyan.
203  }
204 
205  void SetPosition(IndexType Position, bool Value=true )
206  {
207  mIsDefined |= (BlockType(1) << Position);
208 
209 
210  mFlags &= ~(BlockType(1) << Position); // First reseting the position
211  mFlags |= (BlockType(Value) << Position);
212 
213  }
214 
215  bool GetPosition(IndexType Position) const
216  {
217  return (mFlags & (BlockType(1) << Position));
218  }
219 
220 
221  void FlipPosition(IndexType Position)
222  {
223  mIsDefined |= (BlockType(1) << Position);
224  mFlags ^= (BlockType(1) << Position);
225  }
226 
227 
228  void ClearPosition(IndexType Position)
229  {
230  mIsDefined &= ~((BlockType(1) << Position));
231  mFlags &= ~(BlockType(1) << Position);
232  }
233 
234 
235  void Clear()
236  {
237  mIsDefined = BlockType();
238  mFlags = BlockType();
239  }
240 
241  Flags AsFalse() const
242  {
243  Flags this_flag_false(*this);
244  this_flag_false.mFlags = !((*this).mFlags);
245  return this_flag_false;
246  }
247 
251 
252  static const Flags AllDefined()
253  {
254  return Flags(~0,0);
255  }
256 
257  static const Flags AllTrue()
258  {
259  return Flags(~0,~0);
260  }
261 
265 
266 
267 // template<class TFlagsType>
268 // bool Is(TFlagsType Flag)
269 // {
270 // return (mFlags & Flag);
271 // }
272 
273 
274  bool Is(Flags const & rOther) const
275  {
276  return (mFlags & rOther.mFlags) | ((rOther.mIsDefined ^ rOther.mFlags) & (~mFlags));
277  }
278 
279  bool IsDefined(Flags const & rOther) const
280  {
281  return (mIsDefined & rOther.mIsDefined);
282  }
283 
284 
285 // template<class TFlagsType>
286 // bool IsNot(TFlagsType const& Flag )
287 // {
288 // return !(mFlags & Flag);
289 // }
290 
291  bool IsNot(Flags const& rOther) const
292  {
293  return !((mFlags & rOther.mFlags) | ((rOther.mIsDefined ^ rOther.mFlags) & (~mFlags)));
294  }
295 
296  bool IsNotDefined(Flags const& rOther) const
297  {
298  return !(mIsDefined & rOther.mIsDefined);
299  }
300 
301 
302 
306 
308  virtual std::string Info() const
309  {
310  std::stringstream buffer;
311  buffer << "Flags" ;
312  return buffer.str();
313  }
314 
316  virtual void PrintInfo(std::ostream& rOStream) const
317  {
318  rOStream << "Flags";
319  }
320 
322  virtual void PrintData(std::ostream& rOStream) const
323  {
324 
325  for(std::size_t i = sizeof(BlockType) * 8 ; i > 0 ; i--)
326  rOStream << bool(mFlags & (BlockType(1) << i));
327  }
328 
329 
333 
334 
335  friend bool KRATOS_API(KRATOS_CORE) operator==(const Flags& Left, const Flags& Right );
336 
337  friend bool KRATOS_API(KRATOS_CORE) operator!=(const Flags& Left, const Flags& Right );
338 
339  friend Flags KRATOS_API(KRATOS_CORE) operator|(const Flags& Left, const Flags& Right );
340 
341  friend Flags KRATOS_API(KRATOS_CORE) operator&(const Flags& Left, const Flags& Right );
342 
343  const Flags& operator|=(const Flags& Other );
344 
345  const Flags& operator&=(const Flags& Other );
346 
348 
349 protected:
352 
353 
357 
358 
362 
363 
367 
368 
372 
373 
377 
378 
382 
383 
385 
386 private:
389 
390 
394 
395  BlockType mIsDefined;
396  BlockType mFlags;
397 
398 
402 
403 
407 
408  friend class MPIDataCommunicator;
409 
410  BlockType GetDefined() const;
411 
412  void SetDefined(const BlockType& rDefined);
413 
414  BlockType GetFlags() const;
415 
416  void SetFlags(const BlockType& rValues);
417 
421  friend class Serializer;
422 
423  virtual void save(Serializer& rSerializer) const;
424 
425  virtual void load(Serializer& rSerializer);
426 
430 
431 
435 
439 
440  Flags(BlockType DefinedFlags, BlockType SetFlags):
441  mIsDefined(DefinedFlags), mFlags(SetFlags)
442  {}
443 
447 
448 
450 
451 }; // Class Flags
452 
454 
457 
458 
462 
463 
465 inline std::istream& operator >> (std::istream& rIStream,
466  Flags& rThis)
467 {
468  return rIStream;
469 }
470 
472 inline std::ostream& operator << (std::ostream& rOStream,
473  const Flags& rThis)
474 {
475  rThis.PrintInfo(rOStream);
476  rOStream << " : ";
477  rThis.PrintData(rOStream);
478 
479  return rOStream;
480 }
482 
483 
484 } // namespace Kratos.
485 
486 #endif // KRATOS_FLAGS_H_INCLUDED defined
Definition: flags.h:58
std::size_t IndexType
Definition: flags.h:74
void Flip(const Flags ThisFlag)
Definition: flags.h:199
Flags AsFalse() const
Definition: flags.h:241
bool IsDefined(Flags const &rOther) const
Definition: flags.h:279
void ClearPosition(IndexType Position)
Definition: flags.h:228
bool Is(Flags const &rOther) const
Definition: flags.h:274
int64_t FlagType
Definition: flags.h:72
virtual std::string Info() const
Turn back information as a string.
Definition: flags.h:308
void Reset(const Flags ThisFlag)
Definition: flags.h:193
FlagsList
Definition: flags.h:77
void FlipPosition(IndexType Position)
Definition: flags.h:221
static Flags Create(IndexType ThisPosition, bool Value=true)
Definition: flags.h:138
static const Flags AllTrue()
Definition: flags.h:257
Flags operator~() const
Definition: flags.h:164
Flags(Flags const &rOther)
Copy constructor.
Definition: flags.h:122
static const Flags AllDefined()
Definition: flags.h:252
virtual void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: flags.h:322
int64_t BlockType
Definition: flags.h:70
virtual void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: flags.h:316
bool IsNot(Flags const &rOther) const
Definition: flags.h:291
Flags()
Default constructor.
Definition: flags.h:119
KRATOS_CLASS_POINTER_DEFINITION(Flags)
Pointer definition of Flags.
virtual ~Flags()
Destructor.
Definition: flags.h:136
bool GetPosition(IndexType Position) const
Definition: flags.h:215
Flags & operator=(Flags const &rOther)
Assignment operator.
Definition: flags.h:151
void SetPosition(IndexType Position, bool Value=true)
Definition: flags.h:205
bool operator!() const
Definition: flags.h:171
void Clear()
Definition: flags.h:235
bool IsNotDefined(Flags const &rOther) const
Definition: flags.h:296
void AssignFlags(Flags const &rOther)
Definition: flags.h:179
Wrapper for common MPI calls within Kratos.
Definition: mpi_data_communicator.h:182
The serialization consists in storing the state of an object into a storage format like data file or ...
Definition: serializer.h:123
#define KRATOS_API(...)
Definition: kratos_export_api.h:40
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
REACTION_CHECK_STIFFNESS_FACTOR INNER_LOOP_ITERATION DISTANCE_THRESHOLD ACTIVE_CHECK_FACTOR AUXILIAR_COORDINATES NORMAL_GAP WEIGHTED_GAP WEIGHTED_SCALAR_RESIDUAL bool
Definition: contact_structural_mechanics_application_variables.h:93
bool operator==(const Flags &Left, const Flags &Right)
Definition: flags.cpp:45
Flags operator&(const Flags &Left, const Flags &Right)
Definition: flags.cpp:62
Flags operator|(const Flags &Left, const Flags &Right)
Definition: flags.cpp:55
std::istream & operator>>(std::istream &rIStream, LinearMasterSlaveConstraint &rThis)
input stream function
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
bool operator!=(const Flags &Left, const Flags &Right)
Definition: flags.cpp:50
flags
Definition: mpi_module_init.py:6
def load(f)
Definition: ode_solve.py:307
integer i
Definition: TensorModule.f:17