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.
table_key_variables.hpp
Go to the documentation of this file.
1 //
2 // Project Name: KratosConstitutiveModelsApplication $
3 // Created by: $Author: JMCarbonell $
4 // Last modified by: $Co-Author: $
5 // Date: $Date: October 2018 $
6 // Revision: $Revision: 0.0 $
7 //
8 //
9 
10 
11 #if !defined(KRATOS_TABLE_KEY_VARIABLES_H_INCLUDED )
12 #define KRATOS_TABLE_KEY_VARIABLES_H_INCLUDED
13 
14 // System includes
15 
16 // External includes
17 
18 // Project includes
19 #include "includes/define.h"
20 #include "containers/variable.h"
21 
22 namespace Kratos
23 {
24 
27 
31 
35 
39 
43 
45 
48 template<class TArgumentType, class TResultType = TArgumentType>
50 {
51  public:
54 
57 
58 #ifdef _WIN32 // work around for windows int64_t error
59  typedef __int64 int64_t;
60 #endif
61 
63 
65 
66  typedef std::pair<const XVariableType*, const YVariableType*> TableVariablesType;
67 
68  typedef std::vector<TableVariablesType> TableVariablesContainerType;
69 
73 
76 
79  :mKeys(rOther.mKeys)
80  ,mData(rOther.mData)
81  {}
82 
84  TableKeyVariables::Pointer Clone() const
85  {
86  return Kratos::make_shared< TableKeyVariables >(*this);
87  }
88 
91 
95 
99 
100  void RegisterTable(const XVariableType& rXVariable, const YVariableType& rYVariable)
101  {
102  mKeys.push_back(Key(rXVariable.Key(), rYVariable.Key()));
103  mData.push_back(TableVariablesType(&rXVariable,&rYVariable));
104  }
105 
106  const XVariableType& GetXVariable(int64_t rTableKey) const
107  {
108  std::size_t i;
109  for(i=0; i<mKeys.size(); ++i)
110  if(mKeys[i]==rTableKey)
111  break;
112  return *(mData[i].first);
113  }
114 
115  const YVariableType& GetYVariable(int64_t rTableKey) const
116  {
117  std::size_t i;
118  for(i=0; i<mKeys.size(); ++i)
119  if(mKeys[i]==rTableKey)
120  break;
121  return *(mData[i].second);
122  }
123 
127 
131 
135 
137  std::string Info() const
138  {
139  return "TableKeyVariables";
140  }
141 
143  void PrintInfo(std::ostream& rOStream) const
144  {
145  rOStream << "TableKeyVariables";
146  }
147 
149  void PrintData(std::ostream& rOStream) const
150  {
151  rOStream << "This table keys contain " << mData.size() << " variables";
152  }
153 
157 
159 
160  protected:
163 
167 
171 
175 
179 
183 
187 
189 
190  private:
193 
197 
198  std::vector<int64_t> mKeys;
199 
201 
205 
209 
210  // must be the same method as in properties.h
211  int64_t Key(std::size_t XKey, std::size_t YKey) const
212  {
213  int64_t result_key = XKey;
214  result_key = result_key << 32;
215  result_key |= YKey; // I know that the key is less than 2^32 so I don't need zeroing the upper part
216  return result_key;
217  }
218 
222 
223  friend class Serializer;
224 
225  void save(Serializer& rSerializer) const
226  {
227  rSerializer.save("mKeys", mKeys);
228  rSerializer.save("mData", mData);
229  }
230 
231  void load(Serializer& rSerializer)
232  {
233  rSerializer.load("mKeys", mKeys);
234  rSerializer.load("mData", mData);
235  }
236 
240 
241 
245 
246 
250 
252 
253 }; // Class TableKeyVariables
254 
256 
259 
260 
264 
266 template<class TArgumentType, class TResultType>
267 inline std::istream& operator >> (std::istream& rIStream,
269 
271 template<class TArgumentType, class TResultType>
272 inline std::ostream& operator << (std::ostream& rOStream,
274 {
275  rThis.PrintInfo(rOStream);
276  rOStream << std::endl;
277  rThis.PrintData(rOStream);
278 
279  return rOStream;
280 }
281 
283 
284 
285 } // namespace Kratos.
286 
287 #endif // KRATOS_TABLE_KEY_VARIABLES_H_INCLUDED defined
The serialization consists in storing the state of an object into a storage format like data file or ...
Definition: serializer.h:123
void load(std::string const &rTag, TDataType &rObject)
Definition: serializer.h:207
void save(std::string const &rTag, std::array< TDataType, TDataSize > const &rObject)
Definition: serializer.h:545
TableKeyVariables.
Definition: table_key_variables.hpp:50
std::string Info() const
Turn back information as a string.
Definition: table_key_variables.hpp:137
void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: table_key_variables.hpp:143
TableKeyVariables::Pointer Clone() const
Clone.
Definition: table_key_variables.hpp:84
TableKeyVariables()
Default constructor.
Definition: table_key_variables.hpp:75
std::vector< TableVariablesType > TableVariablesContainerType
Definition: table_key_variables.hpp:68
Variable< TResultType > YVariableType
Definition: table_key_variables.hpp:64
TableKeyVariables(const TableKeyVariables &rOther)
Copy constructor.
Definition: table_key_variables.hpp:78
void RegisterTable(const XVariableType &rXVariable, const YVariableType &rYVariable)
Definition: table_key_variables.hpp:100
~TableKeyVariables()
Destructor.
Definition: table_key_variables.hpp:90
KRATOS_CLASS_POINTER_DEFINITION(TableKeyVariables)
Pointer definition of TableKeyVariables.
const YVariableType & GetYVariable(int64_t rTableKey) const
Definition: table_key_variables.hpp:115
const XVariableType & GetXVariable(int64_t rTableKey) const
Definition: table_key_variables.hpp:106
void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: table_key_variables.hpp:149
std::pair< const XVariableType *, const YVariableType * > TableVariablesType
Definition: table_key_variables.hpp:66
Variable< TArgumentType > XVariableType
Definition: table_key_variables.hpp:62
KeyType Key() const
Definition: variable_data.h:187
Variable class contains all information needed to store and retrive data from a data container.
Definition: variable.h:63
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
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
def load(f)
Definition: ode_solve.py:307
integer i
Definition: TensorModule.f:17