18 #include <type_traits>
125 template <
class TVarType>
127 const TVarType &rVariable,
128 const TVarType &rDestinationVariable,
131 const unsigned int ReadBufferStep,
132 const unsigned int WriteBufferStep )
135 const int n_dest_nodes = rDestinationModelPart.
NumberOfNodes();
138 <<
"Origin and destination model parts have different number of nodes."
139 <<
"\n\t- Number of origin nodes: " << n_orig_nodes
140 <<
"\n\t- Number of destination nodes: " << n_dest_nodes << std::endl;
144 auto it_dest_node = rDestinationModelPart.
NodesBegin() + index;
145 const auto it_orig_node = rOriginModelPart.
NodesBegin() + index;
146 const auto &r_value = it_orig_node->GetSolutionStepValue(rVariable, ReadBufferStep);
147 it_dest_node->FastGetSolutionStepValue(rDestinationVariable, WriteBufferStep) = r_value; });
162 template <
class TVarType>
164 const TVarType &rVariable,
165 const TVarType &rDestinationVariable,
168 const unsigned int BuffStep = 0)
170 this->CopyModelPartNodalVar(rVariable, rDestinationVariable, rOriginModelPart, rDestinationModelPart, BuffStep, BuffStep);
182 template<
class TVarType >
184 const TVarType& rVariable,
187 const unsigned int BuffStep = 0)
189 this->CopyModelPartNodalVar(rVariable, rVariable, rOriginModelPart, rDestinationModelPart, BuffStep);
192 template<
class TVarType >
194 const TVarType &rVariable,
195 const TVarType &rDestinationVariable,
198 const unsigned int BuffStep = 0)
201 const int n_dest_nodes = rDestinationModelPart.
NumberOfNodes();
204 "Origin and destination model parts have different number of nodes." <<
205 "\n\t- Number of origin nodes: " << n_orig_nodes <<
206 "\n\t- Number of destination nodes: " << n_dest_nodes << std::endl;
209 auto it_dest_node = rDestinationModelPart.
NodesBegin() + index;
210 const auto it_orig_node = rOriginModelPart.
NodesBegin() + index;
211 const auto& r_value = it_orig_node->GetSolutionStepValue(rVariable, BuffStep);
212 it_dest_node->GetValue(rDestinationVariable) = r_value;
218 template<
class TVarType >
220 const TVarType &rVariable,
223 const unsigned int BuffStep = 0)
228 template <
class TDataType>
235 const bool CheckValue =
true,
236 const unsigned int ReadBufferStep = 0,
237 const unsigned int WriteBufferStep = 0)
243 rOriginVariable == rDestinationVariable &&
244 ReadBufferStep == WriteBufferStep)
245 <<
"Trying to copy flagged nodal solution step values with the same origin and destination model parts/variables/buffer steps. This is not permitted ( Origin model part: "
246 << rOriginModelPart.
Name() <<
", destination model part: " << rDestinationModelPart.
Name()
247 <<
", variable: " << rOriginVariable.
Name() <<
", buffer step: " << ReadBufferStep <<
" ) !";
250 << rOriginVariable.
Name() <<
" is not found in nodal solution step variables list in origin model part ( "
251 << rOriginModelPart.
Name() <<
" ).";
254 << rDestinationVariable.
Name() <<
" is not found in nodal solution step variables list in destination model part ( "
255 << rDestinationModelPart.
Name() <<
" ).";
258 <<
"Origin model part ( " << rOriginModelPart.
Name()
259 <<
" ) buffer size is smaller or equal than read buffer size [ "
260 << rOriginModelPart.
GetBufferSize() <<
" <= " << ReadBufferStep <<
" ].";
263 <<
"Destination model part ( " << rDestinationModelPart.
Name()
264 <<
" ) buffer size is smaller or equal than read buffer size [ "
265 << rDestinationModelPart.
GetBufferSize() <<
" <= " << WriteBufferStep <<
" ].";
267 CopyModelPartFlaggedVariable<NodesContainerType>(
268 rOriginModelPart, rDestinationModelPart, rFlag, CheckValue,
269 [&](
NodeType& rDestNode,
const TDataType& rValue) {
271 rDestinationVariable, WriteBufferStep) = rValue;
273 [&](
const NodeType& rOriginNode) ->
const TDataType& {
274 return rOriginNode.FastGetSolutionStepValue(rOriginVariable, ReadBufferStep);
282 template <
class TDataType>
288 const bool CheckValue =
true,
289 const unsigned int ReadBufferStep = 0,
290 const unsigned int WriteBufferStep = 0)
294 CopyModelPartFlaggedNodalHistoricalVarToHistoricalVar(
295 rOriginVariable, rDestinationVariable, rModelPart, rModelPart,
296 rFlag, CheckValue, ReadBufferStep, WriteBufferStep);
301 template <
class TDataType>
307 const bool CheckValue =
true,
308 const unsigned int ReadBufferStep = 0,
309 const unsigned int WriteBufferStep = 0)
313 CopyModelPartFlaggedNodalHistoricalVarToHistoricalVar(
314 rVariable, rVariable, rOriginModelPart, rDestinationModelPart,
315 rFlag, CheckValue, ReadBufferStep, WriteBufferStep);
320 template <
class TDataType>
327 const bool CheckValue =
true,
328 const unsigned int ReadBufferStep = 0)
333 << rOriginVariable.
Name() <<
" is not found in nodal solution step variables list in origin model part ( "
334 << rOriginModelPart.
Name() <<
" ).";
337 <<
"Origin model part ( " << rOriginModelPart.
Name()
338 <<
" ) buffer size is smaller or equal than read buffer size [ "
339 << rOriginModelPart.
GetBufferSize() <<
" <= " << ReadBufferStep <<
" ].";
342 CopyModelPartFlaggedVariable<NodesContainerType>(
343 rOriginModelPart, rDestinationModelPart, rFlag, CheckValue,
344 [&](
NodeType& rDestNode,
const TDataType& rValue) {
345 rDestNode.
SetValue(rDestinationVariable, rValue);
347 [&](
const NodeType& rOriginNode) ->
const TDataType& {
348 return rOriginNode.FastGetSolutionStepValue(rOriginVariable, ReadBufferStep);
356 template <
class TDataType>
362 const bool CheckValue =
true,
363 const unsigned int ReadBufferStep = 0)
365 CopyModelPartFlaggedNodalHistoricalVarToNonHistoricalVar(
366 rOriginVariable, rDestinationVariable, rModelPart, rModelPart,
367 rFlag, CheckValue, ReadBufferStep);
370 template <
class TDataType>
376 const bool CheckValue =
true,
377 const unsigned int ReadBufferStep = 0)
379 CopyModelPartFlaggedNodalHistoricalVarToNonHistoricalVar(
380 rVariable, rVariable, rOriginModelPart, rDestinationModelPart,
381 rFlag, CheckValue, ReadBufferStep);
384 template <
class TDataType>
389 const bool CheckValue =
true,
390 const unsigned int ReadBufferStep = 0)
392 CopyModelPartFlaggedNodalHistoricalVarToNonHistoricalVar(
393 rVariable, rVariable, rModelPart, rModelPart,
394 rFlag, CheckValue, ReadBufferStep);
397 template <
class TDataType>
404 const bool CheckValue =
true,
405 const unsigned int WriteBufferStep = 0)
410 << rDestinationVariable.
Name() <<
" is not found in nodal solution step variables list in destination model part ( "
411 << rDestinationModelPart.
Name() <<
" ).";
414 <<
"Destination model part ( " << rDestinationModelPart.
Name()
415 <<
" ) buffer size is smaller or equal than read buffer size [ "
416 << rDestinationModelPart.
GetBufferSize() <<
" <= " << WriteBufferStep <<
" ].";
418 CopyModelPartFlaggedVariable<NodesContainerType>(
419 rOriginModelPart, rDestinationModelPart, rFlag, CheckValue,
420 [&](
NodeType& rDestNode,
const TDataType& rValue) {
422 rDestinationVariable, WriteBufferStep) = rValue;
424 [&](
const NodeType& rOriginNode) ->
const TDataType& {
425 return rOriginNode.GetValue(rOriginVariable);
433 template <
class TDataType>
439 const bool CheckValue =
true,
440 const unsigned int WriteBufferStep = 0)
442 CopyModelPartFlaggedNodalNonHistoricalVarToHistoricalVar(
443 rOriginVariable, rDestinationVariable, rModelPart, rModelPart,
444 rFlag, CheckValue, WriteBufferStep);
447 template <
class TDataType>
453 const bool CheckValue =
true,
454 const unsigned int WriteBufferStep = 0)
456 CopyModelPartFlaggedNodalNonHistoricalVarToHistoricalVar(
457 rVariable, rVariable, rOriginModelPart, rDestinationModelPart,
458 rFlag, CheckValue, WriteBufferStep);
461 template <
class TDataType>
466 const bool CheckValue =
true,
467 const unsigned int WriteBufferStep = 0)
469 CopyModelPartFlaggedNodalNonHistoricalVarToHistoricalVar(
470 rVariable, rVariable, rModelPart, rModelPart,
471 rFlag, CheckValue, WriteBufferStep);
474 template <
class TDataType>
481 const bool CheckValue =
true)
487 rOriginVariable == rDestinationVariable
488 ) <<
"Trying to copy flagged nodal non-historical values with the same model parts/variables. This is not permitted ( Origin model part: "
489 << rOriginModelPart.
Name() <<
", destination model part: " << rDestinationModelPart.
Name()
490 <<
", variable: " << rOriginVariable.
Name() <<
" ) !";
492 CopyModelPartFlaggedVariable<NodesContainerType>(
493 rOriginModelPart, rDestinationModelPart, rFlag, CheckValue,
494 [&](
NodeType& rDestNode,
const TDataType& rValue) {
495 rDestNode.
SetValue(rDestinationVariable, rValue);
497 [&](
const NodeType& rOriginNode) ->
const TDataType& {
498 return rOriginNode.GetValue(rOriginVariable);
506 template <
class TDataType>
512 const bool CheckValue =
true)
514 CopyModelPartFlaggedNodalNonHistoricalVarToNonHistoricalVar(
515 rOriginVariable, rDestinationVariable, rModelPart, rModelPart, rFlag, CheckValue);
518 template <
class TDataType>
524 const bool CheckValue =
true)
526 CopyModelPartFlaggedNodalNonHistoricalVarToNonHistoricalVar(
527 rVariable, rVariable, rOriginModelPart, rDestinationModelPart, rFlag, CheckValue);
530 template <
class TDataType>
537 const bool CheckValue =
true)
542 <<
"Trying to copy flagged elemental variable data with the same model "
543 "parts/variables. This is not permitted ( Origin model part: "
544 << rOriginModelPart.
Name() <<
", destination model part: " << rDestinationModelPart.
Name()
545 <<
", variable: " << rOriginVariable.
Name() <<
" ) !";
547 CopyModelPartFlaggedVariable<ElementsContainerType>(
548 rOriginModelPart, rDestinationModelPart, rFlag, CheckValue,
549 [&](
ElementType& rDestElement,
const TDataType& rValue) {
550 rDestElement.
SetValue(rDestinationVariable, rValue);
552 [&](
const ElementType& rOriginElement) ->
const TDataType& {
553 return rOriginElement.GetValue(rOriginVariable);
559 template <
class TDataType>
565 const bool CheckValue =
true)
567 CopyModelPartFlaggedElementVar(
568 rOriginVariable, rDestinationVariable, rModelPart, rModelPart, rFlag, CheckValue);
571 template <
class TDataType>
577 const bool CheckValue =
true)
579 CopyModelPartFlaggedElementVar(
580 rVariable, rVariable, rOriginModelPart, rDestinationModelPart, rFlag, CheckValue);
583 template <
class TDataType>
590 const bool CheckValue =
true)
595 <<
"Trying to copy flagged condition variable data with the same model "
596 "parts/variables. This is not permitted ( Origin model part: "
597 << rOriginModelPart.
Name() <<
", destination model part: " << rDestinationModelPart.
Name()
598 <<
", variable: " << rOriginVariable.
Name() <<
" ) !";
600 CopyModelPartFlaggedVariable<ConditionsContainerType>(
601 rOriginModelPart, rDestinationModelPart, rFlag, CheckValue,
602 [&](
ConditionType& rDestCondition,
const TDataType& rValue) {
603 rDestCondition.
SetValue(rDestinationVariable, rValue);
605 [&](
const ConditionType& rOriginCondition) ->
const TDataType& {
606 return rOriginCondition.GetValue(rOriginVariable);
612 template <
class TDataType>
618 const bool CheckValue =
true)
620 CopyModelPartFlaggedConditionVar(
621 rOriginVariable, rDestinationVariable, rModelPart, rModelPart, rFlag, CheckValue);
624 template <
class TDataType>
630 const bool CheckValue =
true)
632 CopyModelPartFlaggedConditionVar(
633 rVariable, rVariable, rOriginModelPart, rDestinationModelPart, rFlag, CheckValue);
645 template<
class TVarType >
647 const TVarType& rVariable,
654 KRATOS_ERROR_IF_NOT(n_orig_elems == n_dest_elems) <<
"Origin and destination model parts have different number of elements."
655 <<
"\n\t- Number of origin elements: " << n_orig_elems
656 <<
"\n\t- Number of destination elements: " << n_dest_elems << std::endl;
659 auto it_dest_elems = rDestinationModelPart.
ElementsBegin() + index;
660 const auto it_orig_elems = rOriginModelPart.
ElementsBegin() + index;
661 const auto& r_value = it_orig_elems->GetValue(rVariable);
662 it_dest_elems->SetValue(rVariable,r_value);
674 template<
class TDataType,
class TVarType = Variable<TDataType> >
676 const TVarType& rVariable,
677 const TDataType& rValue,
679 const unsigned int Step = 0)
700 template <
class TDataType,
class TVarType = Variable<TDataType>>
702 const TVarType &rVariable,
703 const TDataType &rValue,
706 const bool CheckValue =
true)
711 if(rNode.
Is(Flag) == CheckValue){
712 rNode.FastGetSolutionStepValue(rVariable) = rValue;}
723 template<
class TType ,
class TContainerType>
726 TContainerType& rContainer)
729 this->SetNonHistoricalVariable(rVariable, rVariable.
Zero(), rContainer);
741 template<
class TContainerType,
class... TVariableArgs>
743 TContainerType& rContainer,
744 const TVariableArgs&... rVariableArgs)
747 (rEntity.SetValue(rVariableArgs, rVariableArgs.Zero()), ...);
756 template<
class TType >
762 this->SetVariable(rVariable, rVariable.
Zero(), rNodes);
773 template<
class... TVariableArgs>
776 const TVariableArgs&... rVariableArgs)
779 AuxiliaryHistoricalValueSetter<typename TVariableArgs::Type>(rVariableArgs, rVariableArgs.Zero(), rNode), ...);
789 template<
class TType,
class TContainerType,
class TVarType = Variable< TType >>
791 const TVarType& rVariable,
793 TContainerType& rContainer
798 block_for_each(rContainer, [&](
typename TContainerType::value_type& rEntity){
799 rEntity.SetValue(rVariable, Value);
813 template<
class TType,
class TContainerType,
class TVarType = Variable< TType >>
815 const TVarType& rVariable,
817 TContainerType& rContainer,
819 const bool Check =
true
824 block_for_each(rContainer, [&](
typename TContainerType::value_type& rEntity){
825 if(rEntity.Is(Flag) == Check){
826 rEntity.SetValue(rVariable, rValue);}
837 template<
class TContainerType,
class TVarType>
839 const TVarType& rVariable,
840 TContainerType& rContainer
846 rEntity.GetData().Erase(rVariable);
856 template<
class TContainerType>
861 block_for_each(rContainer, [&](
typename TContainerType::value_type& rEntity){
862 rEntity.GetData().Clear();
886 template <
class TDataType,
class TContainerType,
class TWeightDataType>
887 void WeightedAccumulateVariableOnNodes(
891 const bool IsInverseWeightProvided =
false);
899 template<
class TContainerType >
902 const bool FlagValue,
903 TContainerType& rContainer
908 block_for_each(rContainer, [&](
typename TContainerType::value_type& rEntity){
909 rEntity.Set(rFlag, FlagValue);
921 template<
class TContainerType >
924 TContainerType& rContainer
929 block_for_each(rContainer, [&](
typename TContainerType::value_type& rEntity){
930 rEntity.Reset(rFlag);
941 template<
class TContainerType >
944 TContainerType& rContainer
949 block_for_each(rContainer, [&](
typename TContainerType::value_type& rEntity){
965 template<
class TDataType,
class TVariableType = Variable<TDataType> >
967 const TVariableType &rOriginVariable,
968 const TVariableType &rSavedVariable,
990 template<
class TDataType,
class TContainerType,
class TVariableType = Variable<TDataType> >
992 const TVariableType &rOriginVariable,
993 const TVariableType &rSavedVariable,
994 TContainerType &rContainer
999 block_for_each(rContainer, [&](
typename TContainerType::value_type& rEntity){
1000 rEntity.SetValue(rSavedVariable, rEntity.GetValue(rOriginVariable));
1016 template<
class TDataType,
class TVariableType = Variable<TDataType> >
1018 const TVariableType &rOriginVariable,
1019 const TVariableType &rDestinationVariable,
1050 template<
class TVarType>
1052 const TVarType& rVariable,
1058 for (
auto& i_node : rNodes)
1072 template<
class TVarType >
1074 const TVarType& rVar,
1081 if (rNodes.
size() != 0) {
1083 KRATOS_ERROR_IF_NOT(rNodes.
begin()->HasDofFor(rVar)) <<
"Trying to fix/free dof of variable " << rVar.Name() <<
" but this dof does not exist in node #" << rNodes.
begin()->Id() <<
"!" << std::endl;
1086 for (
const auto& r_node : rNodes) {
1087 KRATOS_ERROR_IF_NOT(r_node.HasDofFor(rVar)) <<
"Trying to fix/free dof of variable " << rVar.Name() <<
" but this dof does not exist in node #" << r_node.Id() <<
"!" << std::endl;
1091 CheckVariableExists(rVar, rNodes);
1095 rNode.
pGetDof(rVar)->FixDof();
1099 rNode.
pGetDof(rVar)->FreeDof();
1120 template<
class TVarType >
1122 const TVarType& rVariable,
1126 const bool CheckValue =
true)
1130 if (rNodes.
size() != 0) {
1133 <<
"Trying to fix/free dof of variable " << rVariable.Name()
1134 <<
" but this dof does not exist in node #"
1135 << rNodes.
begin()->Id() <<
"!" << std::endl;
1138 for (
const auto& r_node : rNodes) {
1140 <<
"Trying to fix/free dof of variable " << rVariable.Name()
1141 <<
" but this dof does not exist in node #" << r_node.Id()
1142 <<
"!" << std::endl;
1146 CheckVariableExists(rVariable, rNodes);
1150 if (rNode.
Is(rFlag) == CheckValue) {
1151 rNode.pGetDof(rVariable)->FixDof();
1157 if (rNode.
Is(rFlag) == CheckValue) {
1158 rNode.pGetDof(rVariable)->FreeDof();
1177 template<
class TVarType >
1179 const TVarType& rVar,
1186 if(rNodes.
size() != 0 && rNodes.
size() == rData.size()) {
1188 CheckVariableExists(rVar, rNodes);
1192 it_node->FastGetSolutionStepValue(rVar) = rData[index];
1195 KRATOS_ERROR <<
"There is a mismatch between the size of data array and the number of nodes ";
1207 const ArrayVarType& rVar,
1217 template<
class TVarType >
1219 const TVarType& rVar,
1225 double sum_value = 0.0;
1229 const auto& r_local_mesh = r_communicator.
LocalMesh();
1230 const auto& r_nodes_array = r_local_mesh.
Nodes();
1232 sum_value = block_for_each<SumReduction<double>>(r_nodes_array, [&](
Node& rNode){
1233 return rNode.GetValue(rVar);
1236 return r_communicator.GetDataCommunicator().SumAll(sum_value);
1252 template<
class TDataType,
class TVarType = Variable<TDataType> >
1254 const TVarType &rVariable,
1256 const unsigned int BuffStep = 0
1263 TDataType sum_value = block_for_each<SumReduction<TDataType>>(r_communicator.LocalMesh().Nodes(),[&](
Node& rNode){
1264 return rNode.GetSolutionStepValue(rVariable, BuffStep);
1280 const ArrayVarType& rVar,
1290 template<
class TVarType >
1292 const TVarType& rVar,
1298 double sum_value = 0.0;
1302 const auto& r_local_mesh = r_communicator.
LocalMesh();
1303 const auto& r_conditions_array = r_local_mesh.
Conditions();
1305 sum_value = block_for_each<SumReduction<double>>(r_conditions_array, [&](
ConditionType& rCond){
1306 return rCond.GetValue(rVar);
1309 return r_communicator.GetDataCommunicator().SumAll(sum_value);
1321 const ArrayVarType& rVar,
1331 template<
class TVarType >
1333 const TVarType& rVar,
1339 double sum_value = 0.0;
1343 const auto& r_local_mesh = r_communicator.
LocalMesh();
1344 const auto& r_elements_array = r_local_mesh.
Elements();
1346 sum_value = block_for_each<SumReduction<double>>(r_elements_array, [&](
ElementType& rElem){
1347 return rElem.GetValue(rVar);
1350 return r_communicator.GetDataCommunicator().SumAll(sum_value);
1360 template<
class TVarType >
1362 const TVarType& rVar,
1370 KRATOS_ERROR_IF_NOT(rModelPart.
NodesBegin()->SolutionStepsDataHas(rVar)) <<
"ERROR:: Variable : " << rVar <<
"not included in the Solution step data ";
1387 template<
class TVarType >
1389 const TVarType& rVar,
1390 const TVarType& rReactionVar,
1397 KRATOS_ERROR_IF_NOT(rModelPart.
NodesBegin()->SolutionStepsDataHas(rVar)) <<
"ERROR:: DoF Variable : " << rVar <<
"not included in the Soluttion step data ";
1398 KRATOS_ERROR_IF_NOT(rModelPart.
NodesBegin()->SolutionStepsDataHas(rReactionVar)) <<
"ERROR:: Reaction Variable : " << rReactionVar <<
"not included in the Soluttion step data ";
1403 CheckVariableExists(rVar, rModelPart.
Nodes());
1404 CheckVariableExists(rReactionVar, rModelPart.
Nodes());
1410 rNode.AddDof(rVar,rReactionVar);
1423 static void AddDofsList(
1424 const std::vector<std::string>& rDofsVarNamesList,
1434 static void AddDofsWithReactionsList(
1435 const std::vector<std::array<std::string,2>>& rDofsAndReactionsNamesList,
1442 bool CheckVariableKeys();
1463 void UpdateCurrentPosition(
1465 const ArrayVarType& rUpdateVariable = DISPLACEMENT,
1480 template<
class TVectorType=Vector>
1481 [[nodiscard]] TVectorType GetCurrentPositionsVector(
1483 const unsigned int Dimension
1497 template<
class TVectorType=Vector>
1498 [[nodiscard]] TVectorType GetInitialPositionsVector(
1500 const unsigned int Dimension
1515 void SetCurrentPositionsVector(
1532 void SetInitialPositionsVector(
1540 template <Globals::DataLocation TLocation,
class TEntity,
class TValue>
1544 static_assert(std::is_same_v<TEntity,Node>);
1545 return rEntity.SolutionStepsDataHas(rVariable);
1547 static_assert(std::is_same_v<TEntity,Node>
1548 || std::is_same_v<TEntity,Element>
1549 || std::is_same_v<TEntity,Condition>
1550 || std::is_same_v<TEntity,ProcessInfo>
1551 || std::is_same_v<TEntity,ModelPart>);
1552 return rEntity.Has(rVariable);
1559 template <Globals::DataLocation TLocation,
class TEntity,
class TValue>
1560 static std::conditional_t<std::is_arithmetic_v<TValue>,
1566 static_assert(std::is_same_v<TEntity,Node>);
1567 return rEntity.FastGetSolutionStepValue(rVariable);
1569 static_assert(std::is_same_v<TEntity,Node>);
1570 return rEntity.GetValue(rVariable);
1572 static_assert(std::is_same_v<TEntity,Element>);
1573 return rEntity.GetValue(rVariable);
1575 static_assert(std::is_same_v<TEntity,Condition>);
1576 return rEntity.GetValue(rVariable);
1578 static_assert(std::is_same_v<TEntity,ProcessInfo>);
1579 return rEntity.GetValue(rVariable);
1581 static_assert(std::is_same_v<TEntity,ModelPart>);
1582 return rEntity.GetValue(rVariable);
1584 static_assert(std::is_same_v<TEntity,void>,
"Unsupported DataLocation");
1591 template <Globals::DataLocation TLocation,
class TEntity,
class TValue>
1595 static_assert(std::is_same_v<TEntity,Node>);
1596 return rEntity.FastGetSolutionStepValue(rVariable);
1598 static_assert(std::is_same_v<TEntity,Node>);
1599 return rEntity.GetValue(rVariable);
1601 static_assert(std::is_same_v<TEntity,Element>);
1602 return rEntity.GetValue(rVariable);
1604 static_assert(std::is_same_v<TEntity,Condition>);
1605 return rEntity.GetValue(rVariable);
1607 static_assert(std::is_same_v<TEntity,ProcessInfo>);
1608 return rEntity.GetValue(rVariable);
1610 static_assert(std::is_same_v<TEntity,ModelPart>);
1611 return rEntity.GetValue(rVariable);
1613 static_assert(std::is_same_v<TEntity,void>,
"Unsupported DataLocation");
1621 template <Globals::DataLocation TLocation,
class TEntity,
class TValue>
1624 std::conditional_t<std::is_arithmetic_v<TValue>,
1626 const TValue&> Value)
1629 static_assert(std::is_same_v<TEntity,Node>);
1630 rEntity.FastGetSolutionStepValue(rVariable) = Value;
1632 static_assert(std::is_same_v<TEntity,Node>);
1633 rEntity.SetValue(rVariable, Value);
1635 static_assert(std::is_same_v<TEntity,Element>);
1636 rEntity.SetValue(rVariable, Value);
1638 static_assert(std::is_same_v<TEntity,Condition>);
1639 rEntity.SetValue(rVariable, Value);
1641 static_assert(std::is_same_v<TEntity,ProcessInfo>);
1642 rEntity.SetValue(rVariable, Value);
1644 static_assert(std::is_same_v<TEntity,ModelPart>);
1645 rEntity.SetValue(rVariable, Value);
1647 static_assert(std::is_same_v<TEntity,void>,
"Unsupported DataLocation");
1662 [[nodiscard]]
Vector GetSolutionStepValuesVector(
1665 const unsigned int Step,
1666 const unsigned int Dimension=3
1679 [[nodiscard]]
Vector GetSolutionStepValuesVector(
1682 const unsigned int Step
1694 void SetSolutionStepValuesVector(
1698 const unsigned int Step
1710 void SetSolutionStepValuesVector(
1714 const unsigned int Step
1729 [[nodiscard]]
Vector GetValuesVector(
1732 const unsigned int Dimension=3
1746 [[nodiscard]]
Vector GetValuesVector(
1761 void SetValuesVector(
1777 void SetValuesVector(
1822 template<
class TVarType >
1823 bool CheckVariableKeysHelper()
1828 if (var.first ==
"NONE" || var.first ==
"")
1829 std::cout <<
" var first is NONE or empty " << var.first << var.second << std::endl;
1830 if (var.second->Name() ==
"NONE" || var.second->Name() ==
"")
1831 std::cout << var.first << var.second << std::endl;
1832 if (var.first != var.second->Name())
1833 std::cout <<
"Registration Name = " << var.first <<
" Variable Name = " << std::endl;
1840 template <
class TContainerType>
1841 [[nodiscard]] TContainerType&
GetContainer(ModelPart& rModelPart);
1843 template <
class TContainerType>
1844 [[nodiscard]]
const TContainerType&
GetContainer(
const ModelPart& rModelPart);
1846 template<
class TDataType>
1847 static void AuxiliaryHistoricalValueSetter(
1848 const Variable<TDataType>& rVariable,
1849 const TDataType& rValue,
1852 template <
class TContainerType,
class TSetterFunction,
class TGetterFunction>
1853 void CopyModelPartFlaggedVariable(
1854 const ModelPart& rOriginModelPart,
1855 ModelPart& rDestinationModelPart,
1857 const bool CheckValue,
1858 TSetterFunction&& rSetterFunction,
1859 TGetterFunction&& rGetterFunction)
1863 const auto& r_origin_container = GetContainer<TContainerType>(rOriginModelPart);
1864 auto& r_destination_container = GetContainer<TContainerType>(rDestinationModelPart);
1866 const int number_of_origin_items = r_origin_container.size();
1867 const int number_of_destination_items = r_destination_container.size();
1870 <<
"Origin ( " << rOriginModelPart.Name() <<
" ) and destination ( "
1871 << rDestinationModelPart.Name() <<
" ) model parts have different number of items."
1872 <<
"\n\t- Number of origin items: " << number_of_origin_items
1873 <<
"\n\t- Number of destination items: " << number_of_destination_items
1876 IndexPartition<int>(number_of_origin_items).for_each([&](
int i_node) {
1877 const auto& r_orig_item = *(r_origin_container.begin() + i_node);
1878 auto& r_dest_item = *(r_destination_container.begin() + i_node);
1879 if (r_orig_item.Is(rFlag) == CheckValue) {
1880 rSetterFunction(r_dest_item, rGetterFunction(r_orig_item));
virtual bool SynchronizeNonHistoricalVariable(Variable< int > const &rThisVariable)
Definition: communicator.cpp:407
virtual bool SynchronizeVariable(Variable< int > const &rThisVariable)
Definition: communicator.cpp:357
virtual const DataCommunicator & GetDataCommunicator() const
Definition: communicator.cpp:340
MeshType & LocalMesh()
Returns the reference to the mesh storing all local entities.
Definition: communicator.cpp:245
Base class for all Conditions.
Definition: condition.h:59
Base class for all Elements.
Definition: element.h:60
bool Is(Flags const &rOther) const
Definition: flags.h:274
void SetValue(const TVariableType &rThisVariable, typename TVariableType::Type const &rValue)
Definition: geometrical_object.h:238
This class is useful for index iteration over containers.
Definition: parallel_utilities.h:451
void for_each(TUnaryFunction &&f)
Definition: parallel_utilities.h:514
KratosComponents class encapsulates a lookup table for a family of classes in a generic way.
Definition: kratos_components.h:49
ConditionsContainerType & Conditions()
Definition: mesh.h:691
NodesContainerType & Nodes()
Definition: mesh.h:346
ElementsContainerType & Elements()
Definition: mesh.h:568
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
ElementIterator ElementsBegin(IndexType ThisIndex=0)
Definition: model_part.h:1169
std::string FullName() const
This method returns the full name of the model part (including the parents model parts)
Definition: model_part.h:1850
Communicator & GetCommunicator()
Definition: model_part.h:1821
std::string & Name()
Definition: model_part.h:1811
IndexType GetBufferSize() const
This method gets the suffer size of the model part database.
Definition: model_part.h:1876
NodeIterator NodesBegin(IndexType ThisIndex=0)
Definition: model_part.h:487
bool HasNodalSolutionStepVariable(VariableData const &ThisVariable) const
Definition: model_part.h:544
SizeType NumberOfElements(IndexType ThisIndex=0) const
Definition: model_part.h:1027
MeshType::NodesContainerType NodesContainerType
Nodes container. Which is a vector set of nodes with their Id's as key.
Definition: model_part.h:128
SizeType NumberOfNodes(IndexType ThisIndex=0) const
Definition: model_part.h:341
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
VariablesList & GetNodalSolutionStepVariablesList()
Definition: model_part.h:549
This class defines the node.
Definition: node.h:65
TVariableType::Type & FastGetSolutionStepValue(const TVariableType &rThisVariable)
Definition: node.h:435
void SetValue(const TVariableType &rThisVariable, typename TVariableType::Type const &rValue)
Definition: node.h:493
DofType::Pointer pGetDof(TVariableType const &rDofVariable) const
Get DoF counted pointer for a given variable.
Definition: node.h:711
A sorted associative container similar to an STL set, but uses a vector to store pointers to its data...
Definition: pointer_vector_set.h:72
boost::indirect_iterator< typename TContainerType::iterator > iterator
Definition: pointer_vector_set.h:95
size_type size() const
Returns the number of elements in the container.
Definition: pointer_vector_set.h:502
iterator begin()
Returns an iterator pointing to the beginning of the container.
Definition: pointer_vector_set.h:278
const std::string & Name() const
Definition: variable_data.h:201
const TDataType & Zero() const
This method returns the zero value of the variable type.
Definition: variable.h:346
This class implements a set of auxiliar, already parallelized, methods to perform some common tasks r...
Definition: variable_utils.h:63
ModelPart::ElementType ElementType
The element type.
Definition: variable_utils.h:75
void CopyVariable(const TVariableType &rOriginVariable, const TVariableType &rDestinationVariable, NodesContainerType &rNodesContainer)
Takes the value of an historical variable and sets it in another variable This function takes the val...
Definition: variable_utils.h:1017
void CopyModelPartFlaggedNodalHistoricalVarToNonHistoricalVar(const Variable< TDataType > &rVariable, ModelPart &rModelPart, const Flags &rFlag, const bool CheckValue=true, const unsigned int ReadBufferStep=0)
Definition: variable_utils.h:385
void CopyModelPartFlaggedConditionVar(const Variable< TDataType > &rVariable, const ModelPart &rOriginModelPart, ModelPart &rDestinationModelPart, const Flags &rFlag, const bool CheckValue=true)
Definition: variable_utils.h:625
double SumNonHistoricalNodeScalarVariable(const TVarType &rVar, const ModelPart &rModelPart)
Returns the nodal value summation of a non-historical scalar variable.
Definition: variable_utils.h:1218
void CopyModelPartNodalVar(const TVarType &rVariable, const ModelPart &rOriginModelPart, ModelPart &rDestinationModelPart, const unsigned int BuffStep=0)
Copies the nodal value of a variable from an origin model part nodes to the nodes in a destination mo...
Definition: variable_utils.h:183
void AddDofWithReaction(const TVarType &rVar, const TVarType &rReactionVar, ModelPart &rModelPart)
This function add dofs to the nodes in a model part. It is useful since addition is done in parallel.
Definition: variable_utils.h:1388
void CopyModelPartFlaggedNodalHistoricalVarToNonHistoricalVar(const Variable< TDataType > &rVariable, const ModelPart &rOriginModelPart, ModelPart &rDestinationModelPart, const Flags &rFlag, const bool CheckValue=true, const unsigned int ReadBufferStep=0)
Definition: variable_utils.h:371
void SetHistoricalVariableToZero(const Variable< TType > &rVariable, NodesContainerType &rNodes)
Sets the nodal value of any variable to zero.
Definition: variable_utils.h:757
void SetNonHistoricalVariable(const TVarType &rVariable, const TType &rValue, TContainerType &rContainer, const Flags Flag, const bool Check=true)
Sets the container value of any type of non historical variable (considering flag)
Definition: variable_utils.h:814
void CopyModelPartFlaggedElementVar(const Variable< TDataType > &rOriginVariable, const Variable< TDataType > &rDestinationVariable, const ModelPart &rOriginModelPart, ModelPart &rDestinationModelPart, const Flags &rFlag, const bool CheckValue=true)
Definition: variable_utils.h:531
void ApplyFixity(const TVarType &rVar, const bool IsFixed, NodesContainerType &rNodes)
Fixes or frees a variable for all of the nodes in the list. The dof has to exist.
Definition: variable_utils.h:1073
void CopyModelPartFlaggedNodalNonHistoricalVarToHistoricalVar(const Variable< TDataType > &rVariable, ModelPart &rModelPart, const Flags &rFlag, const bool CheckValue=true, const unsigned int WriteBufferStep=0)
Definition: variable_utils.h:462
static bool HasValue(const TEntity &rEntity, const Variable< TValue > &rVariable)
Check whether a Node, Element, Condition, ProcessInfo, or ModelPart stores a value for the provided V...
Definition: variable_utils.h:1541
ModelPart::ElementsContainerType ElementsContainerType
The elements container.
Definition: variable_utils.h:87
void CopyModelPartFlaggedNodalNonHistoricalVarToNonHistoricalVar(const Variable< TDataType > &rOriginVariable, const Variable< TDataType > &rDestinationVariable, ModelPart &rModelPart, const Flags &rFlag, const bool CheckValue=true)
Definition: variable_utils.h:507
ModelPart::NodesContainerType NodesContainerType
The nodes container.
Definition: variable_utils.h:81
Variable< double > DoubleVarType
A definition of the double variable.
Definition: variable_utils.h:90
void CopyModelPartFlaggedNodalHistoricalVarToHistoricalVar(const Variable< TDataType > &rVariable, const ModelPart &rOriginModelPart, ModelPart &rDestinationModelPart, const Flags &rFlag, const bool CheckValue=true, const unsigned int ReadBufferStep=0, const unsigned int WriteBufferStep=0)
Definition: variable_utils.h:302
int CheckVariableExists(const TVarType &rVariable, const NodesContainerType &rNodes)
Checks if all the nodes of a node set has the specified variable.
Definition: variable_utils.h:1051
void ClearNonHistoricalData(TContainerType &rContainer)
Clears the container data value container.
Definition: variable_utils.h:857
void ApplyVector(const TVarType &rVar, const Vector &rData, NodesContainerType &rNodes)
Loops along a vector data to set its values to the nodes contained in a node set.
Definition: variable_utils.h:1178
ModelPart::NodeType NodeType
The node type.
Definition: variable_utils.h:69
static TValue & GetValue(TEntity &rEntity, const Variable< TValue > &rVariable)
Fetch the value of a variable stored in an entity.
Definition: variable_utils.h:1592
void CopyModelPartFlaggedNodalHistoricalVarToNonHistoricalVar(const Variable< TDataType > &rOriginVariable, const Variable< TDataType > &rDestinationVariable, ModelPart &rModelPart, const Flags &rFlag, const bool CheckValue=true, const unsigned int ReadBufferStep=0)
Definition: variable_utils.h:357
static void SetNonHistoricalVariablesToZero(TContainerType &rContainer, const TVariableArgs &... rVariableArgs)
Set the Non Historical Variables To Zero This method sets the provided list of variables to zero in t...
Definition: variable_utils.h:742
void SaveVariable(const TVariableType &rOriginVariable, const TVariableType &rSavedVariable, NodesContainerType &rNodesContainer)
Takes the value of a non-historical variable and saves it in another variable For a nodal container,...
Definition: variable_utils.h:966
void SetNonHistoricalVariable(const TVarType &rVariable, const TType &Value, TContainerType &rContainer)
Sets the container value of any type of non historical variable.
Definition: variable_utils.h:790
void EraseNonHistoricalVariable(const TVarType &rVariable, TContainerType &rContainer)
Erases the container non historical variable.
Definition: variable_utils.h:838
void CopyModelPartFlaggedElementVar(const Variable< TDataType > &rVariable, const ModelPart &rOriginModelPart, ModelPart &rDestinationModelPart, const Flags &rFlag, const bool CheckValue=true)
Definition: variable_utils.h:572
void SaveNonHistoricalVariable(const TVariableType &rOriginVariable, const TVariableType &rSavedVariable, TContainerType &rContainer)
Takes the value of a non-historical variable and saves it in another historical variable For a non-no...
Definition: variable_utils.h:991
void SetNonHistoricalVariableToZero(const Variable< TType > &rVariable, TContainerType &rContainer)
Sets the nodal value of any variable to zero.
Definition: variable_utils.h:724
void AddDof(const TVarType &rVar, ModelPart &rModelPart)
This function add dofs to the nodes in a model part. It is useful since addition is done in parallel.
Definition: variable_utils.h:1361
static std::conditional_t< std::is_arithmetic_v< TValue >, TValue, const TValue & > GetValue(const TEntity &rEntity, const Variable< TValue > &rVariable)
Fetch the value of a variable stored in an entity.
Definition: variable_utils.h:1563
void SetVariable(const TVarType &rVariable, const TDataType &rValue, NodesContainerType &rNodes, const unsigned int Step=0)
Sets the nodal value of a scalar variable.
Definition: variable_utils.h:675
ModelPart::ConditionsContainerType ConditionsContainerType
The conditions container.
Definition: variable_utils.h:84
void CopyModelPartFlaggedNodalHistoricalVarToHistoricalVar(const Variable< TDataType > &rOriginVariable, const Variable< TDataType > &rDestinationVariable, const ModelPart &rOriginModelPart, ModelPart &rDestinationModelPart, const Flags &rFlag, const bool CheckValue=true, const unsigned int ReadBufferStep=0, const unsigned int WriteBufferStep=0)
Definition: variable_utils.h:229
void CopyModelPartNodalVar(const TVarType &rVariable, const TVarType &rDestinationVariable, const ModelPart &rOriginModelPart, ModelPart &rDestinationModelPart, const unsigned int BuffStep=0)
Copies the nodal value of a variable from an origin model part nodes to the nodes in a destination mo...
Definition: variable_utils.h:163
void CopyModelPartFlaggedNodalNonHistoricalVarToHistoricalVar(const Variable< TDataType > &rVariable, const ModelPart &rOriginModelPart, ModelPart &rDestinationModelPart, const Flags &rFlag, const bool CheckValue=true, const unsigned int WriteBufferStep=0)
Definition: variable_utils.h:448
static void SetValue(TEntity &rEntity, const Variable< TValue > &rVariable, std::conditional_t< std::is_arithmetic_v< TValue >, TValue, const TValue & > Value)
Overwrite the value of a variable stored in an entity.
Definition: variable_utils.h:1622
Variable< array_1d< double, 3 > > ArrayVarType
A definition of the array variable.
Definition: variable_utils.h:93
void ApplyFixity(const TVarType &rVariable, const bool IsFixed, NodesContainerType &rNodes, const Flags &rFlag, const bool CheckValue=true)
Fixes/Frees dofs based on a flag.
Definition: variable_utils.h:1121
void ResetFlag(const Flags &rFlag, TContainerType &rContainer)
Flips a flag over a given container.
Definition: variable_utils.h:922
void CopyModelPartNodalVarToNonHistoricalVar(const TVarType &rVariable, const ModelPart &rOriginModelPart, ModelPart &rDestinationModelPart, const unsigned int BuffStep=0)
Definition: variable_utils.h:219
void CopyModelPartFlaggedNodalNonHistoricalVarToNonHistoricalVar(const Variable< TDataType > &rOriginVariable, const Variable< TDataType > &rDestinationVariable, const ModelPart &rOriginModelPart, ModelPart &rDestinationModelPart, const Flags &rFlag, const bool CheckValue=true)
Definition: variable_utils.h:475
void SetVariable(const TVarType &rVariable, const TDataType &rValue, NodesContainerType &rNodes, const Flags Flag, const bool CheckValue=true)
Sets the nodal value of a scalar variable (considering flag)
Definition: variable_utils.h:701
void CopyModelPartNodalVar(const TVarType &rVariable, const TVarType &rDestinationVariable, const ModelPart &rOriginModelPart, ModelPart &rDestinationModelPart, const unsigned int ReadBufferStep, const unsigned int WriteBufferStep)
Copies the nodal value of a variable from an origin model part nodes to the nodes in a destination mo...
Definition: variable_utils.h:126
double SumConditionScalarVariable(const TVarType &rVar, const ModelPart &rModelPart)
Returns the condition value summation of a historical scalar variable.
Definition: variable_utils.h:1291
KRATOS_CLASS_POINTER_DEFINITION(VariableUtils)
We create the Pointer related to VariableUtils.
void CopyModelPartFlaggedConditionVar(const Variable< TDataType > &rOriginVariable, const Variable< TDataType > &rDestinationVariable, const ModelPart &rOriginModelPart, ModelPart &rDestinationModelPart, const Flags &rFlag, const bool CheckValue=true)
Definition: variable_utils.h:584
void CopyModelPartElementalVar(const TVarType &rVariable, const ModelPart &rOriginModelPart, ModelPart &rDestinationModelPart)
Copies the elemental value of a variable from an origin model part elements to the elements in a dest...
Definition: variable_utils.h:646
static void SetHistoricalVariablesToZero(NodesContainerType &rNodes, const TVariableArgs &... rVariableArgs)
Set the Historical Variables To Zero This method sets the provided list of variables to zero in the n...
Definition: variable_utils.h:774
void CopyModelPartFlaggedConditionVar(const Variable< TDataType > &rOriginVariable, const Variable< TDataType > &rDestinationVariable, ModelPart &rModelPart, const Flags &rFlag, const bool CheckValue=true)
Definition: variable_utils.h:613
void CopyModelPartFlaggedElementVar(const Variable< TDataType > &rOriginVariable, const Variable< TDataType > &rDestinationVariable, ModelPart &rModelPart, const Flags &rFlag, const bool CheckValue=true)
Definition: variable_utils.h:560
void SetFlag(const Flags &rFlag, const bool FlagValue, TContainerType &rContainer)
Sets a flag according to a given status over a given container.
Definition: variable_utils.h:900
void CopyModelPartFlaggedNodalHistoricalVarToHistoricalVar(const Variable< TDataType > &rOriginVariable, const Variable< TDataType > &rDestinationVariable, ModelPart &rModelPart, const Flags &rFlag, const bool CheckValue=true, const unsigned int ReadBufferStep=0, const unsigned int WriteBufferStep=0)
Definition: variable_utils.h:283
TDataType SumHistoricalVariable(const TVarType &rVariable, const ModelPart &rModelPart, const unsigned int BuffStep=0)
This method accumulates and return a variable value For a nodal historical variable,...
Definition: variable_utils.h:1253
void CopyModelPartFlaggedNodalNonHistoricalVarToNonHistoricalVar(const Variable< TDataType > &rVariable, const ModelPart &rOriginModelPart, ModelPart &rDestinationModelPart, const Flags &rFlag, const bool CheckValue=true)
Definition: variable_utils.h:519
void CopyModelPartFlaggedNodalNonHistoricalVarToHistoricalVar(const Variable< TDataType > &rOriginVariable, const Variable< TDataType > &rDestinationVariable, const ModelPart &rOriginModelPart, ModelPart &rDestinationModelPart, const Flags &rFlag, const bool CheckValue=true, const unsigned int WriteBufferStep=0)
Definition: variable_utils.h:398
void CopyModelPartNodalVarToNonHistoricalVar(const TVarType &rVariable, const TVarType &rDestinationVariable, const ModelPart &rOriginModelPart, ModelPart &rDestinationModelPart, const unsigned int BuffStep=0)
Definition: variable_utils.h:193
void CopyModelPartFlaggedNodalNonHistoricalVarToHistoricalVar(const Variable< TDataType > &rOriginVariable, const Variable< TDataType > &rDestinationVariable, ModelPart &rModelPart, const Flags &rFlag, const bool CheckValue=true, const unsigned int WriteBufferStep=0)
Definition: variable_utils.h:434
double SumElementScalarVariable(const TVarType &rVar, const ModelPart &rModelPart)
Returns the element value summation of a historical scalar variable.
Definition: variable_utils.h:1332
void FlipFlag(const Flags &rFlag, TContainerType &rContainer)
Flips a flag over a given container.
Definition: variable_utils.h:942
ModelPart::ConditionType ConditionType
The condition type.
Definition: variable_utils.h:72
void CopyModelPartFlaggedNodalHistoricalVarToNonHistoricalVar(const Variable< TDataType > &rOriginVariable, const Variable< TDataType > &rDestinationVariable, const ModelPart &rOriginModelPart, ModelPart &rDestinationModelPart, const Flags &rFlag, const bool CheckValue=true, const unsigned int ReadBufferStep=0)
Definition: variable_utils.h:321
int AddDof(VariableData const *pThisDofVariable)
Definition: variables_list.h:282
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
std::size_t IndexType
The definition of the index type.
Definition: key_hash.h:35
#define KRATOS_ERROR
Definition: exception.h:161
#define KRATOS_ERROR_IF_NOT(conditional)
Definition: exception.h:163
#define KRATOS_ERROR_IF(conditional)
Definition: exception.h:162
#define KRATOS_CHECK_VARIABLE_IN_NODAL_DATA(TheVariable, TheNode)
Definition: checks.h:171
TContainerType & GetContainer(ModelPart::MeshType &rMesh)
void CopyModelPartNodalVarToNonHistoricalVar(VariableUtils &rVariableUtils, const TVarType &rVariable, const ModelPart &rOriginModelPart, ModelPart &rDestinationModelPart, const unsigned int BuffStep=0)
Definition: add_variable_utils_to_python.cpp:104
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
ModelPart::NodesContainerType NodesContainerType
Definition: find_conditions_neighbours_process.h:44
void block_for_each(TIterator itBegin, TIterator itEnd, TFunction &&rFunction)
Execute a functor on all items of a range in parallel.
Definition: parallel_utilities.h:299