16 #if !defined(KRATOS_VARIABLE_H_INCLUDED )
17 #define KRATOS_VARIABLE_H_INCLUDED
61 template<
class TDataType>
91 const std::string& NewName,
92 const TDataType
Zero = TDataType(),
97 mpTimeDerivativeVariable(pTimeDerivativeVariable)
99 RegisterThisVariable();
107 const std::string& NewName,
112 mpTimeDerivativeVariable(pTimeDerivativeVariable)
114 RegisterThisVariable();
122 template<
typename TSourceVariableType>
124 const std::string& rNewName,
125 TSourceVariableType* pSourceVariable,
127 const TDataType
Zero = TDataType()
129 :
VariableData(rNewName, sizeof(TDataType), pSourceVariable, ComponentIndex),
132 RegisterThisVariable();
141 template<
typename TSourceVariableType>
143 const std::string& rNewName,
144 TSourceVariableType* pSourceVariable,
147 const TDataType
Zero = TDataType()
149 :
VariableData(rNewName, sizeof(TDataType), pSourceVariable, ComponentIndex),
151 mpTimeDerivativeVariable(pTimeDerivativeVariable)
153 RegisterThisVariable();
163 mZero(rOtherVariable.mZero),
164 mpTimeDerivativeVariable(rOtherVariable.mpTimeDerivativeVariable)
191 void*
Clone(
const void* pSource)
const override
193 return new TDataType(*
static_cast<const TDataType*
>(pSource) );
203 void*
Copy(
const void* pSource,
void* pDestination)
const override
205 return new(pDestination) TDataType(*
static_cast<const TDataType*
>(pSource) );
214 void Assign(
const void* pSource,
void* pDestination)
const override
216 (*
static_cast<TDataType*
>(pDestination) ) = (*
static_cast<const TDataType*
>(pSource) );
227 new (pDestination) TDataType(mZero);
235 void Delete(
void* pSource)
const override
237 delete static_cast<TDataType*
>(pSource);
248 static_cast<TDataType*
>(pSource)->~TDataType();
257 void Print(
const void* pSource, std::ostream& rOStream)
const override
260 rOStream <<
Name() <<
" component of " <<
GetSourceVariable().
Name() <<
" variable : " << *
static_cast<const TDataType*
>(pSource) ;
263 rOStream <<
Name() <<
" : " << *
static_cast<const TDataType*
>(pSource) ;
273 void PrintData(
const void* pSource, std::ostream& rOStream)
const override
275 rOStream << *static_cast<const TDataType* >(pSource) ;
286 rSerializer.
save(
"Data",*
static_cast<TDataType*
>(pData));
295 *pData =
new TDataType;
305 rSerializer.
load(
"Data",*
static_cast<TDataType*
>(pData));
315 return static_object;
323 const TDataType&
GetValue(
const void* pSource)
const
338 KRATOS_DEBUG_ERROR_IF(mpTimeDerivativeVariable ==
nullptr) <<
"Time derivative for Variable \"" <<
Name() <<
"\" was not assigned" << std::endl;
339 return *mpTimeDerivativeVariable;
351 const void*
pZero()
const override {
367 std::string
Info()
const override
369 std::stringstream buffer;
370 buffer <<
Name() <<
" variable" <<
" #" <<
static_cast<unsigned int>(
Key());
375 buffer <<
Name() <<
" variable #" <<
static_cast<unsigned int>(
Key());
462 template<
typename TValueType>
463 TDataType& GetValueByIndex(TValueType* pValue, std::size_t index)
const
465 return *
static_cast<TDataType*
>(pValue + index);
468 template<
typename TValueType>
469 const TDataType& GetValueByIndex(
const TValueType* pValue, std::size_t index)
const
471 return *
static_cast<const TDataType*
>(pValue + index);
474 void RegisterThisVariable(){
475 std::string variable_path =
"variables.all." +
Name();
477 Registry::AddItem<VariableType>(variable_path, *
this);
491 void save(
Serializer& rSerializer)
const override
494 rSerializer.
save(
"Zero",mZero);
495 rSerializer.
save(
"TimeDerivativeVariable",mpTimeDerivativeVariable);
505 rSerializer.
load(
"Zero",mZero);
506 rSerializer.
load(
"TimeDerivativeVariable",mpTimeDerivativeVariable);
543 template<
class TDataType>
548 template<
class TDataType>
static bool HasItem(std::string const &rItemFullName)
Definition: registry.cpp:88
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
This class is the base of variables and variable's components which contains their common data.
Definition: variable_data.h:49
virtual void PrintData(const void *pSource, std::ostream &rOStream) const
Definition: variable_data.cpp:80
KeyType GetComponentIndex() const
Returns the component index.
Definition: variable_data.h:227
const VariableData & GetSourceVariable() const
Definition: variable_data.h:232
bool IsComponent() const
Definition: variable_data.h:211
const std::string & Name() const
Definition: variable_data.h:201
KeyType Key() const
Definition: variable_data.h:187
std::size_t KeyType
Definition: variable_data.h:57
Variable class contains all information needed to store and retrive data from a data container.
Definition: variable.h:63
void Allocate(void **pData) const override
This method allocates the data of the variable.
Definition: variable.h:293
void Assign(const void *pSource, void *pDestination) const override
Assign is very similar to Copy. It just differs in using an assignment operator besides the copy cons...
Definition: variable.h:214
Variable(const std::string &rNewName, TSourceVariableType *pSourceVariable, char ComponentIndex, const VariableType *pTimeDerivativeVariable, const TDataType Zero=TDataType())
Constructor for creating a component of other variable.
Definition: variable.h:142
void Load(Serializer &rSerializer, void *pData) const override
The load operation which restores the data of the class.
Definition: variable.h:303
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: variable.h:390
TDataType & GetValue(void *pSource) const
Definition: variable.h:318
KRATOS_CLASS_POINTER_DEFINITION(Variable)
Pointer definition of Variable.
void Save(Serializer &rSerializer, void *pData) const override
The save operation which backups the data of the class.
Definition: variable.h:283
static const VariableType & StaticObject()
This method returns the variable type.
Definition: variable.h:312
VariableType & operator=(const VariableType &rOtherVariable)=delete
Assignment operator, deleted to avoid misuse which can lead to memory problems.
Variable(const std::string &NewName, const VariableType *pTimeDerivativeVariable)
Constructor with specific name and zero value.
Definition: variable.h:106
const void * pZero() const override
Definition: variable.h:351
const TDataType & Zero() const
This method returns the zero value of the variable type.
Definition: variable.h:346
void Delete(void *pSource) const override
Delete removes an object of variable type from memory.
Definition: variable.h:235
void PrintData(const void *pSource, std::ostream &rOStream) const override
PrintData is an auxiliary method to produce output only the value of given variable knowing its addre...
Definition: variable.h:273
std::string Info() const override
Definition: variable.h:367
void * Copy(const void *pSource, void *pDestination) const override
Copy is very similar to Clone except that it also the destination pointer also passed to it.
Definition: variable.h:203
const TDataType & GetValue(const void *pSource) const
Definition: variable.h:323
const VariableType & GetTimeDerivative() const
This method returns the time derivative variable.
Definition: variable.h:336
Variable(const std::string &NewName, const TDataType Zero=TDataType(), const VariableType *pTimeDerivativeVariable=nullptr)
Constructor with specific name and zero value.
Definition: variable.h:90
VariableData::KeyType KeyType
Definition: variable.h:75
void Print(const void *pSource, std::ostream &rOStream) const override
Print is an auxiliary method to produce output of given variable knowing its address.
Definition: variable.h:257
Variable(const VariableType &rOtherVariable)
Copy constructor.
Definition: variable.h:161
void * Clone(const void *pSource) const override
Clone creates a copy of the object using a copy constructor of the class.
Definition: variable.h:191
void Destruct(void *pSource) const override
Destruct eliminates an object maintaining the memory it is using.
Definition: variable.h:246
void PrintInfo(std::ostream &rOStream) const override
Definition: variable.h:384
Variable< TDataType > VariableType
Definition: variable.h:78
void AssignZero(void *pDestination) const override
AssignZero is a special case of Assign for which variable zero value used as source.
Definition: variable.h:224
~Variable() override
Destructor.
Definition: variable.h:170
TDataType Type
type of this variable
Definition: variable.h:72
Variable(const std::string &rNewName, TSourceVariableType *pSourceVariable, char ComponentIndex, const TDataType Zero=TDataType())
Constructor for creating a component of other variable.
Definition: variable.h:123
#define KRATOS_SERIALIZE_SAVE_BASE_CLASS(Serializer, BaseType)
Definition: define.h:812
#define KRATOS_SERIALIZE_LOAD_BASE_CLASS(Serializer, BaseType)
Definition: define.h:815
#define KRATOS_DEBUG_ERROR_IF(conditional)
Definition: exception.h:171
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