-
Notifications
You must be signed in to change notification settings - Fork 247
/
master_slave_constraint.h
657 lines (556 loc) · 19 KB
/
master_slave_constraint.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
// | / |
// ' / __| _` | __| _ \ __|
// . \ | ( | | ( |\__ `
// _|\_\_| \__,_|\__|\___/ ____/
// Multi-Physics
//
// License: BSD License
// Kratos default license: kratos/license.txt
//
// Main authors: Aditya Ghantasala
// Collaborators: Vicente Mataix
//
#pragma once
// System includes
// project includes
#include "includes/define.h"
#include "includes/node.h"
#include "containers/flags.h"
#include "containers/variable.h"
#include "includes/process_info.h"
#include "includes/indexed_object.h"
namespace Kratos
{
///@name Kratos Globals
///@{
///@}
///@name Type Definitions
///@{
///@}
///@name Enum's
///@{
///@}
///@name Functions
///@{
///@}
///@name Kratos Classes
///@{
/**
* @class MasterSlaveConstraint
* @ingroup KratosCore
* @brief A class that implements the interface for different master-slave constraints to be applied on a system.
* @details This is the part that is seen by the user from the python level. Objects of this class are
* first class citizens of the modelpart.
*
* This class allows to add a master-slave constraint which is of the form
*
* SlaveDofVector = T * MasterDofVector + rConstantVector. (Processing of this is currently not implemented.)
*
* or
*
* SlaveDof = weight * MasterDof + Constant
*
* This class's object will provide its slave, master details and relation matrix between them.
*
* One can add two MasterSlaveConstraint objects with same slave but different masters and weights.
* Consider user adds : SlaveDof = weight1 * MasterDof1 + Constant1
* and : SlaveDof = weight2 * MasterDof2 + Constant2
*
* These are later consolidated in the builder and solver to make
* : SlaveDof = weight1 * MasterDof1 + weight2 * MasterDof2 + Constant1+Constant2
* and then converted to :
* : SlaveEqID = weight1 * MasterEqId1 + weight2 * MasterEqId2 + Constant1+Constant2
* This unique equation is used later on to modify the equation system.
* @author Aditya Ghantasala
*/
class KRATOS_API(KRATOS_CORE) MasterSlaveConstraint
: public IndexedObject, public Flags
{
public:
///@name Type Definitions
///@{
/// The definition of the base class
typedef IndexedObject BaseType;
/// The index type definition
typedef std::size_t IndexType;
/// The DoF type definition
typedef Dof<double> DofType;
/// The DoF pointer vector type definition
typedef std::vector< DofType::Pointer > DofPointerVectorType;
/// The node type definition
typedef Node NodeType;
/// The equation Id vector type definition
typedef std::vector<std::size_t> EquationIdVectorType;
/// The matrix type definition
typedef Matrix MatrixType;
/// The vector type definition
typedef Vector VectorType;
/// The variable type definition (double)
typedef Kratos::Variable<double> VariableType;
/// Pointer definition of MasterSlaveConstraint
KRATOS_CLASS_POINTER_DEFINITION(MasterSlaveConstraint);
///@}
///@name Enum's
///@{
///@}
///@name Life Cycle
///@{
/**
* @brief The default constructor
* @param IndexType The Id of the new created constraint
*/
explicit MasterSlaveConstraint(IndexType Id = 0) : IndexedObject(Id), Flags()
{
}
/// Destructor.
virtual ~MasterSlaveConstraint() override
{
}
/// Copy Constructor
MasterSlaveConstraint(const MasterSlaveConstraint& rOther)
: BaseType(rOther),
mData(rOther.mData)
{
}
/// Assignment operator
MasterSlaveConstraint& operator=(const MasterSlaveConstraint& rOther)
{
BaseType::operator=( rOther );
mData = rOther.mData;
return *this;
}
///@}
///@name Operators
///@{
///@}
///@name Operations
///@{
/**
* @brief Creates a new constraint pointer
* @param Id the ID of the new constraint
* @param rMasterDofsVector the vector of master degree of freedoms.
* @param rSlaveDofsVector the vector of slave degree of freedoms.
* @param rRelationMatrix The matrix of weights relating the master DOFs and Slave DOFs
* @param rConstantVector The vector of the constants, one entry for each of the slave.
* @return A Pointer to the new constraint
*/
virtual MasterSlaveConstraint::Pointer Create(
IndexType Id,
DofPointerVectorType& rMasterDofsVector,
DofPointerVectorType& rSlaveDofsVector,
const MatrixType& rRelationMatrix,
const VectorType& rConstantVector
) const
{
KRATOS_TRY
KRATOS_ERROR << "Create not implemented in MasterSlaveConstraintBaseClass" << std::endl;
KRATOS_CATCH("");
}
/**
* creates a new constraint pointer
* @param Id the ID of the new constraint
* @param rMasterNode Node which is the master of for this constraint.
* @param rMasterVariable the scalar variable which is on the master node. (DOF)
* @param rSlaveNode Node which is the slave of for this constraint.
* @param rSlaveVariable the scalar variable which is on the slave node. (DOF)
* @param Weight The weight with which the master and slave are related s = w*m + c
* @param Constant The constant in the master slave relation
* @return A Pointer to the new constraint
*/
virtual MasterSlaveConstraint::Pointer Create(
IndexType Id,
NodeType& rMasterNode,
const VariableType& rMasterVariable,
NodeType& rSlaveNode,
const VariableType& rSlaveVariable,
const double Weight,
const double Constant
) const
{
KRATOS_TRY
KRATOS_ERROR << "Create not implemented in MasterSlaveConstraintBaseClass" << std::endl;
KRATOS_CATCH("");
}
/**
* @brief It creates a new constraint pointer and clones the previous constraint data
* @param NewId the ID of the new constraint
* @return a Pointer to the new constraint
*/
virtual Pointer Clone (IndexType NewId) const
{
KRATOS_TRY
KRATOS_WARNING("MasterSlaveConstraint") << " Call base class constraint Clone " << std::endl;
MasterSlaveConstraint::Pointer p_new_const = Kratos::make_shared<MasterSlaveConstraint>(*this);
p_new_const->SetId(NewId);
p_new_const->SetData(this->GetData());
p_new_const->Set(Flags(*this));
return p_new_const;
KRATOS_CATCH("");
}
/**
* @brief Clears the maps contents
*/
virtual void Clear()
{
}
/**
* @brief It is called to initialize the constraint
* @details If the constraint needs to perform any operation before any calculation is done
* @param rCurrentProcessInfo The current process info instance
*/
virtual void Initialize(const ProcessInfo& rCurrentProcessInfo)
{
}
/**
* @brief It is called to finalize the constraint
* @details If the constraint needs to perform any operation before any calculation is done
* @param rCurrentProcessInfo The current process info instance
*/
virtual void Finalize(const ProcessInfo& rCurrentProcessInfo)
{
this->Clear();
}
/**
* @brief This is called in the beginning of each solution step
* @param rCurrentProcessInfo The current process info instance
*/
virtual void InitializeSolutionStep(const ProcessInfo& rCurrentProcessInfo)
{
}
/**
* @brief This is called for non-linear analysis at the beginning of the iteration process
* @param rCurrentProcessInfo The current process info instance
*/
virtual void InitializeNonLinearIteration(const ProcessInfo& rCurrentProcessInfo)
{
}
/**
* @brief This is called for non-linear analysis at the end of the iteration process
* @param rCurrentProcessInfo The current process info instance
*/
virtual void FinalizeNonLinearIteration(const ProcessInfo& rCurrentProcessInfo)
{
}
/**
* @brief This is called at the end of each solution step
*/
virtual void FinalizeSolutionStep(const ProcessInfo& rCurrentProcessInfo)
{
}
/**
* @brief Determines the constrant's slave and master list of DOFs
* @param rSlaveDofsVector The list of slave DOFs
* @param rMasterDofsVector The list of slave DOFs
* @param rCurrentProcessInfo The current process info instance
*/
virtual void GetDofList(
DofPointerVectorType& rSlaveDofsVector,
DofPointerVectorType& rMasterDofsVector,
const ProcessInfo& rCurrentProcessInfo
) const
{
KRATOS_ERROR << "GetDofList not implemented in MasterSlaveConstraintBaseClass" << std::endl;
}
/**
* @brief Determines the constrant's slave and master list of DOFs
* @param rSlaveDofsVector The list of slave DOFs
* @param rMasterDofsVector The list of slave DOFs
* @param rCurrentProcessInfo The current process info instance
*/
virtual void SetDofList(
const DofPointerVectorType& rSlaveDofsVector,
const DofPointerVectorType& rMasterDofsVector,
const ProcessInfo& rCurrentProcessInfo
)
{
KRATOS_ERROR << "SetDofList not implemented in MasterSlaveConstraintBaseClass" << std::endl;
}
/**
* @brief This determines the master equation IDs connected to this constraint
* @param rSlaveEquationIds The vector of slave equation ids.
* @param rMasterEquationIds The vector of master equation ids.
* @param rCurrentProcessInfo The current process info instance
*/
virtual void EquationIdVector(
EquationIdVectorType& rSlaveEquationIds,
EquationIdVectorType& rMasterEquationIds,
const ProcessInfo& rCurrentProcessInfo
) const
{
if (rSlaveEquationIds.size() != 0)
rSlaveEquationIds.resize(0);
if (rMasterEquationIds.size() != 0)
rMasterEquationIds.resize(0);
}
/**
* @brief This method returns the slave dof vector
* @return The vector containing the slave dofs
*/
virtual const DofPointerVectorType& GetSlaveDofsVector() const
{
KRATOS_ERROR << "GetSlaveDofsVector not implemented in MasterSlaveConstraintBaseClass" << std::endl;
}
/**
* @brief This method returns the slave dof vector
* @return The vector containing the slave dofs
*/
virtual void SetSlaveDofsVector(const DofPointerVectorType& rSlaveDofsVector)
{
KRATOS_ERROR << "SetSlaveDofsVector not implemented in MasterSlaveConstraintBaseClass" << std::endl;
}
/**
* @brief This method returns the slave dof vector
* @return The vector containing the slave dofs
*/
virtual const DofPointerVectorType& GetMasterDofsVector() const
{
KRATOS_ERROR << "GetMasterDofsVector not implemented in MasterSlaveConstraintBaseClass" << std::endl;
}
/**
* @brief This method returns the slave dof vector
* @return The vector containing the slave dofs
*/
virtual void SetMasterDofsVector(const DofPointerVectorType& rMasterDofsVector)
{
KRATOS_ERROR << "SetMasterDofsVector not implemented in MasterSlaveConstraintBaseClass" << std::endl;
}
/**
* @brief This method resets the values of the slave dofs
* @param rCurrentProcessInfo the current process info instance
*/
virtual void ResetSlaveDofs(const ProcessInfo& rCurrentProcessInfo)
{
KRATOS_ERROR << "ResetSlaveDofs not implemented in MasterSlaveConstraintBaseClass" << std::endl;
}
/**
* @brief This method directly applies the master/slave relationship
* @param rCurrentProcessInfo the current process info instance
*/
virtual void Apply(const ProcessInfo& rCurrentProcessInfo)
{
KRATOS_ERROR << "Apply not implemented in MasterSlaveConstraintBaseClass" << std::endl;
}
/**
* @brief This method allows to set the Local System in case is not computed on running time (internal variable)
* @param rRelationMatrix the matrix which relates the master and slave degree of freedom
* @param rConstant The constant vector (one entry for each slave)
* @param rCurrentProcessInfo The current process info instance
*/
virtual void SetLocalSystem(
const MatrixType& rRelationMatrix,
const VectorType& rConstantVector,
const ProcessInfo& rCurrentProcessInfo
)
{
KRATOS_TRY
KRATOS_ERROR << "SetLocalSystem not implemented in MasterSlaveConstraintBaseClass" << std::endl;
KRATOS_CATCH("");
}
/**
* @brief This method allows to get the Local System in case is not computed on running time (internal variable)
* @param rRelationMatrix the matrix which relates the master and slave degree of freedom
* @param rConstant The constant vector (one entry for each slave)
* @param rCurrentProcessInfo The current process info instance
*/
virtual void GetLocalSystem(
MatrixType& rRelationMatrix,
VectorType& rConstantVector,
const ProcessInfo& rCurrentProcessInfo
) const
{
KRATOS_TRY
this->CalculateLocalSystem(rRelationMatrix, rConstantVector, rCurrentProcessInfo);
KRATOS_CATCH("");
}
/**
* @brief This is called during the assembling process in order
* @details To calculate the relation between the master and slave.
* @param rRelationMatrix the matrix which relates the master and slave degree of freedom
* @param rConstant The constant vector (one entry for each slave)
* @param rCurrentProcessInfo the current process info instance
*/
virtual void CalculateLocalSystem(
MatrixType& rRelationMatrix,
VectorType& rConstantVector,
const ProcessInfo& rCurrentProcessInfo
) const
{
if (rRelationMatrix.size1() != 0) {
rRelationMatrix.resize(0, 0, false);
}
if (rConstantVector.size() != 0) {
rConstantVector.resize(0, false);
}
}
/**
* @brief This method provides the place to perform checks on the completeness of the input
* and the compatibility with the problem options
* @details It is designed to be called only once (or anyway, not often) typically at the beginning
* of the calculations, so to verify that nothing is missing from the input or that no common error is found.
* @param rCurrentProcessInfo
* @note This method is: MANDATORY
*/
virtual int Check(const ProcessInfo& rCurrentProcessInfo) const
{
KRATOS_TRY
KRATOS_ERROR_IF( this->Id() < 1 ) << "MasterSlaveConstraint found with Id " << this->Id() << std::endl;
return 0;
KRATOS_CATCH("")
}
///@}
///@name Input and output
///@{
/**
* @brief Returns the string containing a detailed description of this object.
* @return the string with information
*/
virtual std::string GetInfo() const
{
return " Constraint base class !";
}
/**
* @brief This method prints the current Constraint Id
* @param rOStream The buffer where the information is given
*/
virtual void PrintInfo(std::ostream &rOStream) const override
{
rOStream << " MasterSlaveConstraint Id : " << this->Id() << std::endl;
}
///@}
///@name Access
///@{
/**
* @brief This method returns the data container of the constraint
* @return The data container mData
*/
DataValueContainer& Data()
{
return mData;
}
/**
* @brief This method returns the data container of the constraint (constant)
* @return The data container mData
*/
DataValueContainer const& GetData() const
{
return mData;
}
/**
* @brief This method sets the data container of the constraint
* @param rThisData The data container to set on mData
*/
void SetData(DataValueContainer const& rThisData)
{
mData = rThisData;
}
/**
* @brief Check if the Data exists with Has(..) methods:
* @param rThisVariable The variable to be check
*/
template<class TDataType>
bool Has(const Variable<TDataType>& rThisVariable) const
{
return mData.Has(rThisVariable);
}
/**
* @brief Set Data with SetValue and the Variable to set
* @param rThisVariable The variable to be set
* @param rValue The value to be set
*/
template<class TVariableType>
void SetValue(
const TVariableType& rThisVariable,
typename TVariableType::Type const& rValue
)
{
mData.SetValue(rThisVariable, rValue);
}
/**
* @brief Get Data with GetValue and the Variable to get
* @param rThisVariable The variable to get
*/
template<class TVariableType>
typename TVariableType::Type& GetValue(const TVariableType& rThisVariable)
{
return mData.GetValue(rThisVariable);
}
/**
* @brief Get Data with GetValue and the Variable to get
* @param rThisVariable The variable to get
*/
template<class TVariableType>
typename TVariableType::Type& GetValue(const TVariableType& rThisVariable) const
{
return mData.GetValue(rThisVariable);
}
///@}
///@name Inquiry
///@{
/**
* @brief Checks if the GeometricalObject is active
* @return True by default, otherwise depending on the ACTIVE flag
*/
bool IsActive() const;
///@}
protected:
///@name Protected static Member Variables
///@{
///@}
///@name Protected member Variables
///@{
///@}
///@name Protected Operators
///@{
///@}
///@name Protected Operations
///@{
///@}
///@name Protected Access
///@{
///@}
///@name Protected Inquiry
///@{
///@}
///@name Protected LifeCycle
///@{
///@}
private:
///@name Static Member Variables
///@{
///@}
///@name Member Variables
///@{
DataValueContainer mData; /// Pointer to the data related to this constraint
///@}
///@name Serialization
///@{
friend class Serializer;
virtual void save(Serializer &rSerializer) const override
{
KRATOS_SERIALIZE_SAVE_BASE_CLASS(rSerializer, IndexedObject);
KRATOS_SERIALIZE_SAVE_BASE_CLASS(rSerializer, Flags);
rSerializer.save("Data", mData);
}
virtual void load(Serializer &rSerializer) override
{
KRATOS_SERIALIZE_LOAD_BASE_CLASS(rSerializer, IndexedObject);
KRATOS_SERIALIZE_LOAD_BASE_CLASS(rSerializer, Flags);
rSerializer.load("Data", mData);
}
};
KRATOS_API_EXTERN template class KRATOS_API(KRATOS_CORE) KratosComponents<MasterSlaveConstraint>;
///@name Input/Output functions
///@{
/// input stream function
inline std::istream& operator >> (std::istream& rIStream,
MasterSlaveConstraint& rThis);
/// output stream function
inline std::ostream& operator << (std::ostream& rOStream,
const MasterSlaveConstraint& rThis)
{
rThis.PrintInfo(rOStream);
rOStream << std::endl;
return rOStream;
}
///@}
} // namespace Kratos