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.
master_slave_constraint.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: Aditya Ghantasala
11 // Collaborators: Vicente Mataix
12 //
13 
14 #pragma once
15 
16 // System includes
17 
18 // project includes
19 #include "includes/define.h"
20 #include "includes/node.h"
21 #include "containers/flags.h"
22 #include "containers/variable.h"
23 #include "includes/process_info.h"
25 
26 namespace Kratos
27 {
30 
34 
38 
42 
46 
74 class KRATOS_API(KRATOS_CORE) MasterSlaveConstraint
75  : public IndexedObject, public Flags
76 {
77 public:
80 
83 
85  typedef std::size_t IndexType;
86 
89 
91  typedef std::vector< DofType::Pointer > DofPointerVectorType;
92 
94  typedef Node NodeType;
95 
97  typedef std::vector<std::size_t> EquationIdVectorType;
98 
101 
104 
107 
110 
114 
118 
124  {
125  }
126 
128  virtual ~MasterSlaveConstraint() override
129  {
130 
131  }
132 
135  : BaseType(rOther),
136  mData(rOther.mData)
137  {
138  }
139 
142  {
143  BaseType::operator=( rOther );
144  mData = rOther.mData;
145  return *this;
146  }
147 
151 
155 
165  virtual MasterSlaveConstraint::Pointer Create(
166  IndexType Id,
167  DofPointerVectorType& rMasterDofsVector,
168  DofPointerVectorType& rSlaveDofsVector,
169  const MatrixType& rRelationMatrix,
170  const VectorType& rConstantVector
171  ) const
172  {
173  KRATOS_TRY
174 
175  KRATOS_ERROR << "Create not implemented in MasterSlaveConstraintBaseClass" << std::endl;
176 
177  KRATOS_CATCH("");
178  }
179 
191  virtual MasterSlaveConstraint::Pointer Create(
192  IndexType Id,
193  NodeType& rMasterNode,
194  const VariableType& rMasterVariable,
195  NodeType& rSlaveNode,
196  const VariableType& rSlaveVariable,
197  const double Weight,
198  const double Constant
199  ) const
200  {
201  KRATOS_TRY
202 
203  KRATOS_ERROR << "Create not implemented in MasterSlaveConstraintBaseClass" << std::endl;
204 
205  KRATOS_CATCH("");
206  }
207 
213  virtual Pointer Clone (IndexType NewId) const
214  {
215  KRATOS_TRY
216 
217  KRATOS_WARNING("MasterSlaveConstraint") << " Call base class constraint Clone " << std::endl;
218  MasterSlaveConstraint::Pointer p_new_const = Kratos::make_shared<MasterSlaveConstraint>(*this);
219  p_new_const->SetId(NewId);
220  p_new_const->SetData(this->GetData());
221  p_new_const->Set(Flags(*this));
222  return p_new_const;
223 
224  KRATOS_CATCH("");
225  }
226 
230  virtual void Clear()
231  {
232  }
233 
239  virtual void Initialize(const ProcessInfo& rCurrentProcessInfo)
240  {
241  }
242 
248  virtual void Finalize(const ProcessInfo& rCurrentProcessInfo)
249  {
250  this->Clear();
251  }
252 
257  virtual void InitializeSolutionStep(const ProcessInfo& rCurrentProcessInfo)
258  {
259  }
260 
265  virtual void InitializeNonLinearIteration(const ProcessInfo& rCurrentProcessInfo)
266  {
267  }
268 
273  virtual void FinalizeNonLinearIteration(const ProcessInfo& rCurrentProcessInfo)
274  {
275  }
276 
280  virtual void FinalizeSolutionStep(const ProcessInfo& rCurrentProcessInfo)
281  {
282  }
283 
290  virtual void GetDofList(
291  DofPointerVectorType& rSlaveDofsVector,
292  DofPointerVectorType& rMasterDofsVector,
293  const ProcessInfo& rCurrentProcessInfo
294  ) const
295  {
296  KRATOS_ERROR << "GetDofList not implemented in MasterSlaveConstraintBaseClass" << std::endl;
297  }
298 
305  virtual void SetDofList(
306  const DofPointerVectorType& rSlaveDofsVector,
307  const DofPointerVectorType& rMasterDofsVector,
308  const ProcessInfo& rCurrentProcessInfo
309  )
310  {
311  KRATOS_ERROR << "SetDofList not implemented in MasterSlaveConstraintBaseClass" << std::endl;
312  }
313 
320  virtual void EquationIdVector(
321  EquationIdVectorType& rSlaveEquationIds,
322  EquationIdVectorType& rMasterEquationIds,
323  const ProcessInfo& rCurrentProcessInfo
324  ) const
325  {
326  if (rSlaveEquationIds.size() != 0)
327  rSlaveEquationIds.resize(0);
328 
329  if (rMasterEquationIds.size() != 0)
330  rMasterEquationIds.resize(0);
331  }
332 
338  {
339  KRATOS_ERROR << "GetSlaveDofsVector not implemented in MasterSlaveConstraintBaseClass" << std::endl;
340  }
341 
346  virtual void SetSlaveDofsVector(const DofPointerVectorType& rSlaveDofsVector)
347  {
348  KRATOS_ERROR << "SetSlaveDofsVector not implemented in MasterSlaveConstraintBaseClass" << std::endl;
349  }
350 
356  {
357  KRATOS_ERROR << "GetMasterDofsVector not implemented in MasterSlaveConstraintBaseClass" << std::endl;
358  }
359 
364  virtual void SetMasterDofsVector(const DofPointerVectorType& rMasterDofsVector)
365  {
366  KRATOS_ERROR << "SetMasterDofsVector not implemented in MasterSlaveConstraintBaseClass" << std::endl;
367  }
368 
373  virtual void ResetSlaveDofs(const ProcessInfo& rCurrentProcessInfo)
374  {
375  KRATOS_ERROR << "ResetSlaveDofs not implemented in MasterSlaveConstraintBaseClass" << std::endl;
376  }
377 
382  virtual void Apply(const ProcessInfo& rCurrentProcessInfo)
383  {
384  KRATOS_ERROR << "Apply not implemented in MasterSlaveConstraintBaseClass" << std::endl;
385  }
386 
393  virtual void SetLocalSystem(
394  const MatrixType& rRelationMatrix,
395  const VectorType& rConstantVector,
396  const ProcessInfo& rCurrentProcessInfo
397  )
398  {
399  KRATOS_TRY
400 
401  KRATOS_ERROR << "SetLocalSystem not implemented in MasterSlaveConstraintBaseClass" << std::endl;
402 
403  KRATOS_CATCH("");
404  }
405 
412  virtual void GetLocalSystem(
413  MatrixType& rRelationMatrix,
414  VectorType& rConstantVector,
415  const ProcessInfo& rCurrentProcessInfo
416  ) const
417  {
418  KRATOS_TRY
419 
420  this->CalculateLocalSystem(rRelationMatrix, rConstantVector, rCurrentProcessInfo);
421 
422  KRATOS_CATCH("");
423  }
424 
432  virtual void CalculateLocalSystem(
433  MatrixType& rRelationMatrix,
434  VectorType& rConstantVector,
435  const ProcessInfo& rCurrentProcessInfo
436  ) const
437  {
438  if (rRelationMatrix.size1() != 0) {
439  rRelationMatrix.resize(0, 0, false);
440  }
441 
442  if (rConstantVector.size() != 0) {
443  rConstantVector.resize(0, false);
444  }
445  }
446 
455  virtual int Check(const ProcessInfo& rCurrentProcessInfo) const
456  {
457  KRATOS_TRY
458 
459  KRATOS_ERROR_IF( this->Id() < 1 ) << "MasterSlaveConstraint found with Id " << this->Id() << std::endl;
460 
461  return 0;
462 
463  KRATOS_CATCH("")
464  }
465 
469 
474  virtual std::string GetInfo() const
475  {
476  return " Constraint base class !";
477  }
478 
483  virtual void PrintInfo(std::ostream &rOStream) const override
484  {
485  rOStream << " MasterSlaveConstraint Id : " << this->Id() << std::endl;
486  }
487 
491 
497  {
498  return mData;
499  }
500 
506  {
507  return mData;
508  }
509 
514  void SetData(DataValueContainer const& rThisData)
515  {
516  mData = rThisData;
517  }
518 
523  template<class TDataType>
524  bool Has(const Variable<TDataType>& rThisVariable) const
525  {
526  return mData.Has(rThisVariable);
527  }
528 
534  template<class TVariableType>
535  void SetValue(
536  const TVariableType& rThisVariable,
537  typename TVariableType::Type const& rValue
538  )
539  {
540  mData.SetValue(rThisVariable, rValue);
541  }
542 
547  template<class TVariableType>
548  typename TVariableType::Type& GetValue(const TVariableType& rThisVariable)
549  {
550  return mData.GetValue(rThisVariable);
551  }
552 
557  template<class TVariableType>
558  typename TVariableType::Type& GetValue(const TVariableType& rThisVariable) const
559  {
560  return mData.GetValue(rThisVariable);
561  }
562 
566 
571  bool IsActive() const;
572 
574 protected:
577 
581 
585 
589 
593 
597 
601 
603 
604 private:
607 
608 
612 
613  DataValueContainer mData;
614 
618 
619  friend class Serializer;
620 
621  virtual void save(Serializer &rSerializer) const override
622  {
625  rSerializer.save("Data", mData);
626  }
627 
628  virtual void load(Serializer &rSerializer) override
629  {
632  rSerializer.load("Data", mData);
633  }
634 };
635 
637 
640 
642 inline std::istream& operator >> (std::istream& rIStream,
643  MasterSlaveConstraint& rThis);
644 
646 inline std::ostream& operator << (std::ostream& rOStream,
647  const MasterSlaveConstraint& rThis)
648 {
649  rThis.PrintInfo(rOStream);
650  rOStream << std::endl;
651 
652  return rOStream;
653 }
654 
656 
657 } // namespace Kratos
PeriodicInterfaceProcess & operator=(const PeriodicInterfaceProcess &)=delete
Container for storing data values associated with variables.
Definition: data_value_container.h:63
Dof represents a degree of freedom (DoF).
Definition: dof.h:86
Definition: flags.h:58
std::size_t IndexType
Definition: flags.h:74
This object defines an indexed object.
Definition: indexed_object.h:54
void resize(std::size_t NewSize1, std::size_t NewSize2, bool preserve=0)
Definition: amatrix_interface.h:224
KratosComponents class encapsulates a lookup table for a family of classes in a generic way.
Definition: kratos_components.h:49
A class that implements the interface for different master-slave constraints to be applied on a syste...
Definition: master_slave_constraint.h:76
virtual void FinalizeSolutionStep(const ProcessInfo &rCurrentProcessInfo)
This is called at the end of each solution step.
Definition: master_slave_constraint.h:280
MasterSlaveConstraint(const MasterSlaveConstraint &rOther)
Copy Constructor.
Definition: master_slave_constraint.h:134
virtual std::string GetInfo() const
Returns the string containing a detailed description of this object.
Definition: master_slave_constraint.h:474
virtual const DofPointerVectorType & GetSlaveDofsVector() const
This method returns the slave dof vector.
Definition: master_slave_constraint.h:337
MasterSlaveConstraint(IndexType Id=0)
The default constructor.
Definition: master_slave_constraint.h:123
virtual void ResetSlaveDofs(const ProcessInfo &rCurrentProcessInfo)
This method resets the values of the slave dofs.
Definition: master_slave_constraint.h:373
virtual Pointer Clone(IndexType NewId) const
It creates a new constraint pointer and clones the previous constraint data.
Definition: master_slave_constraint.h:213
virtual int Check(const ProcessInfo &rCurrentProcessInfo) const
This method provides the place to perform checks on the completeness of the input and the compatibili...
Definition: master_slave_constraint.h:455
virtual void SetSlaveDofsVector(const DofPointerVectorType &rSlaveDofsVector)
This method returns the slave dof vector.
Definition: master_slave_constraint.h:346
virtual void GetDofList(DofPointerVectorType &rSlaveDofsVector, DofPointerVectorType &rMasterDofsVector, const ProcessInfo &rCurrentProcessInfo) const
Determines the constrant's slave and master list of DOFs.
Definition: master_slave_constraint.h:290
virtual void Apply(const ProcessInfo &rCurrentProcessInfo)
This method directly applies the master/slave relationship.
Definition: master_slave_constraint.h:382
Matrix MatrixType
The matrix type definition.
Definition: master_slave_constraint.h:100
virtual void GetLocalSystem(MatrixType &rRelationMatrix, VectorType &rConstantVector, const ProcessInfo &rCurrentProcessInfo) const
This method allows to get the Local System in case is not computed on running time (internal variable...
Definition: master_slave_constraint.h:412
virtual void CalculateLocalSystem(MatrixType &rRelationMatrix, VectorType &rConstantVector, const ProcessInfo &rCurrentProcessInfo) const
This is called during the assembling process in order.
Definition: master_slave_constraint.h:432
bool Has(const Variable< TDataType > &rThisVariable) const
Check if the Data exists with Has(..) methods:
Definition: master_slave_constraint.h:524
Vector VectorType
The vector type definition.
Definition: master_slave_constraint.h:103
TVariableType::Type & GetValue(const TVariableType &rThisVariable) const
Get Data with GetValue and the Variable to get.
Definition: master_slave_constraint.h:558
virtual MasterSlaveConstraint::Pointer Create(IndexType Id, NodeType &rMasterNode, const VariableType &rMasterVariable, NodeType &rSlaveNode, const VariableType &rSlaveVariable, const double Weight, const double Constant) const
Definition: master_slave_constraint.h:191
DataValueContainer const & GetData() const
This method returns the data container of the constraint (constant)
Definition: master_slave_constraint.h:505
virtual void Finalize(const ProcessInfo &rCurrentProcessInfo)
It is called to finalize the constraint.
Definition: master_slave_constraint.h:248
Node NodeType
The node type definition.
Definition: master_slave_constraint.h:94
virtual void SetDofList(const DofPointerVectorType &rSlaveDofsVector, const DofPointerVectorType &rMasterDofsVector, const ProcessInfo &rCurrentProcessInfo)
Determines the constrant's slave and master list of DOFs.
Definition: master_slave_constraint.h:305
Kratos::Variable< double > VariableType
The variable type definition (double)
Definition: master_slave_constraint.h:106
virtual void SetMasterDofsVector(const DofPointerVectorType &rMasterDofsVector)
This method returns the slave dof vector.
Definition: master_slave_constraint.h:364
MasterSlaveConstraint & operator=(const MasterSlaveConstraint &rOther)
Assignment operator.
Definition: master_slave_constraint.h:141
virtual void EquationIdVector(EquationIdVectorType &rSlaveEquationIds, EquationIdVectorType &rMasterEquationIds, const ProcessInfo &rCurrentProcessInfo) const
This determines the master equation IDs connected to this constraint.
Definition: master_slave_constraint.h:320
DataValueContainer & Data()
This method returns the data container of the constraint.
Definition: master_slave_constraint.h:496
virtual void Initialize(const ProcessInfo &rCurrentProcessInfo)
It is called to initialize the constraint.
Definition: master_slave_constraint.h:239
TVariableType::Type & GetValue(const TVariableType &rThisVariable)
Get Data with GetValue and the Variable to get.
Definition: master_slave_constraint.h:548
virtual void PrintInfo(std::ostream &rOStream) const override
This method prints the current Constraint Id.
Definition: master_slave_constraint.h:483
virtual ~MasterSlaveConstraint() override
Destructor.
Definition: master_slave_constraint.h:128
KRATOS_CLASS_POINTER_DEFINITION(MasterSlaveConstraint)
Pointer definition of MasterSlaveConstraint.
IndexedObject BaseType
The definition of the base class.
Definition: master_slave_constraint.h:82
void SetValue(const TVariableType &rThisVariable, typename TVariableType::Type const &rValue)
Set Data with SetValue and the Variable to set.
Definition: master_slave_constraint.h:535
Dof< double > DofType
The DoF type definition.
Definition: master_slave_constraint.h:88
virtual void InitializeNonLinearIteration(const ProcessInfo &rCurrentProcessInfo)
This is called for non-linear analysis at the beginning of the iteration process.
Definition: master_slave_constraint.h:265
virtual const DofPointerVectorType & GetMasterDofsVector() const
This method returns the slave dof vector.
Definition: master_slave_constraint.h:355
virtual void Clear()
Clears the maps contents.
Definition: master_slave_constraint.h:230
std::size_t IndexType
The index type definition.
Definition: master_slave_constraint.h:85
void SetData(DataValueContainer const &rThisData)
This method sets the data container of the constraint.
Definition: master_slave_constraint.h:514
std::vector< std::size_t > EquationIdVectorType
The equation Id vector type definition.
Definition: master_slave_constraint.h:97
virtual void FinalizeNonLinearIteration(const ProcessInfo &rCurrentProcessInfo)
This is called for non-linear analysis at the end of the iteration process.
Definition: master_slave_constraint.h:273
virtual void InitializeSolutionStep(const ProcessInfo &rCurrentProcessInfo)
This is called in the beginning of each solution step.
Definition: master_slave_constraint.h:257
virtual void SetLocalSystem(const MatrixType &rRelationMatrix, const VectorType &rConstantVector, const ProcessInfo &rCurrentProcessInfo)
This method allows to set the Local System in case is not computed on running time (internal variable...
Definition: master_slave_constraint.h:393
virtual MasterSlaveConstraint::Pointer Create(IndexType Id, DofPointerVectorType &rMasterDofsVector, DofPointerVectorType &rSlaveDofsVector, const MatrixType &rRelationMatrix, const VectorType &rConstantVector) const
Creates a new constraint pointer.
Definition: master_slave_constraint.h:165
std::vector< DofType::Pointer > DofPointerVectorType
The DoF pointer vector type definition.
Definition: master_slave_constraint.h:91
This class defines the node.
Definition: node.h:65
ProcessInfo holds the current value of different solution parameters.
Definition: process_info.h:59
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
#define KRATOS_SERIALIZE_SAVE_BASE_CLASS(Serializer, BaseType)
Definition: define.h:812
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
#define KRATOS_SERIALIZE_LOAD_BASE_CLASS(Serializer, BaseType)
Definition: define.h:815
#define KRATOS_ERROR
Definition: exception.h:161
#define KRATOS_ERROR_IF(conditional)
Definition: exception.h:162
#define KRATOS_WARNING(label)
Definition: logger.h:265
#define KRATOS_API_EXTERN
Definition: kratos_export_api.h:57
#define KRATOS_API(...)
Definition: kratos_export_api.h:40
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