From d0b2ea858c81815f65bd7965a7c009cc1488f22a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vicente=20Mataix=20Ferr=C3=A1ndiz?= Date: Thu, 6 Feb 2025 15:19:31 +0100 Subject: [PATCH 01/12] WIP --- kratos/includes/node.h | 456 +++++++++------------------------------- kratos/sources/node.cpp | 381 +++++++++++++++++++++++++++++++++ 2 files changed, 485 insertions(+), 352 deletions(-) create mode 100644 kratos/sources/node.cpp diff --git a/kratos/includes/node.h b/kratos/includes/node.h index 94ba69783eba..22f2edf983ee 100755 --- a/kratos/includes/node.h +++ b/kratos/includes/node.h @@ -14,16 +14,10 @@ #pragma once // System includes -#include -#include -#include -#include -#include // External includes // Project includes -#include "includes/define.h" #include "includes/lock_object.h" #include "geometries/point.h" #include "includes/dof.h" @@ -70,15 +64,9 @@ class Node : public Point, public Flags /// Pointer definition of Node KRATOS_CLASS_INTRUSIVE_POINTER_DEFINITION(Node); - /// Node definition - using NodeType = Node; - /// Base type using BaseType = Point; - /// Point type - using PointType = Point; - /// Dof type using DofType = Dof; @@ -102,17 +90,7 @@ class Node : public Point, public Flags ///@{ /// Default constructor. - Node() - : BaseType() - , Flags() - , mNodalData(0) - , mDofs() - , mData() - , mInitialPosition() - , mNodeLock() - { - CreateSolutionStepData(); - } + Node(); explicit Node(IndexType NewId ) : BaseType() @@ -128,56 +106,16 @@ class Node : public Point, public Flags } /// 1d constructor. - Node(IndexType NewId, double const& NewX) - : BaseType(NewX) - , Flags() - , mNodalData(NewId) - , mDofs() - , mData() - , mInitialPosition(NewX) - , mNodeLock() - { - CreateSolutionStepData(); - } + Node(IndexType NewId, const double NewX); /// 2d constructor. - Node(IndexType NewId, double const& NewX, double const& NewY) - : BaseType(NewX, NewY) - , Flags() - , mNodalData(NewId) - , mDofs() - , mData() - , mInitialPosition(NewX, NewY) - , mNodeLock() - { - CreateSolutionStepData(); - } + Node(IndexType NewId, const double NewX, const double NewY); /// 3d constructor. - Node(IndexType NewId, double const& NewX, double const& NewY, double const& NewZ) - : BaseType(NewX, NewY, NewZ) - , Flags() - , mNodalData(NewId) - , mDofs() - , mData() - , mInitialPosition(NewX, NewY, NewZ) - , mNodeLock() - { - CreateSolutionStepData(); - } + Node(IndexType NewId, const double NewX, const double NewY, const double NewZ); /// Point constructor. - Node(IndexType NewId, PointType const& rThisPoint) - : BaseType(rThisPoint) - , Flags() - , mNodalData(NewId) - , mDofs() - , mData() - , mInitialPosition(rThisPoint) - , mNodeLock() - { - CreateSolutionStepData(); - } + Node(IndexType NewId, Point const& rThisPoint); /** Copy constructor. Initialize this node with given node.*/ Node(Node const& rOtherNode) = delete; @@ -198,58 +136,17 @@ class Node : public Point, public Flags CreateSolutionStepData(); } - - /** Constructor using coordinates stored in given std::vector. Initialize this point with the coordinates in the array. */ - Node(IndexType NewId, std::vector const& rOtherCoordinates) - : BaseType(rOtherCoordinates) - , Flags() - , mNodalData(NewId) - , mDofs() - , mData() - , mInitialPosition() - , mNodeLock() - { - CreateSolutionStepData(); - } + Node(IndexType NewId, std::vector const& rOtherCoordinates); /// 3d with variables list and data constructor. - Node(IndexType NewId, double const& NewX, double const& NewY, double const& NewZ, VariablesList::Pointer pVariablesList, BlockType const * ThisData, SizeType NewQueueSize = 1) - : BaseType(NewX, NewY, NewZ) - , Flags() - , mNodalData(NewId, pVariablesList,ThisData,NewQueueSize) - , mDofs() - , mData() - , mInitialPosition(NewX, NewY, NewZ) - , mNodeLock() - { - } - - typename Node::Pointer Clone() - { - Node::Pointer p_new_node = Kratos::make_intrusive( this->Id(), (*this)[0], (*this)[1], (*this)[2]); - p_new_node->mNodalData = this->mNodalData; - - Node::DofsContainerType& my_dofs = (this)->GetDofs(); - for (typename DofsContainerType::const_iterator it_dof = my_dofs.begin(); it_dof != my_dofs.end(); it_dof++) - { - p_new_node->pAddDof(**it_dof); - } - - p_new_node->mData = this->mData; - p_new_node->mInitialPosition = this->mInitialPosition; + Node(IndexType NewId, const double NewX, const double NewY, const double NewZ, VariablesList::Pointer pVariablesList, BlockType const * ThisData, SizeType NewQueueSize = 1); - p_new_node->Set(Flags(*this)); - - return p_new_node; - } + typename Node::Pointer Clone(); /// Destructor. - ~Node() override - { - ClearSolutionStepsData(); - } + ~Node() override; //********************************************* //public API of intrusive_ptr @@ -259,25 +156,13 @@ class Node : public Point, public Flags } //********************************************* - IndexType Id() const - { - return mNodalData.Id(); - } + IndexType Id() const; - IndexType GetId() const - { - return mNodalData.Id(); - } + IndexType GetId() const; - void SetId(IndexType NewId) - { - mNodalData.SetId(NewId); - } + void SetId(IndexType NewId); - LockObject& GetLock() - { - return mNodeLock; - } + LockObject& GetLock(); inline void SetLock() { @@ -294,186 +179,143 @@ class Node : public Point, public Flags ///@{ /// Assignment operator. - Node& operator=(const Node& rOther) - { - BaseType::operator=(rOther); - Flags::operator =(rOther); - - mNodalData = rOther.mNodalData; - - // Deep copying the dofs - for(typename DofsContainerType::const_iterator it_dof = rOther.mDofs.begin() ; it_dof != rOther.mDofs.end() ; it_dof++) - { - pAddDof(**it_dof); - } - - mData = rOther.mData; - mInitialPosition = rOther.mInitialPosition; + Node& operator=(const Node& rOther); - return *this; - } - - bool operator==(const Node& rOther) - { - return PointType::operator ==(rOther); - } + bool operator==(const Node& rOther); - template typename TVariableType::Type& operator()(const TVariableType& rThisVariable, IndexType SolutionStepIndex) + template + typename TVariableType::Type& operator()(const TVariableType& rThisVariable, IndexType SolutionStepIndex) { return GetSolutionStepValue(rThisVariable, SolutionStepIndex); } - template typename TVariableType::Type& operator()(const TVariableType& rThisVariable) + template + typename TVariableType::Type& operator()(const TVariableType& rThisVariable) { return GetSolutionStepValue(rThisVariable); } - template TDataType& operator[](const Variable& rThisVariable) + template + TDataType& operator[](const Variable& rThisVariable) { return GetValue(rThisVariable); } - template const TDataType& operator[](const Variable& rThisVariable) const + template + const TDataType& operator[](const Variable& rThisVariable) const { return GetValue(rThisVariable); } - double& operator[](IndexType ThisIndex) - { - return BaseType::operator[](ThisIndex); - } - - double operator[](IndexType ThisIndex) const - { - return BaseType::operator[](ThisIndex); - } + double& operator[](IndexType ThisIndex); + + double operator[](IndexType ThisIndex) const; ///@} ///@name Nodal Data ///@{ - void CreateSolutionStepData() - { - SolutionStepData().PushFront(); - } + void CreateSolutionStepData(); - void CloneSolutionStepData() - { - SolutionStepData().CloneFront(); - } + void CloneSolutionStepData(); - void OverwriteSolutionStepData(IndexType SourceSolutionStepIndex, IndexType DestinationSourceSolutionStepIndex) - { - SolutionStepData().AssignData(SolutionStepData().Data(SourceSolutionStepIndex), DestinationSourceSolutionStepIndex); - } + void OverwriteSolutionStepData(IndexType SourceSolutionStepIndex, IndexType DestinationSourceSolutionStepIndex); - void ClearSolutionStepsData() - { - SolutionStepData().Clear(); - } + void ClearSolutionStepsData(); - void SetSolutionStepVariablesList(VariablesList::Pointer pVariablesList) - { - SolutionStepData().SetVariablesList(pVariablesList); - } + void SetSolutionStepVariablesList(VariablesList::Pointer pVariablesList); - VariablesListDataValueContainer& SolutionStepData() - { - return mNodalData.GetSolutionStepData(); - } + VariablesListDataValueContainer& SolutionStepData(); - const VariablesListDataValueContainer& SolutionStepData() const - { - return mNodalData.GetSolutionStepData(); - } + const VariablesListDataValueContainer& SolutionStepData() const; KRATOS_DEPRECATED_MESSAGE("This method is deprecated. Use 'GetData()' instead.") - DataValueContainer& Data() - { - return mData; - } + DataValueContainer& Data(); - DataValueContainer& GetData() - { - return mData; - } + DataValueContainer& GetData(); - const DataValueContainer& GetData() const - { - return mData; - } + const DataValueContainer& GetData() const; - template typename TVariableType::Type& GetSolutionStepValue(const TVariableType& rThisVariable) + template + typename TVariableType::Type& GetSolutionStepValue(const TVariableType& rThisVariable) { return SolutionStepData().GetValue(rThisVariable); } - template typename TVariableType::Type const& GetSolutionStepValue(const TVariableType& rThisVariable) const + template + typename TVariableType::Type const& GetSolutionStepValue(const TVariableType& rThisVariable) const { return SolutionStepData().GetValue(rThisVariable); } - template typename TVariableType::Type& GetSolutionStepValue(const TVariableType& rThisVariable, IndexType SolutionStepIndex) + template + typename TVariableType::Type& GetSolutionStepValue(const TVariableType& rThisVariable, IndexType SolutionStepIndex) { return SolutionStepData().GetValue(rThisVariable, SolutionStepIndex); } - template typename TVariableType::Type const& GetSolutionStepValue(const TVariableType& rThisVariable, IndexType SolutionStepIndex) const + template + typename TVariableType::Type const& GetSolutionStepValue(const TVariableType& rThisVariable, IndexType SolutionStepIndex) const { return SolutionStepData().GetValue(rThisVariable, SolutionStepIndex); } - - bool SolutionStepsDataHas(const VariableData& rThisVariable) const - { - return SolutionStepData().Has(rThisVariable); - } + bool SolutionStepsDataHas(const VariableData& rThisVariable) const; //******************************************************************************************* //By Riccardo //very similar to the one before BUT throws an error if the variable does not exist - template typename TVariableType::Type& FastGetSolutionStepValue(const TVariableType& rThisVariable) + template + typename TVariableType::Type& FastGetSolutionStepValue(const TVariableType& rThisVariable) { return SolutionStepData().FastGetValue(rThisVariable); } - template const typename TVariableType::Type& FastGetSolutionStepValue(const TVariableType& rThisVariable) const + template + const typename TVariableType::Type& FastGetSolutionStepValue(const TVariableType& rThisVariable) const { return SolutionStepData().FastGetValue(rThisVariable); } - template typename TVariableType::Type& FastGetSolutionStepValue(const TVariableType& rThisVariable, IndexType SolutionStepIndex) + template + typename TVariableType::Type& FastGetSolutionStepValue(const TVariableType& rThisVariable, IndexType SolutionStepIndex) { return SolutionStepData().FastGetValue(rThisVariable, SolutionStepIndex); } - template const typename TVariableType::Type& FastGetSolutionStepValue(const TVariableType& rThisVariable, IndexType SolutionStepIndex) const + template + const typename TVariableType::Type& FastGetSolutionStepValue(const TVariableType& rThisVariable, IndexType SolutionStepIndex) const { return SolutionStepData().FastGetValue(rThisVariable, SolutionStepIndex); } - template typename TVariableType::Type& FastGetSolutionStepValue(const TVariableType& rThisVariable, IndexType SolutionStepIndex, IndexType ThisPosition) + template + typename TVariableType::Type& FastGetSolutionStepValue(const TVariableType& rThisVariable, IndexType SolutionStepIndex, IndexType ThisPosition) { return SolutionStepData().FastGetValue(rThisVariable, SolutionStepIndex, ThisPosition); } - template typename TVariableType::Type& FastGetCurrentSolutionStepValue(const TVariableType& rThisVariable, IndexType ThisPosition) + template + typename TVariableType::Type& FastGetCurrentSolutionStepValue(const TVariableType& rThisVariable, IndexType ThisPosition) { return SolutionStepData().FastGetCurrentValue(rThisVariable, ThisPosition); } //******************************************************************************************* - template typename TVariableType::Type& GetValue(const TVariableType& rThisVariable) + template + typename TVariableType::Type& GetValue(const TVariableType& rThisVariable) { return mData.GetValue(rThisVariable); } - template typename TVariableType::Type const& GetValue(const TVariableType& rThisVariable) const + template + typename TVariableType::Type const& GetValue(const TVariableType& rThisVariable) const { return mData.GetValue(rThisVariable); } - template typename TVariableType::Type& GetValue(const TVariableType& rThisVariable, IndexType SolutionStepIndex) + template + typename TVariableType::Type& GetValue(const TVariableType& rThisVariable, IndexType SolutionStepIndex) { if(!mData.Has(rThisVariable)) return SolutionStepData().GetValue(rThisVariable, SolutionStepIndex); @@ -481,7 +323,8 @@ class Node : public Point, public Flags return mData.GetValue(rThisVariable); } - template typename TVariableType::Type const& GetValue(const TVariableType& rThisVariable, IndexType SolutionStepIndex) const + template + typename TVariableType::Type const& GetValue(const TVariableType& rThisVariable, IndexType SolutionStepIndex) const { if(!mData.Has(rThisVariable)) return SolutionStepData().GetValue(rThisVariable, SolutionStepIndex); @@ -495,7 +338,8 @@ class Node : public Point, public Flags mData.SetValue(rThisVariable, rValue); } - template bool Has(const Variable& rThisVariable) const + template + bool Has(const Variable& rThisVariable) const { return mData.Has(rThisVariable); } @@ -515,8 +359,7 @@ class Node : public Point, public Flags } #ifdef KRATOS_DEBUG - if(OpenMPUtils::IsInParallel() != 0) - { + if(OpenMPUtils::IsInParallel() != 0) { KRATOS_ERROR << "Attempting to Fix the variable: " << rDofVariable << " within a parallel region. This is not permitted. Create the Dof first by pAddDof" << std::endl; } #endif @@ -534,86 +377,45 @@ class Node : public Point, public Flags } #ifdef KRATOS_DEBUG - if(OpenMPUtils::IsInParallel() != 0) - { + if(OpenMPUtils::IsInParallel() != 0) { KRATOS_ERROR << "Attempting to Free the variable: " << rDofVariable << " within a parallel region. This is not permitted. Create the Dof first by pAddDof" << std::endl; } #endif pAddDof(rDofVariable)->FreeDof(); } - IndexType GetBufferSize() const - { - return SolutionStepData().QueueSize(); - } + IndexType GetBufferSize() const; - void SetBufferSize(IndexType NewBufferSize) - { - SolutionStepData().Resize(NewBufferSize); - } + void SetBufferSize(IndexType NewBufferSize); ///@} ///@name Access ///@{ - const PointType& GetInitialPosition() const - { - return mInitialPosition; - } - PointType& GetInitialPosition() - { - return mInitialPosition; - } + const Point& GetInitialPosition() const; - double& X0() - { - return mInitialPosition.X(); - } - double& Y0() - { - return mInitialPosition.Y(); - } - double& Z0() - { - return mInitialPosition.Z(); - } + Point& GetInitialPosition(); - double X0() const - { - return mInitialPosition.X(); - } - double Y0() const - { - return mInitialPosition.Y(); - } - double Z0() const - { - return mInitialPosition.Z(); - } + double& X0(); - void SetInitialPosition(const PointType& NewInitialPosition) - { - mInitialPosition.X() = NewInitialPosition.X(); - mInitialPosition.Y() = NewInitialPosition.Y(); - mInitialPosition.Z() = NewInitialPosition.Z(); - } + double& Y0(); + + double& Z0(); + - void SetInitialPosition(double X,double Y, double Z) - { - mInitialPosition.X() = X; - mInitialPosition.Y() = Y; - mInitialPosition.Z() = Z; - } + double X0() const; + + double Y0() const; + + double Z0() const; - VariablesList::Pointer pGetVariablesList() - { - return SolutionStepData().pGetVariablesList(); - } + void SetInitialPosition(const Point& NewInitialPosition); - const VariablesList::Pointer pGetVariablesList() const - { - return SolutionStepData().pGetVariablesList(); - } + void SetInitialPosition(double X,double Y, double Z); + + VariablesList::Pointer pGetVariablesList(); + + const VariablesList::Pointer pGetVariablesList() const; ///@} ///@name Dofs @@ -691,15 +493,9 @@ class Node : public Point, public Flags } /** returns all of the Dofs */ - DofsContainerType& GetDofs() - { - return mDofs; - } + DofsContainerType& GetDofs(); - const DofsContainerType& GetDofs() const - { - return mDofs; - } + const DofsContainerType& GetDofs() const; /** * @brief Get DoF counted pointer for a given variable @@ -918,28 +714,13 @@ class Node : public Point, public Flags ///@{ /// Turn back information as a string. - std::string Info() const override - { - std::stringstream buffer; - buffer << "Node #" << Id(); - return buffer.str(); - } + std::string Info() const override; /// Print information about this object. - void PrintInfo(std::ostream& rOStream) const override - { - rOStream << Info(); - } + void PrintInfo(std::ostream& rOStream) const override; /// Print object's data. - void PrintData(std::ostream& rOStream) const override - { - BaseType::PrintData(rOStream); - if(!mDofs.empty()) - rOStream << std::endl << " Dofs :" << std::endl; - for(typename DofsContainerType::const_iterator i = mDofs.begin() ; i != mDofs.end() ; i++) - rOStream << " " << (*i)->Info() << std::endl; - } + void PrintData(std::ostream& rOStream) const override; ///@} ///@name Friends @@ -985,45 +766,39 @@ class Node : public Point, public Flags NodalData mNodalData; - /** storage for the dof of the node */ + /// storage for the dof of the node DofsContainerType mDofs; - /** A pointer to data related to this node. */ + /// A pointer to data related to this node. DataValueContainer mData; - - ///Initial Position of the node - PointType mInitialPosition; + /// Initial Position of the node + Point mInitialPosition; LockObject mNodeLock; ///@} ///@name Private Operators ///@{ - //********************************************* + //this block is needed for refcounting mutable std::atomic mReferenceCounter{0}; - friend void intrusive_ptr_add_ref(const NodeType* x) + friend void intrusive_ptr_add_ref(const Node* x) { x->mReferenceCounter.fetch_add(1, std::memory_order_relaxed); } - friend void intrusive_ptr_release(const NodeType* x) + friend void intrusive_ptr_release(const Node* x) { if (x->mReferenceCounter.fetch_sub(1, std::memory_order_release) == 1) { std::atomic_thread_fence(std::memory_order_acquire); delete x; } } - //********************************************* + void SortDofs(); - void SortDofs(){ - std::sort(mDofs.begin(), mDofs.end(), [](Kratos::unique_ptr const& First, Kratos::unique_ptr const& Second)->bool{ - return First->GetVariable().Key() < Second->GetVariable().Key(); - }); - } ///@} ///@name Private Operations ///@{ @@ -1034,27 +809,9 @@ class Node : public Point, public Flags friend class Serializer; - void save(Serializer& rSerializer) const override - { - KRATOS_SERIALIZE_SAVE_BASE_CLASS(rSerializer, Point ); - KRATOS_SERIALIZE_SAVE_BASE_CLASS(rSerializer, Flags ); - rSerializer.save("NodalData", &mNodalData); // Storing it as pointer to be shared by Dof pointer - rSerializer.save("Data", mData); - rSerializer.save("Initial Position", mInitialPosition); - rSerializer.save("Data", mDofs); - - } + void save(Serializer& rSerializer) const override; - void load(Serializer& rSerializer) override - { - KRATOS_SERIALIZE_LOAD_BASE_CLASS(rSerializer, Point ); - KRATOS_SERIALIZE_LOAD_BASE_CLASS(rSerializer, Flags ); - NodalData* p_nodal_data = &mNodalData; - rSerializer.load("NodalData", p_nodal_data); - rSerializer.load("Data", mData); - rSerializer.load("Initial Position", mInitialPosition); - rSerializer.load("Data", mDofs); - } + void load(Serializer& rSerializer) override; ///@} ///@name Private Access @@ -1102,9 +859,4 @@ inline std::ostream& operator << (std::ostream& rOStream, } ///@} -// namespace Globals -// { -// extern Node DefaultNode3; -// } - } // namespace Kratos. diff --git a/kratos/sources/node.cpp b/kratos/sources/node.cpp new file mode 100644 index 000000000000..8f36422aeb28 --- /dev/null +++ b/kratos/sources/node.cpp @@ -0,0 +1,381 @@ +// | / | +// ' / __| _` | __| _ \ __| +// . \ | ( | | ( |\__ ` +// _|\_\_| \__,_|\__|\___/ ____/ +// Multi-Physics +// +// License: BSD License +// Kratos default license: kratos/license.txt +// +// Main authors: Pooyan Dadvand +// Riccardo Rossi +// + +#pragma once + +// System includes + +// External includes + +// Project includes +#include "includes/node.h" + +namespace Kratos +{ + +/// Default constructor. +Node::Node() + : BaseType() + , Flags() + , mNodalData(0) + , mDofs() + , mData() + , mInitialPosition() + , mNodeLock() +{ + CreateSolutionStepData(); +} + +/// 1d constructor. +Node::Node(IndexType NewId, const double NewX) + : BaseType(NewX) + , Flags() + , mNodalData(NewId) + , mDofs() + , mData() + , mInitialPosition(NewX) + , mNodeLock() +{ + CreateSolutionStepData(); +} + +/// 2d constructor. +Node::Node(IndexType NewId, const double NewX, const double NewY) + : BaseType(NewX, NewY) + , Flags() + , mNodalData(NewId) + , mDofs() + , mData() + , mInitialPosition(NewX, NewY) + , mNodeLock() +{ + CreateSolutionStepData(); +} + +/// 3d constructor. +Node::Node(IndexType NewId, const double NewX, const double NewY, const double NewZ) + : BaseType(NewX, NewY, NewZ) + , Flags() + , mNodalData(NewId) + , mDofs() + , mData() + , mInitialPosition(NewX, NewY, NewZ) + , mNodeLock() +{ + CreateSolutionStepData(); +} + +/// Point constructor. +Node::Node(IndexType NewId, Point const& rThisPoint) + : BaseType(rThisPoint) + , Flags() + , mNodalData(NewId) + , mDofs() + , mData() + , mInitialPosition(rThisPoint) + , mNodeLock() +{ + CreateSolutionStepData(); +} + +Node::Node(IndexType NewId, std::vector const& rOtherCoordinates) + : BaseType(rOtherCoordinates) + , Flags() + , mNodalData(NewId) + , mDofs() + , mData() + , mInitialPosition() + , mNodeLock() +{ + CreateSolutionStepData(); +} + +/// 3d with variables list and data constructor. +Node::Node(IndexType NewId, const double NewX, const double NewY, const double NewZ, VariablesList::Pointer pVariablesList, BlockType const * ThisData, SizeType NewQueueSize = 1) + : BaseType(NewX, NewY, NewZ) + , Flags() + , mNodalData(NewId, pVariablesList,ThisData,NewQueueSize) + , mDofs() + , mData() + , mInitialPosition(NewX, NewY, NewZ) + , mNodeLock() +{ +} + +typename Node::Pointer Node::Clone() +{ + Node::Pointer p_new_node = Kratos::make_intrusive( this->Id(), (*this)[0], (*this)[1], (*this)[2]); + p_new_node->mNodalData = this->mNodalData; + + Node::DofsContainerType& my_dofs = (this)->GetDofs(); + for (typename DofsContainerType::const_iterator it_dof = my_dofs.begin(); it_dof != my_dofs.end(); it_dof++) { + p_new_node->pAddDof(**it_dof); + } + + p_new_node->mData = this->mData; + p_new_node->mInitialPosition = this->mInitialPosition; + + p_new_node->Set(Flags(*this)); + + return p_new_node; +} + +/// Destructor. +Node::~Node() +{ + ClearSolutionStepsData(); +} + +Node::IndexType Node::Id() const +{ + return mNodalData.Id(); +} + +Node::IndexType Node::GetId() const +{ + return mNodalData.Id(); +} + +void Node::SetId(IndexType NewId) +{ + mNodalData.SetId(NewId); +} + +LockObject& Node::GetLock() +{ + return mNodeLock; +} + +Node& Node::operator=(const Node& rOther) +{ + BaseType::operator=(rOther); + Flags::operator =(rOther); + + mNodalData = rOther.mNodalData; + + // Deep copying the dofs + for(typename DofsContainerType::const_iterator it_dof = rOther.mDofs.begin() ; it_dof != rOther.mDofs.end() ; it_dof++) { + pAddDof(**it_dof); + } + + mData = rOther.mData; + mInitialPosition = rOther.mInitialPosition; + + return *this; +} + +bool Node::operator==(const Node& rOther) +{ + return Point::operator ==(rOther); +} + +double& Node::operator[](IndexType ThisIndex) +{ + return BaseType::operator[](ThisIndex); +} + +double Node::operator[](IndexType ThisIndex) const +{ + return BaseType::operator[](ThisIndex); +} + +void Node::CreateSolutionStepData() +{ + SolutionStepData().PushFront(); +} + +void Node::CloneSolutionStepData() +{ + SolutionStepData().CloneFront(); +} + +void Node::OverwriteSolutionStepData(IndexType SourceSolutionStepIndex, IndexType DestinationSourceSolutionStepIndex) +{ + SolutionStepData().AssignData(SolutionStepData().Data(SourceSolutionStepIndex), DestinationSourceSolutionStepIndex); +} + +void Node::ClearSolutionStepsData() +{ + SolutionStepData().Clear(); +} + +void Node::SetSolutionStepVariablesList(VariablesList::Pointer pVariablesList) +{ + SolutionStepData().SetVariablesList(pVariablesList); +} + +VariablesListDataValueContainer& Node::SolutionStepData() +{ + return mNodalData.GetSolutionStepData(); +} + +const VariablesListDataValueContainer& Node::SolutionStepData() const +{ + return mNodalData.GetSolutionStepData(); +} + +DataValueContainer& Node::Data() +{ + return mData; +} + +DataValueContainer& Node::GetData() +{ + return mData; +} + +const DataValueContainer& Node::GetData() const +{ + return mData; +} + +bool Node::SolutionStepsDataHas(const VariableData& rThisVariable) const +{ + return SolutionStepData().Has(rThisVariable); +} + + +IndexType Node::GetBufferSize() const +{ + return SolutionStepData().QueueSize(); +} + +void Node::SetBufferSize(IndexType NewBufferSize) +{ + SolutionStepData().Resize(NewBufferSize); +} + +const Point& Node::GetInitialPosition() const +{ + return mInitialPosition; +} + +Point& Node::GetInitialPosition() +{ + return mInitialPosition; +} + +double& Node::X0() +{ + return mInitialPosition.X(); +} + +double& Node::Y0() +{ + return mInitialPosition.Y(); +} + +double& Node::Z0() +{ + return mInitialPosition.Z(); +} + +double Node::X0() const +{ + return mInitialPosition.X(); +} + +double Node::Y0() const +{ + return mInitialPosition.Y(); +} + +double Node::Z0() const +{ + return mInitialPosition.Z(); +} + +void Node::SetInitialPosition(const Point& NewInitialPosition) +{ + mInitialPosition.X() = NewInitialPosition.X(); + mInitialPosition.Y() = NewInitialPosition.Y(); + mInitialPosition.Z() = NewInitialPosition.Z(); +} + +void Node::SetInitialPosition(double X,double Y, double Z) +{ + mInitialPosition.X() = X; + mInitialPosition.Y() = Y; + mInitialPosition.Z() = Z; +} + +VariablesList::Pointer Node::pGetVariablesList() +{ + return SolutionStepData().pGetVariablesList(); +} + +const VariablesList::Pointer Node::pGetVariablesList() const +{ + return SolutionStepData().pGetVariablesList(); +} + +DofsContainerType& Node::GetDofs() +{ + return mDofs; +} + +const DofsContainerType& Node::GetDofs() const +{ + return mDofs; +} + +std::string Node::Info() const +{ + std::stringstream buffer; + buffer << "Node #" << Id(); + return buffer.str(); +} + +void Node::PrintInfo(std::ostream& rOStream) const +{ + rOStream << Info(); +} + +void Node::PrintData(std::ostream& rOStream) const +{ + BaseType::PrintData(rOStream); + if(!mDofs.empty()) + rOStream << std::endl << " Dofs :" << std::endl; + for(typename DofsContainerType::const_iterator i = mDofs.begin() ; i != mDofs.end() ; i++) + rOStream << " " << (*i)->Info() << std::endl; +} + +void Node::SortDofs(){ + std::sort(mDofs.begin(), mDofs.end(), [](Kratos::unique_ptr const& First, Kratos::unique_ptr const& Second)->bool{ + return First->GetVariable().Key() < Second->GetVariable().Key(); + }); +} + +void Node::save(Serializer& rSerializer) const +{ + KRATOS_SERIALIZE_SAVE_BASE_CLASS(rSerializer, Point ); + KRATOS_SERIALIZE_SAVE_BASE_CLASS(rSerializer, Flags ); + rSerializer.save("NodalData", &mNodalData); // Storing it as pointer to be shared by Dof pointer + rSerializer.save("Data", mData); + rSerializer.save("Initial Position", mInitialPosition); + rSerializer.save("Data", mDofs); + +} + +void Node::load(Serializer& rSerializer) +{ + KRATOS_SERIALIZE_LOAD_BASE_CLASS(rSerializer, Point ); + KRATOS_SERIALIZE_LOAD_BASE_CLASS(rSerializer, Flags ); + NodalData* p_nodal_data = &mNodalData; + rSerializer.load("NodalData", p_nodal_data); + rSerializer.load("Data", mData); + rSerializer.load("Initial Position", mInitialPosition); + rSerializer.load("Data", mDofs); +} + +} // namespace Kratos. From 0b7b3eb19a87fb0e631453914f7421d1ea08b0a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vicente=20Mataix=20Ferr=C3=A1ndiz?= Date: Thu, 6 Feb 2025 16:51:39 +0100 Subject: [PATCH 02/12] Doc --- kratos/includes/node.h | 182 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 172 insertions(+), 10 deletions(-) diff --git a/kratos/includes/node.h b/kratos/includes/node.h index 22f2edf983ee..a00e404e81e3 100755 --- a/kratos/includes/node.h +++ b/kratos/includes/node.h @@ -52,10 +52,18 @@ namespace Kratos ///@name Kratos Classes ///@{ -/// This class defines the node -/** The node class from Kratos is defined in this class -*/ -class Node : public Point, public Flags +/** + * @ingroup KratosCore + * @class Node + * @brief This class defines the node + * @details The node class from Kratos is defined in this class. Represents a node in a finite element model. + * The Node class provides various functionalities for handling nodal data, + * degrees of freedom (DOFs), etc... + * @author Pooyan Dadvand + * @author Riccardo Rossi + */ +class Node + : public Point, public Flags { public: ///@name Type Definitions @@ -143,32 +151,65 @@ class Node : public Point, public Flags /// 3d with variables list and data constructor. Node(IndexType NewId, const double NewX, const double NewY, const double NewZ, VariablesList::Pointer pVariablesList, BlockType const * ThisData, SizeType NewQueueSize = 1); + /** + * @brief Creates a clone of the current node. + * @details This function creates a new node with the same ID and coordinates as + * the current node, copies its nodal data, DOFs, and flags. + * @return Pointer to the cloned node. + */ typename Node::Pointer Clone(); - /// Destructor. + /** + * @brief Destructor for the Node class. + * @details Clears any stored solution step data before destruction. + */ ~Node() override; - //********************************************* - //public API of intrusive_ptr + /** + * @brief Gets the reference count of the node. + * @details Public API of intrusive_ptr + * @return The current reference count. + */ unsigned int use_count() const noexcept { return mReferenceCounter; } - //********************************************* + /** + * @brief Retrieves the node ID. + * @return The ID of the node. + */ IndexType Id() const; + /** + * @brief Retrieves the node ID (alternative method). + * @return The ID of the node. + */ IndexType GetId() const; + /** + * @brief Sets a new ID for the node. + * @param NewId The new ID to assign. + */ void SetId(IndexType NewId); + /** + * @brief Retrieves the lock object for thread safety. + * @return A reference to the lock object. + */ LockObject& GetLock(); + /** + * @brief Locks the node for thread-safe operations. + */ inline void SetLock() { mNodeLock.lock(); } + /** + * @brief Unlocks the node. + */ inline void UnSetLock() { mNodeLock.unlock(); @@ -178,88 +219,209 @@ class Node : public Point, public Flags ///@name Operators ///@{ - /// Assignment operator. + /** + * @brief Assignment operator for deep copying a node. + * @details Copies the nodal data, DOFs, and initial position from another node. + * @param rOther The node to copy from. + * @return A reference to the copied node. + */ Node& operator=(const Node& rOther); + /** + * @brief Equality operator. + * @details Compares two nodes based on their position. + * @param rOther The node to compare with. + * @return True if nodes are equal, false otherwise. + */ bool operator==(const Node& rOther); + /** + * @brief Accesses a solution step value for a given variable and step index. + * @tparam TVariableType The type of the variable. + * @param rThisVariable The variable to access. + * @param SolutionStepIndex The solution step index. + * @return Reference to the stored value. + */ template typename TVariableType::Type& operator()(const TVariableType& rThisVariable, IndexType SolutionStepIndex) { return GetSolutionStepValue(rThisVariable, SolutionStepIndex); } + /** + * @brief Accesses the current solution step value for a given variable. + * @tparam TVariableType The type of the variable. + * @param rThisVariable The variable to access. + * @return Reference to the stored value. + */ template typename TVariableType::Type& operator()(const TVariableType& rThisVariable) { return GetSolutionStepValue(rThisVariable); } + /** + * @brief Accessor for node data using a variable. + * @tparam TDataType The type of data stored. + * @param rThisVariable The variable representing the data. + * @return Reference to the stored data. + */ template TDataType& operator[](const Variable& rThisVariable) { return GetValue(rThisVariable); } + /** + * @brief Const accessor for node data using a variable. + * @tparam TDataType The type of data stored. + * @param rThisVariable The variable representing the data. + * @return Const reference to the stored data. + */ template const TDataType& operator[](const Variable& rThisVariable) const { return GetValue(rThisVariable); } + /** + * @brief Accessor for node coordinates. + * @param ThisIndex The index of the coordinate (0 = X, 1 = Y, 2 = Z). + * @return Reference to the coordinate value. + */ double& operator[](IndexType ThisIndex); - + + /** + * @brief Const accessor for node coordinates. + * @param ThisIndex The index of the coordinate (0 = X, 1 = Y, 2 = Z). + * @return The coordinate value. + */ double operator[](IndexType ThisIndex) const; ///@} ///@name Nodal Data ///@{ + /** + * @brief Creates a new solution step data entry. + * @details Adds a new solution step at the front of the solution step data container. + */ void CreateSolutionStepData(); + /** + * @brief Clones the current solution step data. + * @details Copies the front solution step data to create a new step. + */ void CloneSolutionStepData(); + /** + * @brief Overwrites solution step data at a given index. + * @details Copies the data from a source solution step index to a destination index. + * @param SourceSolutionStepIndex The index of the source solution step. + * @param DestinationSourceSolutionStepIndex The index of the destination step where the data will be assigned. + */ void OverwriteSolutionStepData(IndexType SourceSolutionStepIndex, IndexType DestinationSourceSolutionStepIndex); + /** + * @brief Clears all stored solution step data. + * @details Removes all solution step data entries. + */ void ClearSolutionStepsData(); + /** + * @brief Sets the list of solution step variables. + * @details Assigns a new variables list to the solution step data. + * @param pVariablesList Pointer to the new list of variables. + */ void SetSolutionStepVariablesList(VariablesList::Pointer pVariablesList); + /** + * @brief Retrieves the solution step data container. + * @return Reference to the solution step data container. + */ VariablesListDataValueContainer& SolutionStepData(); + /** + * @brief Retrieves the solution step data container (const version). + * @return Const reference to the solution step data container. + */ const VariablesListDataValueContainer& SolutionStepData() const; + /** + * @deprecated This method is deprecated. Use GetData() instead. + * @brief Retrieves the data container for the node. + * @return Reference to the data container. + */ KRATOS_DEPRECATED_MESSAGE("This method is deprecated. Use 'GetData()' instead.") DataValueContainer& Data(); + /** + * @brief Retrieves the data container for the node. + * @return Reference to the data container. + */ DataValueContainer& GetData(); + /** + * @brief Retrieves the data container for the node (const version). + * @return Const reference to the data container. + */ const DataValueContainer& GetData() const; + /** + * @brief Retrieves the solution step value for a given variable. + * @tparam TVariableType The type of the variable. + * @param rThisVariable The variable whose value is to be retrieved. + * @return Reference to the stored value. + */ template typename TVariableType::Type& GetSolutionStepValue(const TVariableType& rThisVariable) { return SolutionStepData().GetValue(rThisVariable); } + /** + * @brief Retrieves the solution step value for a given variable (const version). + * @tparam TVariableType The type of the variable. + * @param rThisVariable The variable whose value is to be retrieved. + * @return Const reference to the stored value. + */ template typename TVariableType::Type const& GetSolutionStepValue(const TVariableType& rThisVariable) const { return SolutionStepData().GetValue(rThisVariable); } + /** + * @brief Retrieves the solution step value for a given variable at a specific step. + * @tparam TVariableType The type of the variable. + * @param rThisVariable The variable whose value is to be retrieved. + * @param SolutionStepIndex The index of the solution step. + * @return Reference to the stored value. + */ template typename TVariableType::Type& GetSolutionStepValue(const TVariableType& rThisVariable, IndexType SolutionStepIndex) { return SolutionStepData().GetValue(rThisVariable, SolutionStepIndex); } + /** + * @brief Retrieves the solution step value for a given variable at a specific step (const version). + * @tparam TVariableType The type of the variable. + * @param rThisVariable The variable whose value is to be retrieved. + * @param SolutionStepIndex The index of the solution step. + * @return Const reference to the stored value. + */ template typename TVariableType::Type const& GetSolutionStepValue(const TVariableType& rThisVariable, IndexType SolutionStepIndex) const { return SolutionStepData().GetValue(rThisVariable, SolutionStepIndex); } + /** + * @brief Checks if the solution step data contains a given variable. + * @param rThisVariable The variable to check. + * @return True if the variable exists in the solution step data, false otherwise. + */ bool SolutionStepsDataHas(const VariableData& rThisVariable) const; //******************************************************************************************* From 3fc90e88d0a43e7816ee4da1e37b86832e18c3cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vicente=20Mataix=20Ferr=C3=A1ndiz?= Date: Fri, 7 Feb 2025 09:33:34 +0100 Subject: [PATCH 03/12] More doc --- kratos/includes/node.h | 87 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 82 insertions(+), 5 deletions(-) diff --git a/kratos/includes/node.h b/kratos/includes/node.h index a00e404e81e3..426b0df88d68 100755 --- a/kratos/includes/node.h +++ b/kratos/includes/node.h @@ -424,58 +424,115 @@ class Node */ bool SolutionStepsDataHas(const VariableData& rThisVariable) const; - //******************************************************************************************* - //By Riccardo - //very similar to the one before BUT throws an error if the variable does not exist + /** + * @brief Retrieves the solution step value for a given variable quickly. + * @tparam TVariableType The type of the variable. + * @param rThisVariable The variable whose value is to be retrieved. + * @return Reference to the stored value. + */ template typename TVariableType::Type& FastGetSolutionStepValue(const TVariableType& rThisVariable) { return SolutionStepData().FastGetValue(rThisVariable); } + /** + * @brief Retrieves the solution step value for a given variable quickly (const version). + * @tparam TVariableType The type of the variable. + * @param rThisVariable The variable whose value is to be retrieved. + * @return Const reference to the stored value. + */ template const typename TVariableType::Type& FastGetSolutionStepValue(const TVariableType& rThisVariable) const { return SolutionStepData().FastGetValue(rThisVariable); } + /** + * @brief Retrieves the solution step value for a given variable at a specific step quickly. + * @tparam TVariableType The type of the variable. + * @param rThisVariable The variable whose value is to be retrieved. + * @param SolutionStepIndex The index of the solution step. + * @return Reference to the stored value. + */ template typename TVariableType::Type& FastGetSolutionStepValue(const TVariableType& rThisVariable, IndexType SolutionStepIndex) { return SolutionStepData().FastGetValue(rThisVariable, SolutionStepIndex); } + /** + * @brief Retrieves the solution step value for a given variable at a specific step quickly (const version). + * @tparam TVariableType The type of the variable. + * @param rThisVariable The variable whose value is to be retrieved. + * @param SolutionStepIndex The index of the solution step. + * @return Const reference to the stored value. + */ template const typename TVariableType::Type& FastGetSolutionStepValue(const TVariableType& rThisVariable, IndexType SolutionStepIndex) const { return SolutionStepData().FastGetValue(rThisVariable, SolutionStepIndex); } + /** + * @brief Retrieves the solution step value for a given variable at a specific step and position quickly. + * @tparam TVariableType The type of the variable. + * @param rThisVariable The variable whose value is to be retrieved. + * @param SolutionStepIndex The index of the solution step. + * @param ThisPosition The position in the solution step data. + * @return Reference to the stored value. + */ template typename TVariableType::Type& FastGetSolutionStepValue(const TVariableType& rThisVariable, IndexType SolutionStepIndex, IndexType ThisPosition) { return SolutionStepData().FastGetValue(rThisVariable, SolutionStepIndex, ThisPosition); } + /** + * @brief Retrieves the current solution step value for a given variable at a specific position quickly. + * @tparam TVariableType The type of the variable. + * @param rThisVariable The variable whose value is to be retrieved. + * @param ThisPosition The position in the solution step data. + * @return Reference to the stored value. + */ template typename TVariableType::Type& FastGetCurrentSolutionStepValue(const TVariableType& rThisVariable, IndexType ThisPosition) { return SolutionStepData().FastGetCurrentValue(rThisVariable, ThisPosition); } -//******************************************************************************************* + /** + * @brief Retrieves the stored value of a given variable. + * @tparam TVariableType The type of the variable. + * @param rThisVariable The variable whose value is to be retrieved. + * @return Reference to the stored value. + */ template typename TVariableType::Type& GetValue(const TVariableType& rThisVariable) { return mData.GetValue(rThisVariable); } + /** + * @brief Retrieves the stored value of a given variable (const version). + * @tparam TVariableType The type of the variable. + * @param rThisVariable The variable whose value is to be retrieved. + * @return Const reference to the stored value. + */ template typename TVariableType::Type const& GetValue(const TVariableType& rThisVariable) const { return mData.GetValue(rThisVariable); } + /** + * @brief Retrieves the value of a variable, checking both node data and solution step data. + * @details If the variable is not present in the node's data, it fetches from the solution step data. + * @tparam TVariableType The type of the variable. + * @param rThisVariable The variable to retrieve. + * @param SolutionStepIndex The solution step index. + * @return Reference to the value of the variable. + */ template typename TVariableType::Type& GetValue(const TVariableType& rThisVariable, IndexType SolutionStepIndex) { @@ -485,6 +542,14 @@ class Node return mData.GetValue(rThisVariable); } + /** + * @brief Retrieves the value of a variable, checking both node data and solution step data (const version). + * @details If the variable is not present in the node's data, it fetches from the solution step data. + * @tparam TVariableType The type of the variable. + * @param rThisVariable The variable to retrieve. + * @param SolutionStepIndex The solution step index. + * @return Const reference to the value of the variable. + */ template typename TVariableType::Type const& GetValue(const TVariableType& rThisVariable, IndexType SolutionStepIndex) const { @@ -494,12 +559,25 @@ class Node return mData.GetValue(rThisVariable); } + /** + * @brief Sets the value of a given variable. + * @details Stores a new value for the given variable in the node's data. + * @tparam TVariableType The type of the variable. + * @param rThisVariable The variable to store. + * @param rValue The value to assign. + */ template void SetValue(const TVariableType& rThisVariable, typename TVariableType::Type const& rValue) { mData.SetValue(rThisVariable, rValue); } + /** + * @brief Checks if a variable exists in the node's data. + * @tparam TDataType The type of the variable. + * @param rThisVariable The variable to check. + * @return True if the variable exists, false otherwise. + */ template bool Has(const Variable& rThisVariable) const { @@ -563,7 +641,6 @@ class Node double& Y0(); double& Z0(); - double X0() const; From 0f386c29b2062ba475d03983c05383fa12058ea4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vicente=20Mataix=20Ferr=C3=A1ndiz?= Date: Fri, 7 Feb 2025 09:56:19 +0100 Subject: [PATCH 04/12] More doc --- kratos/includes/node.h | 109 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 96 insertions(+), 13 deletions(-) diff --git a/kratos/includes/node.h b/kratos/includes/node.h index 426b0df88d68..8874066501e3 100755 --- a/kratos/includes/node.h +++ b/kratos/includes/node.h @@ -788,8 +788,15 @@ class Node KRATOS_ERROR << "Non-existent DOF in node #" << Id() << " for variable : " << rDofVariable.Name() << std::endl; } - - /** adds a Dof to the node and return new added dof or existed one. */ + /** + * @brief Adds a degree of freedom (DOF) to the node, returning the newly added DOF or the existing one if it already exists. + * @details This function checks if the DOF for the given variable already exists in the node's DOF list. If it exists, + * it returns the existing DOF. Otherwise, it creates a new DOF for the given variable and adds it to the list. + * The DOF list is then sorted to maintain order. + * @tparam TVariableType The type of the variable associated with the degree of freedom. + * @param rDofVariable The variable associated with the degree of freedom to be added. + * @return A pointer to the added or existing DOF. + */ template inline typename DofType::Pointer pAddDof(TVariableType const& rDofVariable) { @@ -812,15 +819,21 @@ class Node KRATOS_CATCH(*this); } - /** adds a Dof to the node and return new added dof or existed one. */ + /** + * @brief Adds a degree of freedom (DOF) to the node, returning the newly added DOF or the existing one if it already exists. + * @details This function checks if the DOF for the given variable already exists in the node's DOF list. If it exists, + * it updates the reaction and returns the existing DOF. If not, it creates a new DOF based on the provided `SourceDof`. + * The DOF list is then sorted to maintain order. + * @param SourceDof The DOF to be added or whose reaction should be updated. + * @return A pointer to the added or existing DOF. + */ inline typename DofType::Pointer pAddDof(DofType const& SourceDof) { KRATOS_TRY for(auto it_dof = mDofs.begin() ; it_dof != mDofs.end() ; it_dof++){ - if((*it_dof)->GetVariable() == SourceDof.GetVariable()){ - if((*it_dof)->GetReaction() != SourceDof.GetReaction()) - { + if((*it_dof)->GetVariable() == SourceDof.GetVariable()) { + if((*it_dof)->GetReaction() != SourceDof.GetReaction()) { **it_dof = SourceDof; (*it_dof)->SetNodalData(&mNodalData); } @@ -840,7 +853,17 @@ class Node KRATOS_CATCH(*this); } - /** adds a Dof to the node and return new added dof or existed one. */ + /** + * @brief Adds a degree of freedom (DOF) to the node, returning the newly added DOF or the existing one if it already exists, with a reaction. + * @details This function checks if the DOF for the given variable already exists in the node's DOF list. If it exists, + * it updates the reaction and returns the existing DOF. Otherwise, it creates a new DOF with both the variable + * and the reaction, and adds it to the list. The DOF list is then sorted to maintain order. + * @tparam TVariableType The type of the variable associated with the degree of freedom. + * @tparam TReactionType The type of the reaction associated with the degree of freedom. + * @param rDofVariable The variable associated with the degree of freedom to be added. + * @param rDofReaction The reaction associated with the degree of freedom to be added. + * @return A pointer to the added or existing DOF. + */ template inline typename DofType::Pointer pAddDof(TVariableType const& rDofVariable, TReactionType const& rDofReaction) { @@ -865,7 +888,15 @@ class Node } - /** adds a Dof to the node and return new added dof or existed one. */ + /** + * @brief Adds a degree of freedom (DOF) to the node, returning the newly added DOF or the existing one if it already exists. + * @details This function checks if the DOF for the given variable already exists in the node's DOF list. If it exists, + * it returns the existing DOF. Otherwise, it creates a new DOF for the given variable and adds it to the list. + * The DOF list is then sorted to maintain order. + * @tparam TVariableType The type of the variable associated with the degree of freedom. + * @param rDofVariable The variable associated with the degree of freedom to be added. + * @return A reference to the added or existing DOF. + */ template inline DofType& AddDof(TVariableType const& rDofVariable) { @@ -889,7 +920,17 @@ class Node } - /** adds a Dof to the node and return new added dof or existed one. */ + /** + * @brief Adds a degree of freedom (DOF) to the node, returning the newly added DOF or the existing one if it already exists, with a reaction. + * @details This function checks if the DOF for the given variable already exists in the node's DOF list. If it exists, + * it updates the reaction and returns the existing DOF. Otherwise, it creates a new DOF with both the variable + * and the reaction, and adds it to the list. The DOF list is then sorted to maintain order. + * @tparam TVariableType The type of the variable associated with the degree of freedom. + * @tparam TReactionType The type of the reaction associated with the degree of freedom. + * @param rDofVariable The variable associated with the degree of freedom to be added. + * @param rDofReaction The reaction associated with the degree of freedom to be added. + * @return A reference to the added or existing DOF. + */ template inline DofType& AddDof(TVariableType const& rDofVariable, TReactionType const& rDofReaction) { @@ -918,7 +959,13 @@ class Node ///@name Inquiry ///@{ - /** Return true if the dof of freedom is present on the node */ + /** + * @brief Checks if the degree of freedom (DOF) for a given variable is present on the node. + * @details This function iterates over the DOFs associated with the node and checks whether + * any of the DOFs correspond to the provided `rDofVariable`. + * @param rDofVariable The variable associated with the degree of freedom to be checked. + * @return `true` if the degree of freedom for the given variable is present, otherwise `false`. + */ inline bool HasDofFor(const VariableData& rDofVariable) const { for(auto it_dof = mDofs.begin() ; it_dof != mDofs.end() ; it_dof++){ @@ -929,6 +976,13 @@ class Node return false; } + /** + * @brief Checks if the degree of freedom (DOF) for a given variable is fixed on the node. + * @details This function iterates over the DOFs associated with the node and checks whether + * any of the DOFs corresponding to the given `rDofVariable` are marked as fixed. + * @param rDofVariable The variable associated with the degree of freedom to be checked. + * @return `true` if the degree of freedom for the given variable is fixed, otherwise `false`. + */ inline bool IsFixed(const VariableData& rDofVariable) const { for(auto it_dof = mDofs.begin() ; it_dof != mDofs.end() ; it_dof++){ @@ -1003,31 +1057,46 @@ class Node ///@name Member Variables ///@{ + /// The nodal data (historical variables) NodalData mNodalData; - /// storage for the dof of the node + /// Storage for the dof of the node DofsContainerType mDofs; - /// A pointer to data related to this node. + /// A container with data related to this node (non-historical variables) DataValueContainer mData; /// Initial Position of the node Point mInitialPosition; + /// The lock object of the node LockObject mNodeLock; ///@} ///@name Private Operators ///@{ - //this block is needed for refcounting + // This block is needed for refcounting mutable std::atomic mReferenceCounter{0}; + /** + * @brief Increments the reference counter of the given NodeType object. + * @details This function increments the reference counter of the NodeType object `x` + * by 1 using relaxed memory ordering. + * @param x Pointer to the NodeType object whose reference counter is to be incremented. + */ friend void intrusive_ptr_add_ref(const Node* x) { x->mReferenceCounter.fetch_add(1, std::memory_order_relaxed); } + /** + * @brief Decrements the reference counter of the given NodeType object and deletes it if zero. + * @details This function decrements the reference counter of the NodeType object `x` + * by 1 using release memory ordering. If the counter reaches zero after decrement, + * the function ensures memory visibility using acquire memory ordering and deletes `x`. + * @param x Pointer to the NodeType object whose reference counter is to be decremented. + */ friend void intrusive_ptr_release(const Node* x) { if (x->mReferenceCounter.fetch_sub(1, std::memory_order_release) == 1) { @@ -1036,6 +1105,12 @@ class Node } } + /** + * @brief Sorts the degrees of freedom (DOFs) based on their variable keys. + * @details This function sorts the `mDofs` container (which holds unique pointers to `DofType` objects) + * in ascending order of the keys of their associated variables. The sorting is done using + * the `std::sort` algorithm and compares the `Key()` of the `GetVariable()` for each DOF. + */ void SortDofs(); ///@} @@ -1048,8 +1123,16 @@ class Node friend class Serializer; + /** + * @brief The save operation which copies the database of the class + * @param rSerializer The serializer used to preserve the information + */ void save(Serializer& rSerializer) const override; + /** + * The load operation which restores the database of the class + * @param rSerializer The serializer used to preserve the information + */ void load(Serializer& rSerializer) override; ///@} From 6079718b41ea168ebfd513ee7092f05997b9edde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vicente=20Mataix=20Ferr=C3=A1ndiz?= Date: Fri, 7 Feb 2025 10:24:15 +0100 Subject: [PATCH 05/12] More doc --- kratos/includes/node.h | 105 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 103 insertions(+), 2 deletions(-) diff --git a/kratos/includes/node.h b/kratos/includes/node.h index 8874066501e3..fedab2957776 100755 --- a/kratos/includes/node.h +++ b/kratos/includes/node.h @@ -62,7 +62,7 @@ namespace Kratos * @author Pooyan Dadvand * @author Riccardo Rossi */ -class Node +class KRATOS_API(KRATOS_CORE) Node : public Point, public Flags { public: @@ -588,6 +588,14 @@ class Node ///@name Operations ///@{ + /** + * @brief Fix a Degree of Freedom (DoF) associated with a given variable. + * @details This function searches for the DoF corresponding to @p rDofVariable + * in the internal list of DoFs (@p mDofs) and fixes it if found. If the + * variable is not found, it adds a new DoF and fixes it. + * @tparam TVariableType Type of the variable associated with the DoF. + * @param rDofVariable Reference to the variable to fix. + */ template inline void Fix(const TVariableType& rDofVariable) { @@ -606,6 +614,14 @@ class Node pAddDof(rDofVariable)->FixDof(); } + /** + * @brief Free a Degree of Freedom (DoF) associated with a given variable. + * @details This function searches for the DoF corresponding to @p rDofVariable + * in the internal list of DoFs (@p mDofs) and frees it if found. If the + * variable is not found, it adds a new DoF and frees it. + * @tparam TVariableType Type of the variable associated with the DoF. + * @param rDofVariable Reference to the variable to free. + */ template inline void Free(const TVariableType& rDofVariable) { @@ -624,36 +640,110 @@ class Node pAddDof(rDofVariable)->FreeDof(); } + /** + * @brief Get the buffer size. + * @details This function returns the size of the buffer used for storing + * solution step data. + * @return IndexType The size of the buffer. + */ IndexType GetBufferSize() const; + /** + * @brief Set the buffer size. + * @details This function resizes the buffer used for storing solution step data + * to the given size @p NewBufferSize. + * @param NewBufferSize New size for the buffer. + */ void SetBufferSize(IndexType NewBufferSize); ///@} ///@name Access ///@{ + /** + * @brief Returns the initial position of the node (const version). + * @details This function provides read-only access to the initial position of the node. + * @return A const reference to the initial position of the node. + */ const Point& GetInitialPosition() const; + /** + * @brief Returns the initial position of the node (non-const version). + * @details This function provides access to the initial position of the node and allows modifications. + * @return A reference to the initial position of the node. + */ Point& GetInitialPosition(); + /** + * @brief Returns the X coordinate of the initial position. + * @details This function provides access to the X coordinate of the initial position and allows modifications. + * @return A reference to the X coordinate of the initial position. + */ double& X0(); + /** + * @brief Returns the Y coordinate of the initial position. + * @details This function provides access to the Y coordinate of the initial position and allows modifications. + * @return A reference to the Y coordinate of the initial position. + */ double& Y0(); + /** + * @brief Returns the Z coordinate of the initial position. + * @details This function provides access to the Z coordinate of the initial position and allows modifications. + * @return A reference to the Z coordinate of the initial position. + */ double& Z0(); + /** + * @brief Returns the X coordinate of the initial position (const version). + * @details This function provides read-only access to the X coordinate of the initial position. + * @return The X coordinate of the initial position. + */ double X0() const; + /** + * @brief Returns the Y coordinate of the initial position (const version). + * @details This function provides read-only access to the Y coordinate of the initial position. + * @return The Y coordinate of the initial position. + */ double Y0() const; + /** + * @brief Returns the Z coordinate of the initial position (const version). + * @details This function provides read-only access to the Z coordinate of the initial position. + * @return The Z coordinate of the initial position. + */ double Z0() const; + /** + * @brief Sets the initial position of the node using a PointType. + * @details This function sets the initial position of the node by copying the values from the given `NewInitialPosition`. + * @param NewInitialPosition The new initial position to be set. + */ void SetInitialPosition(const Point& NewInitialPosition); + /** + * @brief Sets the initial position of the node using X, Y, and Z coordinates. + * @details This function sets the initial position of the node by directly assigning values to the X, Y, and Z coordinates. + * @param X The X coordinate of the new initial position. + * @param Y The Y coordinate of the new initial position. + * @param Z The Z coordinate of the new initial position. + */ void SetInitialPosition(double X,double Y, double Z); + /** + * @brief Returns the pointer to the list of variables associated with the node. + * @details This function provides access to the list of variables for the current solution step. + * @return A pointer to the list of variables. + */ VariablesList::Pointer pGetVariablesList(); + /** + * @brief Returns the pointer to the list of variables associated with the node (const version). + * @details This function provides read-only access to the list of variables for the current solution step. + * @return A const pointer to the list of variables. + */ const VariablesList::Pointer pGetVariablesList() const; ///@} @@ -731,9 +821,20 @@ class Node } - /** returns all of the Dofs */ + /** + * @brief Returns all the degrees of freedom (DOFs) associated with the node. + * @details This function provides access to the container holding all the degrees of freedom + * (DOFs) for the node. The returned container is mutable, allowing modifications to the DOFs. + * @return A reference to the container of DOFs. + */ DofsContainerType& GetDofs(); + /** + * @brief Returns all the degrees of freedom (DOFs) associated with the node (const version). + * @details This function provides a read-only access to the container holding all the degrees of freedom + * (DOFs) for the node. The returned container cannot be modified. + * @return A const reference to the container of DOFs. + */ const DofsContainerType& GetDofs() const; /** From 06181244771aa7320943ef969b34c9a60d8394df Mon Sep 17 00:00:00 2001 From: Vicente Mataix Ferrandiz Date: Fri, 7 Feb 2025 11:39:49 +0100 Subject: [PATCH 06/12] Update documentation for clarity and completeness --- kratos/sources/node.cpp | 160 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 150 insertions(+), 10 deletions(-) diff --git a/kratos/sources/node.cpp b/kratos/sources/node.cpp index 8f36422aeb28..a04784f79532 100644 --- a/kratos/sources/node.cpp +++ b/kratos/sources/node.cpp @@ -23,7 +23,6 @@ namespace Kratos { -/// Default constructor. Node::Node() : BaseType() , Flags() @@ -36,7 +35,9 @@ Node::Node() CreateSolutionStepData(); } -/// 1d constructor. +/***********************************************************************************/ +/***********************************************************************************/ + Node::Node(IndexType NewId, const double NewX) : BaseType(NewX) , Flags() @@ -49,7 +50,9 @@ Node::Node(IndexType NewId, const double NewX) CreateSolutionStepData(); } -/// 2d constructor. +/***********************************************************************************/ +/***********************************************************************************/ + Node::Node(IndexType NewId, const double NewX, const double NewY) : BaseType(NewX, NewY) , Flags() @@ -62,7 +65,9 @@ Node::Node(IndexType NewId, const double NewX, const double NewY) CreateSolutionStepData(); } -/// 3d constructor. +/***********************************************************************************/ +/***********************************************************************************/ + Node::Node(IndexType NewId, const double NewX, const double NewY, const double NewZ) : BaseType(NewX, NewY, NewZ) , Flags() @@ -75,7 +80,9 @@ Node::Node(IndexType NewId, const double NewX, const double NewY, const double N CreateSolutionStepData(); } -/// Point constructor. +/***********************************************************************************/ +/***********************************************************************************/ + Node::Node(IndexType NewId, Point const& rThisPoint) : BaseType(rThisPoint) , Flags() @@ -88,6 +95,9 @@ Node::Node(IndexType NewId, Point const& rThisPoint) CreateSolutionStepData(); } +/***********************************************************************************/ +/***********************************************************************************/ + Node::Node(IndexType NewId, std::vector const& rOtherCoordinates) : BaseType(rOtherCoordinates) , Flags() @@ -100,7 +110,9 @@ Node::Node(IndexType NewId, std::vector const& rOtherCoordinates) CreateSolutionStepData(); } -/// 3d with variables list and data constructor. +/***********************************************************************************/ +/***********************************************************************************/ + Node::Node(IndexType NewId, const double NewX, const double NewY, const double NewZ, VariablesList::Pointer pVariablesList, BlockType const * ThisData, SizeType NewQueueSize = 1) : BaseType(NewX, NewY, NewZ) , Flags() @@ -112,6 +124,9 @@ Node::Node(IndexType NewId, const double NewX, const double NewY, const double N { } +/***********************************************************************************/ +/***********************************************************************************/ + typename Node::Pointer Node::Clone() { Node::Pointer p_new_node = Kratos::make_intrusive( this->Id(), (*this)[0], (*this)[1], (*this)[2]); @@ -130,32 +145,49 @@ typename Node::Pointer Node::Clone() return p_new_node; } -/// Destructor. +/***********************************************************************************/ +/***********************************************************************************/ + Node::~Node() { ClearSolutionStepsData(); } +/***********************************************************************************/ +/***********************************************************************************/ + Node::IndexType Node::Id() const { return mNodalData.Id(); } +/***********************************************************************************/ +/***********************************************************************************/ + Node::IndexType Node::GetId() const { return mNodalData.Id(); } +/***********************************************************************************/ +/***********************************************************************************/ + void Node::SetId(IndexType NewId) { mNodalData.SetId(NewId); } +/***********************************************************************************/ +/***********************************************************************************/ + LockObject& Node::GetLock() { return mNodeLock; } +/***********************************************************************************/ +/***********************************************************************************/ + Node& Node::operator=(const Node& rOther) { BaseType::operator=(rOther); @@ -174,127 +206,201 @@ Node& Node::operator=(const Node& rOther) return *this; } +/***********************************************************************************/ +/***********************************************************************************/ + bool Node::operator==(const Node& rOther) { return Point::operator ==(rOther); } +/***********************************************************************************/ +/***********************************************************************************/ + double& Node::operator[](IndexType ThisIndex) { return BaseType::operator[](ThisIndex); } +/***********************************************************************************/ +/***********************************************************************************/ + double Node::operator[](IndexType ThisIndex) const { return BaseType::operator[](ThisIndex); } +/***********************************************************************************/ +/***********************************************************************************/ + void Node::CreateSolutionStepData() { SolutionStepData().PushFront(); } +/***********************************************************************************/ +/***********************************************************************************/ + void Node::CloneSolutionStepData() { SolutionStepData().CloneFront(); } +/***********************************************************************************/ +/***********************************************************************************/ + void Node::OverwriteSolutionStepData(IndexType SourceSolutionStepIndex, IndexType DestinationSourceSolutionStepIndex) { SolutionStepData().AssignData(SolutionStepData().Data(SourceSolutionStepIndex), DestinationSourceSolutionStepIndex); } +/***********************************************************************************/ +/***********************************************************************************/ + void Node::ClearSolutionStepsData() { SolutionStepData().Clear(); } +/***********************************************************************************/ +/***********************************************************************************/ + void Node::SetSolutionStepVariablesList(VariablesList::Pointer pVariablesList) { SolutionStepData().SetVariablesList(pVariablesList); } +/***********************************************************************************/ +/***********************************************************************************/ + VariablesListDataValueContainer& Node::SolutionStepData() { return mNodalData.GetSolutionStepData(); } +/***********************************************************************************/ +/***********************************************************************************/ + const VariablesListDataValueContainer& Node::SolutionStepData() const { return mNodalData.GetSolutionStepData(); } +/***********************************************************************************/ +/***********************************************************************************/ + DataValueContainer& Node::Data() { return mData; } +/***********************************************************************************/ +/***********************************************************************************/ + DataValueContainer& Node::GetData() { return mData; } +/***********************************************************************************/ +/***********************************************************************************/ + const DataValueContainer& Node::GetData() const { return mData; } +/***********************************************************************************/ +/***********************************************************************************/ + bool Node::SolutionStepsDataHas(const VariableData& rThisVariable) const { return SolutionStepData().Has(rThisVariable); } +/***********************************************************************************/ +/***********************************************************************************/ IndexType Node::GetBufferSize() const { return SolutionStepData().QueueSize(); } +/***********************************************************************************/ +/***********************************************************************************/ + void Node::SetBufferSize(IndexType NewBufferSize) { SolutionStepData().Resize(NewBufferSize); } +/***********************************************************************************/ +/***********************************************************************************/ + const Point& Node::GetInitialPosition() const { return mInitialPosition; } +/***********************************************************************************/ +/***********************************************************************************/ + Point& Node::GetInitialPosition() { return mInitialPosition; } +/***********************************************************************************/ +/***********************************************************************************/ + double& Node::X0() { return mInitialPosition.X(); } +/***********************************************************************************/ +/***********************************************************************************/ + double& Node::Y0() { return mInitialPosition.Y(); } +/***********************************************************************************/ +/***********************************************************************************/ + double& Node::Z0() { return mInitialPosition.Z(); } +/***********************************************************************************/ +/***********************************************************************************/ + double Node::X0() const { return mInitialPosition.X(); } +/***********************************************************************************/ +/***********************************************************************************/ + double Node::Y0() const { return mInitialPosition.Y(); } +/***********************************************************************************/ +/***********************************************************************************/ + double Node::Z0() const { return mInitialPosition.Z(); } +/***********************************************************************************/ +/***********************************************************************************/ + void Node::SetInitialPosition(const Point& NewInitialPosition) { mInitialPosition.X() = NewInitialPosition.X(); @@ -302,6 +408,9 @@ void Node::SetInitialPosition(const Point& NewInitialPosition) mInitialPosition.Z() = NewInitialPosition.Z(); } +/***********************************************************************************/ +/***********************************************************************************/ + void Node::SetInitialPosition(double X,double Y, double Z) { mInitialPosition.X() = X; @@ -309,26 +418,41 @@ void Node::SetInitialPosition(double X,double Y, double Z) mInitialPosition.Z() = Z; } +/***********************************************************************************/ +/***********************************************************************************/ + VariablesList::Pointer Node::pGetVariablesList() { return SolutionStepData().pGetVariablesList(); } +/***********************************************************************************/ +/***********************************************************************************/ + const VariablesList::Pointer Node::pGetVariablesList() const { return SolutionStepData().pGetVariablesList(); } -DofsContainerType& Node::GetDofs() +/***********************************************************************************/ +/***********************************************************************************/ + +Node::DofsContainerType& Node::GetDofs() { return mDofs; } -const DofsContainerType& Node::GetDofs() const +/***********************************************************************************/ +/***********************************************************************************/ + +const Node::DofsContainerType& Node::GetDofs() const { return mDofs; } +/***********************************************************************************/ +/***********************************************************************************/ + std::string Node::Info() const { std::stringstream buffer; @@ -336,11 +460,17 @@ std::string Node::Info() const return buffer.str(); } +/***********************************************************************************/ +/***********************************************************************************/ + void Node::PrintInfo(std::ostream& rOStream) const { rOStream << Info(); } +/***********************************************************************************/ +/***********************************************************************************/ + void Node::PrintData(std::ostream& rOStream) const { BaseType::PrintData(rOStream); @@ -350,12 +480,19 @@ void Node::PrintData(std::ostream& rOStream) const rOStream << " " << (*i)->Info() << std::endl; } -void Node::SortDofs(){ +/***********************************************************************************/ +/***********************************************************************************/ + +void Node::SortDofs() +{ std::sort(mDofs.begin(), mDofs.end(), [](Kratos::unique_ptr const& First, Kratos::unique_ptr const& Second)->bool{ return First->GetVariable().Key() < Second->GetVariable().Key(); }); } +/***********************************************************************************/ +/***********************************************************************************/ + void Node::save(Serializer& rSerializer) const { KRATOS_SERIALIZE_SAVE_BASE_CLASS(rSerializer, Point ); @@ -367,6 +504,9 @@ void Node::save(Serializer& rSerializer) const } +/***********************************************************************************/ +/***********************************************************************************/ + void Node::load(Serializer& rSerializer) { KRATOS_SERIALIZE_LOAD_BASE_CLASS(rSerializer, Point ); From d957153f14154516dfc8c72abb1149ac931d5037 Mon Sep 17 00:00:00 2001 From: Vicente Mataix Ferrandiz Date: Fri, 7 Feb 2025 12:33:41 +0100 Subject: [PATCH 07/12] Refactor Node class: add PointType definition and clean up constructor parameters --- kratos/includes/node.h | 5 ++++- kratos/sources/node.cpp | 4 +--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/kratos/includes/node.h b/kratos/includes/node.h index fedab2957776..17be27768675 100755 --- a/kratos/includes/node.h +++ b/kratos/includes/node.h @@ -62,7 +62,7 @@ namespace Kratos * @author Pooyan Dadvand * @author Riccardo Rossi */ -class KRATOS_API(KRATOS_CORE) Node +class KRATOS_API(KRATOS_CORE) Node : public Point, public Flags { public: @@ -75,6 +75,9 @@ class KRATOS_API(KRATOS_CORE) Node /// Base type using BaseType = Point; + /// Point type definition + using PointType = Point; + /// Dof type using DofType = Dof; diff --git a/kratos/sources/node.cpp b/kratos/sources/node.cpp index a04784f79532..cb72606e65a4 100644 --- a/kratos/sources/node.cpp +++ b/kratos/sources/node.cpp @@ -11,8 +11,6 @@ // Riccardo Rossi // -#pragma once - // System includes // External includes @@ -113,7 +111,7 @@ Node::Node(IndexType NewId, std::vector const& rOtherCoordinates) /***********************************************************************************/ /***********************************************************************************/ -Node::Node(IndexType NewId, const double NewX, const double NewY, const double NewZ, VariablesList::Pointer pVariablesList, BlockType const * ThisData, SizeType NewQueueSize = 1) +Node::Node(IndexType NewId, const double NewX, const double NewY, const double NewZ, VariablesList::Pointer pVariablesList, BlockType const * ThisData, SizeType NewQueueSize) : BaseType(NewX, NewY, NewZ) , Flags() , mNodalData(NewId, pVariablesList,ThisData,NewQueueSize) From b27f1326cbd7d30d651c39b7988d78019c4128e0 Mon Sep 17 00:00:00 2001 From: Vicente Mataix Ferrandiz Date: Fri, 7 Feb 2025 13:51:58 +0100 Subject: [PATCH 08/12] Add overloaded Node constructor with error handling and initialization --- kratos/includes/node.h | 150 ++++++++++++++++++++++++---------------- kratos/sources/node.cpp | 16 +++++ 2 files changed, 105 insertions(+), 61 deletions(-) diff --git a/kratos/includes/node.h b/kratos/includes/node.h index 17be27768675..c1da722c9df5 100755 --- a/kratos/includes/node.h +++ b/kratos/includes/node.h @@ -100,42 +100,63 @@ class KRATOS_API(KRATOS_CORE) Node ///@name Life Cycle ///@{ - /// Default constructor. + /** + * @brief @brief Default constructor. + */ Node(); - explicit Node(IndexType NewId ) - : BaseType() - , Flags() - , mNodalData(NewId) - , mDofs() - , mData() - , mInitialPosition() - , mNodeLock() - { - KRATOS_ERROR << "Calling the default constructor for the node ... illegal operation!!" << std::endl; - CreateSolutionStepData(); - } + /** + * @brief Constructor with a given node ID. + * @param NewId The unique index identifier of the node. + */ + explicit Node(IndexType NewId); - /// 1d constructor. + /** + * @brief Constructor for a 1D node. + * @param NewId The unique index identifier of the node. + * @param NewX The X-coordinate of the node. + */ Node(IndexType NewId, const double NewX); - /// 2d constructor. + /** + * @brief Constructor for a 2D node. + * @param NewId The unique index identifier of the node. + * @param NewX The X-coordinate of the node. + * @param NewY The Y-coordinate of the node. + */ Node(IndexType NewId, const double NewX, const double NewY); - /// 3d constructor. + /** + * @brief Constructor for a 3D node. + * @param NewId The unique index identifier of the node. + * @param NewX The X-coordinate of the node. + * @param NewY The Y-coordinate of the node. + * @param NewZ The Z-coordinate of the node. + */ Node(IndexType NewId, const double NewX, const double NewY, const double NewZ); - /// Point constructor. + /** + * @brief Constructor from an existing point. + * @param NewId The unique index identifier of the node. + * @param rThisPoint The point from which to initialize the node. + */ Node(IndexType NewId, Point const& rThisPoint); - /** Copy constructor. Initialize this node with given node.*/ + /** + * @brief Deleted copy constructor to prevent copying. + * @param rOtherNode The node to copy from (deleted). + */ Node(Node const& rOtherNode) = delete; /** - * Constructor using coordinates stored in given array. Initialize - this point with the coordinates in the array. */ + * @brief Constructor using coordinates stored in a vector expression. + * @details Initializes the node with the coordinates in the given vector. + * @tparam TVectorType The type of the vector expression. + * @param NewId The unique index identifier of the node. + * @param rOtherCoordinates The vector expression containing the node coordinates. + */ template - Node(IndexType NewId, vector_expression const& rOtherCoordinates) + Node(IndexType NewId, vector_expression const& rOtherCoordinates) : BaseType(rOtherCoordinates) , Flags() , mNodalData(NewId) @@ -147,12 +168,25 @@ class KRATOS_API(KRATOS_CORE) Node CreateSolutionStepData(); } - /** Constructor using coordinates stored in given std::vector. Initialize - this point with the coordinates in the array. */ - Node(IndexType NewId, std::vector const& rOtherCoordinates); + /** + * @brief Constructor using coordinates stored in a standard vector. + * @param NewId The unique index identifier of the node. + * @param rOtherCoordinates The std::vector containing the node coordinates. + */ + Node(IndexType NewId, std::vector const& rOtherCoordinates); - /// 3d with variables list and data constructor. - Node(IndexType NewId, const double NewX, const double NewY, const double NewZ, VariablesList::Pointer pVariablesList, BlockType const * ThisData, SizeType NewQueueSize = 1); + /** + * @brief Constructor for a 3D node with variables list and data. + * @param NewId The unique index identifier of the node. + * @param NewX The X-coordinate of the node. + * @param NewY The Y-coordinate of the node. + * @param NewZ The Z-coordinate of the node. + * @param pVariablesList Pointer to the variables list associated with the node. + * @param ThisData Pointer to the data block associated with the node. + * @param NewQueueSize The queue size for storing historical data (default = 1). + */ + Node(IndexType NewId, const double NewX, const double NewY, const double NewZ, + VariablesList::Pointer pVariablesList, BlockType const * ThisData, SizeType NewQueueSize = 1); /** * @brief Creates a clone of the current node. @@ -245,7 +279,7 @@ class KRATOS_API(KRATOS_CORE) Node * @param SolutionStepIndex The solution step index. * @return Reference to the stored value. */ - template + template typename TVariableType::Type& operator()(const TVariableType& rThisVariable, IndexType SolutionStepIndex) { return GetSolutionStepValue(rThisVariable, SolutionStepIndex); @@ -257,7 +291,7 @@ class KRATOS_API(KRATOS_CORE) Node * @param rThisVariable The variable to access. * @return Reference to the stored value. */ - template + template typename TVariableType::Type& operator()(const TVariableType& rThisVariable) { return GetSolutionStepValue(rThisVariable); @@ -269,7 +303,7 @@ class KRATOS_API(KRATOS_CORE) Node * @param rThisVariable The variable representing the data. * @return Reference to the stored data. */ - template + template TDataType& operator[](const Variable& rThisVariable) { return GetValue(rThisVariable); @@ -281,7 +315,7 @@ class KRATOS_API(KRATOS_CORE) Node * @param rThisVariable The variable representing the data. * @return Const reference to the stored data. */ - template + template const TDataType& operator[](const Variable& rThisVariable) const { return GetValue(rThisVariable); @@ -376,7 +410,7 @@ class KRATOS_API(KRATOS_CORE) Node * @param rThisVariable The variable whose value is to be retrieved. * @return Reference to the stored value. */ - template + template typename TVariableType::Type& GetSolutionStepValue(const TVariableType& rThisVariable) { return SolutionStepData().GetValue(rThisVariable); @@ -388,7 +422,7 @@ class KRATOS_API(KRATOS_CORE) Node * @param rThisVariable The variable whose value is to be retrieved. * @return Const reference to the stored value. */ - template + template typename TVariableType::Type const& GetSolutionStepValue(const TVariableType& rThisVariable) const { return SolutionStepData().GetValue(rThisVariable); @@ -401,7 +435,7 @@ class KRATOS_API(KRATOS_CORE) Node * @param SolutionStepIndex The index of the solution step. * @return Reference to the stored value. */ - template + template typename TVariableType::Type& GetSolutionStepValue(const TVariableType& rThisVariable, IndexType SolutionStepIndex) { return SolutionStepData().GetValue(rThisVariable, SolutionStepIndex); @@ -414,7 +448,7 @@ class KRATOS_API(KRATOS_CORE) Node * @param SolutionStepIndex The index of the solution step. * @return Const reference to the stored value. */ - template + template typename TVariableType::Type const& GetSolutionStepValue(const TVariableType& rThisVariable, IndexType SolutionStepIndex) const { return SolutionStepData().GetValue(rThisVariable, SolutionStepIndex); @@ -433,7 +467,7 @@ class KRATOS_API(KRATOS_CORE) Node * @param rThisVariable The variable whose value is to be retrieved. * @return Reference to the stored value. */ - template + template typename TVariableType::Type& FastGetSolutionStepValue(const TVariableType& rThisVariable) { return SolutionStepData().FastGetValue(rThisVariable); @@ -445,7 +479,7 @@ class KRATOS_API(KRATOS_CORE) Node * @param rThisVariable The variable whose value is to be retrieved. * @return Const reference to the stored value. */ - template + template const typename TVariableType::Type& FastGetSolutionStepValue(const TVariableType& rThisVariable) const { return SolutionStepData().FastGetValue(rThisVariable); @@ -458,7 +492,7 @@ class KRATOS_API(KRATOS_CORE) Node * @param SolutionStepIndex The index of the solution step. * @return Reference to the stored value. */ - template + template typename TVariableType::Type& FastGetSolutionStepValue(const TVariableType& rThisVariable, IndexType SolutionStepIndex) { return SolutionStepData().FastGetValue(rThisVariable, SolutionStepIndex); @@ -471,7 +505,7 @@ class KRATOS_API(KRATOS_CORE) Node * @param SolutionStepIndex The index of the solution step. * @return Const reference to the stored value. */ - template + template const typename TVariableType::Type& FastGetSolutionStepValue(const TVariableType& rThisVariable, IndexType SolutionStepIndex) const { return SolutionStepData().FastGetValue(rThisVariable, SolutionStepIndex); @@ -485,7 +519,7 @@ class KRATOS_API(KRATOS_CORE) Node * @param ThisPosition The position in the solution step data. * @return Reference to the stored value. */ - template + template typename TVariableType::Type& FastGetSolutionStepValue(const TVariableType& rThisVariable, IndexType SolutionStepIndex, IndexType ThisPosition) { return SolutionStepData().FastGetValue(rThisVariable, SolutionStepIndex, ThisPosition); @@ -498,7 +532,7 @@ class KRATOS_API(KRATOS_CORE) Node * @param ThisPosition The position in the solution step data. * @return Reference to the stored value. */ - template + template typename TVariableType::Type& FastGetCurrentSolutionStepValue(const TVariableType& rThisVariable, IndexType ThisPosition) { return SolutionStepData().FastGetCurrentValue(rThisVariable, ThisPosition); @@ -510,7 +544,7 @@ class KRATOS_API(KRATOS_CORE) Node * @param rThisVariable The variable whose value is to be retrieved. * @return Reference to the stored value. */ - template + template typename TVariableType::Type& GetValue(const TVariableType& rThisVariable) { return mData.GetValue(rThisVariable); @@ -522,7 +556,7 @@ class KRATOS_API(KRATOS_CORE) Node * @param rThisVariable The variable whose value is to be retrieved. * @return Const reference to the stored value. */ - template + template typename TVariableType::Type const& GetValue(const TVariableType& rThisVariable) const { return mData.GetValue(rThisVariable); @@ -536,7 +570,7 @@ class KRATOS_API(KRATOS_CORE) Node * @param SolutionStepIndex The solution step index. * @return Reference to the value of the variable. */ - template + template typename TVariableType::Type& GetValue(const TVariableType& rThisVariable, IndexType SolutionStepIndex) { if(!mData.Has(rThisVariable)) @@ -553,7 +587,7 @@ class KRATOS_API(KRATOS_CORE) Node * @param SolutionStepIndex The solution step index. * @return Const reference to the value of the variable. */ - template + template typename TVariableType::Type const& GetValue(const TVariableType& rThisVariable, IndexType SolutionStepIndex) const { if(!mData.Has(rThisVariable)) @@ -581,7 +615,7 @@ class KRATOS_API(KRATOS_CORE) Node * @param rThisVariable The variable to check. * @return True if the variable exists, false otherwise. */ - template + template bool Has(const Variable& rThisVariable) const { return mData.Has(rThisVariable); @@ -690,7 +724,7 @@ class KRATOS_API(KRATOS_CORE) Node * @return A reference to the Y coordinate of the initial position. */ double& Y0(); - + /** * @brief Returns the Z coordinate of the initial position. * @details This function provides access to the Z coordinate of the initial position and allows modifications. @@ -704,14 +738,14 @@ class KRATOS_API(KRATOS_CORE) Node * @return The X coordinate of the initial position. */ double X0() const; - + /** * @brief Returns the Y coordinate of the initial position (const version). * @details This function provides read-only access to the Y coordinate of the initial position. * @return The Y coordinate of the initial position. */ double Y0() const; - + /** * @brief Returns the Z coordinate of the initial position (const version). * @details This function provides read-only access to the Z coordinate of the initial position. @@ -782,15 +816,13 @@ class KRATOS_API(KRATOS_CORE) Node template inline const DofType& GetDof(TVariableType const& rDofVariable, int pos) const { - typename DofsContainerType::const_iterator it_begin = mDofs.begin(); - typename DofsContainerType::const_iterator it_end = mDofs.end(); + auto it_begin = mDofs.begin(); + auto it_end = mDofs.end(); typename DofsContainerType::const_iterator it; - //if the guess is exact return the guess - if(pos < it_end-it_begin) - { + // If the guess is exact return the guess + if(pos < it_end-it_begin) { it = it_begin + pos; - if( (*it)->GetVariable() == rDofVariable) - { + if( (*it)->GetVariable() == rDofVariable) { return **it; } } @@ -856,7 +888,6 @@ class KRATOS_API(KRATOS_CORE) Node } KRATOS_ERROR << "Non-existent DOF in node #" << Id() << " for variable : " << rDofVariable.Name() << std::endl; - } /** @@ -989,7 +1020,6 @@ class KRATOS_API(KRATOS_CORE) Node return p_new_dof; KRATOS_CATCH(*this); - } /** @@ -1021,7 +1051,6 @@ class KRATOS_API(KRATOS_CORE) Node return *p_new_dof; KRATOS_CATCH(*this); - } /** @@ -1056,7 +1085,6 @@ class KRATOS_API(KRATOS_CORE) Node return *p_new_dof; KRATOS_CATCH(*this); - } ///@} @@ -1087,7 +1115,7 @@ class KRATOS_API(KRATOS_CORE) Node * @param rDofVariable The variable associated with the degree of freedom to be checked. * @return `true` if the degree of freedom for the given variable is fixed, otherwise `false`. */ - inline bool IsFixed(const VariableData& rDofVariable) const + inline bool IsFixed(const VariableData& rDofVariable) const { for(auto it_dof = mDofs.begin() ; it_dof != mDofs.end() ; it_dof++){ if((*it_dof)->GetVariable() == rDofVariable){ @@ -1285,4 +1313,4 @@ inline std::ostream& operator << (std::ostream& rOStream, } ///@} -} // namespace Kratos. +} // namespace Kratos. \ No newline at end of file diff --git a/kratos/sources/node.cpp b/kratos/sources/node.cpp index cb72606e65a4..de1956600376 100644 --- a/kratos/sources/node.cpp +++ b/kratos/sources/node.cpp @@ -36,6 +36,22 @@ Node::Node() /***********************************************************************************/ /***********************************************************************************/ +Node::Node(IndexType NewId ) + : BaseType() + , Flags() + , mNodalData(NewId) + , mDofs() + , mData() + , mInitialPosition() + , mNodeLock() +{ + KRATOS_ERROR << "Calling the default constructor for the node ... illegal operation!!" << std::endl; + CreateSolutionStepData(); +} + +/***********************************************************************************/ +/***********************************************************************************/ + Node::Node(IndexType NewId, const double NewX) : BaseType(NewX) , Flags() From 1e5f4314ffb372f6e41c6b85e0dc11f9fcdc908e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vicente=20Mataix=20Ferr=C3=A1ndiz?= Date: Fri, 7 Feb 2025 22:52:29 +0100 Subject: [PATCH 09/12] Suggestion --- kratos/includes/node.h | 75 ++++++++++++++++++++----- kratos/sources/node.cpp | 120 ---------------------------------------- 2 files changed, 60 insertions(+), 135 deletions(-) diff --git a/kratos/includes/node.h b/kratos/includes/node.h index c1da722c9df5..74d53ca04e19 100755 --- a/kratos/includes/node.h +++ b/kratos/includes/node.h @@ -216,25 +216,37 @@ class KRATOS_API(KRATOS_CORE) Node * @brief Retrieves the node ID. * @return The ID of the node. */ - IndexType Id() const; + IndexType Id() const + { + return mNodalData.Id(); + } /** * @brief Retrieves the node ID (alternative method). * @return The ID of the node. */ - IndexType GetId() const; + IndexType GetId() const + { + return mNodalData.Id(); + } /** * @brief Sets a new ID for the node. * @param NewId The new ID to assign. */ - void SetId(IndexType NewId); + void SetId(IndexType NewId) + { + mNodalData.SetId(NewId); + } /** * @brief Retrieves the lock object for thread safety. * @return A reference to the lock object. */ - LockObject& GetLock(); + LockObject& GetLock() + { + return mNodeLock; + } /** * @brief Locks the node for thread-safe operations. @@ -390,19 +402,28 @@ class KRATOS_API(KRATOS_CORE) Node * @return Reference to the data container. */ KRATOS_DEPRECATED_MESSAGE("This method is deprecated. Use 'GetData()' instead.") - DataValueContainer& Data(); + DataValueContainer& Data() + { + return mData; + } /** * @brief Retrieves the data container for the node. * @return Reference to the data container. */ - DataValueContainer& GetData(); + DataValueContainer& GetData() + { + return mData; + } /** * @brief Retrieves the data container for the node (const version). * @return Const reference to the data container. */ - const DataValueContainer& GetData() const; + const DataValueContainer& GetData() const + { + return mData; + } /** * @brief Retrieves the solution step value for a given variable. @@ -702,56 +723,80 @@ class KRATOS_API(KRATOS_CORE) Node * @details This function provides read-only access to the initial position of the node. * @return A const reference to the initial position of the node. */ - const Point& GetInitialPosition() const; + const Point& GetInitialPosition() const + { + return mInitialPosition; + } /** * @brief Returns the initial position of the node (non-const version). * @details This function provides access to the initial position of the node and allows modifications. * @return A reference to the initial position of the node. */ - Point& GetInitialPosition(); + Point& GetInitialPosition() + { + return mInitialPosition; + } /** * @brief Returns the X coordinate of the initial position. * @details This function provides access to the X coordinate of the initial position and allows modifications. * @return A reference to the X coordinate of the initial position. */ - double& X0(); + double& X0() + { + return mInitialPosition.X(); + } /** * @brief Returns the Y coordinate of the initial position. * @details This function provides access to the Y coordinate of the initial position and allows modifications. * @return A reference to the Y coordinate of the initial position. */ - double& Y0(); + double& Y0() + { + return mInitialPosition.Y(); + } /** * @brief Returns the Z coordinate of the initial position. * @details This function provides access to the Z coordinate of the initial position and allows modifications. * @return A reference to the Z coordinate of the initial position. */ - double& Z0(); + double& Z0() + { + return mInitialPosition.Z(); + } /** * @brief Returns the X coordinate of the initial position (const version). * @details This function provides read-only access to the X coordinate of the initial position. * @return The X coordinate of the initial position. */ - double X0() const; + double X0() const + { + return mInitialPosition.X(); + } /** * @brief Returns the Y coordinate of the initial position (const version). * @details This function provides read-only access to the Y coordinate of the initial position. * @return The Y coordinate of the initial position. */ - double Y0() const; + double Y0() const + { + return mInitialPosition.Y(); + } /** * @brief Returns the Z coordinate of the initial position (const version). * @details This function provides read-only access to the Z coordinate of the initial position. * @return The Z coordinate of the initial position. */ - double Z0() const; + double Z0() const + { + return mInitialPosition.Z(); + } /** * @brief Sets the initial position of the node using a PointType. diff --git a/kratos/sources/node.cpp b/kratos/sources/node.cpp index de1956600376..faf4c8d92d51 100644 --- a/kratos/sources/node.cpp +++ b/kratos/sources/node.cpp @@ -170,38 +170,6 @@ Node::~Node() /***********************************************************************************/ /***********************************************************************************/ -Node::IndexType Node::Id() const -{ - return mNodalData.Id(); -} - -/***********************************************************************************/ -/***********************************************************************************/ - -Node::IndexType Node::GetId() const -{ - return mNodalData.Id(); -} - -/***********************************************************************************/ -/***********************************************************************************/ - -void Node::SetId(IndexType NewId) -{ - mNodalData.SetId(NewId); -} - -/***********************************************************************************/ -/***********************************************************************************/ - -LockObject& Node::GetLock() -{ - return mNodeLock; -} - -/***********************************************************************************/ -/***********************************************************************************/ - Node& Node::operator=(const Node& rOther) { BaseType::operator=(rOther); @@ -303,30 +271,6 @@ const VariablesListDataValueContainer& Node::SolutionStepData() const /***********************************************************************************/ /***********************************************************************************/ -DataValueContainer& Node::Data() -{ - return mData; -} - -/***********************************************************************************/ -/***********************************************************************************/ - -DataValueContainer& Node::GetData() -{ - return mData; -} - -/***********************************************************************************/ -/***********************************************************************************/ - -const DataValueContainer& Node::GetData() const -{ - return mData; -} - -/***********************************************************************************/ -/***********************************************************************************/ - bool Node::SolutionStepsDataHas(const VariableData& rThisVariable) const { return SolutionStepData().Has(rThisVariable); @@ -351,70 +295,6 @@ void Node::SetBufferSize(IndexType NewBufferSize) /***********************************************************************************/ /***********************************************************************************/ -const Point& Node::GetInitialPosition() const -{ - return mInitialPosition; -} - -/***********************************************************************************/ -/***********************************************************************************/ - -Point& Node::GetInitialPosition() -{ - return mInitialPosition; -} - -/***********************************************************************************/ -/***********************************************************************************/ - -double& Node::X0() -{ - return mInitialPosition.X(); -} - -/***********************************************************************************/ -/***********************************************************************************/ - -double& Node::Y0() -{ - return mInitialPosition.Y(); -} - -/***********************************************************************************/ -/***********************************************************************************/ - -double& Node::Z0() -{ - return mInitialPosition.Z(); -} - -/***********************************************************************************/ -/***********************************************************************************/ - -double Node::X0() const -{ - return mInitialPosition.X(); -} - -/***********************************************************************************/ -/***********************************************************************************/ - -double Node::Y0() const -{ - return mInitialPosition.Y(); -} - -/***********************************************************************************/ -/***********************************************************************************/ - -double Node::Z0() const -{ - return mInitialPosition.Z(); -} - -/***********************************************************************************/ -/***********************************************************************************/ - void Node::SetInitialPosition(const Point& NewInitialPosition) { mInitialPosition.X() = NewInitialPosition.X(); From 064eb3acc873629faa0259945ac11d322bd334af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vicente=20Mataix=20Ferr=C3=A1ndiz?= Date: Sun, 9 Feb 2025 19:03:41 +0100 Subject: [PATCH 10/12] `Node` as final --- kratos/includes/node.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kratos/includes/node.h b/kratos/includes/node.h index 74d53ca04e19..107ec31509ba 100755 --- a/kratos/includes/node.h +++ b/kratos/includes/node.h @@ -62,7 +62,7 @@ namespace Kratos * @author Pooyan Dadvand * @author Riccardo Rossi */ -class KRATOS_API(KRATOS_CORE) Node +class KRATOS_API(KRATOS_CORE) Node final : public Point, public Flags { public: From 07c15f54a99071a498d22893e0c732cc55e20185 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vicente=20Mataix=20Ferr=C3=A1ndiz?= Date: Wed, 26 Feb 2025 11:17:54 +0100 Subject: [PATCH 11/12] Revert to header file --- kratos/includes/node.h | 285 +++++++++++++++++++++++---- kratos/sources/node.cpp | 415 ---------------------------------------- 2 files changed, 249 insertions(+), 451 deletions(-) delete mode 100644 kratos/sources/node.cpp diff --git a/kratos/includes/node.h b/kratos/includes/node.h index 107ec31509ba..e23237657a6a 100755 --- a/kratos/includes/node.h +++ b/kratos/includes/node.h @@ -103,20 +103,51 @@ class KRATOS_API(KRATOS_CORE) Node final /** * @brief @brief Default constructor. */ - Node(); + Node() + : BaseType() + , Flags() + , mNodalData(0) + , mDofs() + , mData() + , mInitialPosition() + , mNodeLock() + { + CreateSolutionStepData(); + } /** * @brief Constructor with a given node ID. * @param NewId The unique index identifier of the node. */ - explicit Node(IndexType NewId); + explicit Node(IndexType NewId) + : BaseType() + , Flags() + , mNodalData(NewId) + , mDofs() + , mData() + , mInitialPosition() + , mNodeLock() + { + KRATOS_ERROR << "Calling the default constructor for the node ... illegal operation!!" << std::endl; + CreateSolutionStepData(); + } /** * @brief Constructor for a 1D node. * @param NewId The unique index identifier of the node. * @param NewX The X-coordinate of the node. */ - Node(IndexType NewId, const double NewX); + Node(IndexType NewId, const double NewX) + : BaseType(NewX) + , Flags() + , mNodalData(NewId) + , mDofs() + , mData() + , mInitialPosition(NewX) + , mNodeLock() + { + CreateSolutionStepData(); + } /** * @brief Constructor for a 2D node. @@ -124,7 +155,17 @@ class KRATOS_API(KRATOS_CORE) Node final * @param NewX The X-coordinate of the node. * @param NewY The Y-coordinate of the node. */ - Node(IndexType NewId, const double NewX, const double NewY); + Node(IndexType NewId, const double NewX, const double NewY) + : BaseType(NewX, NewY) + , Flags() + , mNodalData(NewId) + , mDofs() + , mData() + , mInitialPosition(NewX, NewY) + , mNodeLock() + { + CreateSolutionStepData(); + } /** * @brief Constructor for a 3D node. @@ -133,14 +174,34 @@ class KRATOS_API(KRATOS_CORE) Node final * @param NewY The Y-coordinate of the node. * @param NewZ The Z-coordinate of the node. */ - Node(IndexType NewId, const double NewX, const double NewY, const double NewZ); + Node(IndexType NewId, const double NewX, const double NewY, const double NewZ) + : BaseType(NewX, NewY, NewZ) + , Flags() + , mNodalData(NewId) + , mDofs() + , mData() + , mInitialPosition(NewX, NewY, NewZ) + , mNodeLock() + { + CreateSolutionStepData(); + } /** * @brief Constructor from an existing point. * @param NewId The unique index identifier of the node. * @param rThisPoint The point from which to initialize the node. */ - Node(IndexType NewId, Point const& rThisPoint); + Node(IndexType NewId, Point const& rThisPoint) + : BaseType(rThisPoint) + , Flags() + , mNodalData(NewId) + , mDofs() + , mData() + , mInitialPosition(rThisPoint) + , mNodeLock() + { + CreateSolutionStepData(); + } /** * @brief Deleted copy constructor to prevent copying. @@ -173,7 +234,17 @@ class KRATOS_API(KRATOS_CORE) Node final * @param NewId The unique index identifier of the node. * @param rOtherCoordinates The std::vector containing the node coordinates. */ - Node(IndexType NewId, std::vector const& rOtherCoordinates); + Node(IndexType NewId, std::vector const& rOtherCoordinates) + : BaseType(rOtherCoordinates) + , Flags() + , mNodalData(NewId) + , mDofs() + , mData() + , mInitialPosition() + , mNodeLock() + { + CreateSolutionStepData(); + } /** * @brief Constructor for a 3D node with variables list and data. @@ -186,7 +257,16 @@ class KRATOS_API(KRATOS_CORE) Node final * @param NewQueueSize The queue size for storing historical data (default = 1). */ Node(IndexType NewId, const double NewX, const double NewY, const double NewZ, - VariablesList::Pointer pVariablesList, BlockType const * ThisData, SizeType NewQueueSize = 1); + VariablesList::Pointer pVariablesList, BlockType const * ThisData, SizeType NewQueueSize = 1) + : BaseType(NewX, NewY, NewZ) + , Flags() + , mNodalData(NewId, pVariablesList,ThisData,NewQueueSize) + , mDofs() + , mData() + , mInitialPosition(NewX, NewY, NewZ) + , mNodeLock() + { + } /** * @brief Creates a clone of the current node. @@ -194,13 +274,32 @@ class KRATOS_API(KRATOS_CORE) Node final * the current node, copies its nodal data, DOFs, and flags. * @return Pointer to the cloned node. */ - typename Node::Pointer Clone(); + typename Node::Pointer Clone() + { + Node::Pointer p_new_node = Kratos::make_intrusive( this->Id(), (*this)[0], (*this)[1], (*this)[2]); + p_new_node->mNodalData = this->mNodalData; + + Node::DofsContainerType& my_dofs = (this)->GetDofs(); + for (typename DofsContainerType::const_iterator it_dof = my_dofs.begin(); it_dof != my_dofs.end(); it_dof++) { + p_new_node->pAddDof(**it_dof); + } + + p_new_node->mData = this->mData; + p_new_node->mInitialPosition = this->mInitialPosition; + + p_new_node->Set(Flags(*this)); + + return p_new_node; + } /** * @brief Destructor for the Node class. * @details Clears any stored solution step data before destruction. */ - ~Node() override; + ~Node() override + { + ClearSolutionStepsData(); + } /** * @brief Gets the reference count of the node. @@ -274,7 +373,23 @@ class KRATOS_API(KRATOS_CORE) Node final * @param rOther The node to copy from. * @return A reference to the copied node. */ - Node& operator=(const Node& rOther); + Node& operator=(const Node& rOther) + { + BaseType::operator=(rOther); + Flags::operator =(rOther); + + mNodalData = rOther.mNodalData; + + // Deep copying the dofs + for(typename DofsContainerType::const_iterator it_dof = rOther.mDofs.begin() ; it_dof != rOther.mDofs.end() ; it_dof++) { + pAddDof(**it_dof); + } + + mData = rOther.mData; + mInitialPosition = rOther.mInitialPosition; + + return *this; + } /** * @brief Equality operator. @@ -282,7 +397,10 @@ class KRATOS_API(KRATOS_CORE) Node final * @param rOther The node to compare with. * @return True if nodes are equal, false otherwise. */ - bool operator==(const Node& rOther); + bool operator==(const Node& rOther) + { + return Point::operator ==(rOther); + } /** * @brief Accesses a solution step value for a given variable and step index. @@ -338,14 +456,20 @@ class KRATOS_API(KRATOS_CORE) Node final * @param ThisIndex The index of the coordinate (0 = X, 1 = Y, 2 = Z). * @return Reference to the coordinate value. */ - double& operator[](IndexType ThisIndex); + double& operator[](IndexType ThisIndex) + { + return BaseType::operator[](ThisIndex); + } /** * @brief Const accessor for node coordinates. * @param ThisIndex The index of the coordinate (0 = X, 1 = Y, 2 = Z). * @return The coordinate value. */ - double operator[](IndexType ThisIndex) const; + double operator[](IndexType ThisIndex) const + { + return BaseType::operator[](ThisIndex); + } ///@} ///@name Nodal Data @@ -355,13 +479,19 @@ class KRATOS_API(KRATOS_CORE) Node final * @brief Creates a new solution step data entry. * @details Adds a new solution step at the front of the solution step data container. */ - void CreateSolutionStepData(); + void CreateSolutionStepData() + { + SolutionStepData().PushFront(); + } /** * @brief Clones the current solution step data. * @details Copies the front solution step data to create a new step. */ - void CloneSolutionStepData(); + void CloneSolutionStepData() + { + SolutionStepData().CloneFront(); + } /** * @brief Overwrites solution step data at a given index. @@ -369,32 +499,47 @@ class KRATOS_API(KRATOS_CORE) Node final * @param SourceSolutionStepIndex The index of the source solution step. * @param DestinationSourceSolutionStepIndex The index of the destination step where the data will be assigned. */ - void OverwriteSolutionStepData(IndexType SourceSolutionStepIndex, IndexType DestinationSourceSolutionStepIndex); + void OverwriteSolutionStepData(IndexType SourceSolutionStepIndex, IndexType DestinationSourceSolutionStepIndex) + { + SolutionStepData().AssignData(SolutionStepData().Data(SourceSolutionStepIndex), DestinationSourceSolutionStepIndex); + } /** * @brief Clears all stored solution step data. * @details Removes all solution step data entries. */ - void ClearSolutionStepsData(); + void ClearSolutionStepsData() + { + SolutionStepData().Clear(); + } /** * @brief Sets the list of solution step variables. * @details Assigns a new variables list to the solution step data. * @param pVariablesList Pointer to the new list of variables. */ - void SetSolutionStepVariablesList(VariablesList::Pointer pVariablesList); + void SetSolutionStepVariablesList(VariablesList::Pointer pVariablesList) + { + SolutionStepData().SetVariablesList(pVariablesList); + } /** * @brief Retrieves the solution step data container. * @return Reference to the solution step data container. */ - VariablesListDataValueContainer& SolutionStepData(); + VariablesListDataValueContainer& SolutionStepData() + { + return mNodalData.GetSolutionStepData(); + } /** * @brief Retrieves the solution step data container (const version). * @return Const reference to the solution step data container. */ - const VariablesListDataValueContainer& SolutionStepData() const; + const VariablesListDataValueContainer& SolutionStepData() const + { + return mNodalData.GetSolutionStepData(); + } /** * @deprecated This method is deprecated. Use GetData() instead. @@ -480,7 +625,10 @@ class KRATOS_API(KRATOS_CORE) Node final * @param rThisVariable The variable to check. * @return True if the variable exists in the solution step data, false otherwise. */ - bool SolutionStepsDataHas(const VariableData& rThisVariable) const; + bool SolutionStepsDataHas(const VariableData& rThisVariable) const + { + return SolutionStepData().Has(rThisVariable); + } /** * @brief Retrieves the solution step value for a given variable quickly. @@ -704,7 +852,10 @@ class KRATOS_API(KRATOS_CORE) Node final * solution step data. * @return IndexType The size of the buffer. */ - IndexType GetBufferSize() const; + IndexType GetBufferSize() const + { + return SolutionStepData().QueueSize(); + } /** * @brief Set the buffer size. @@ -712,7 +863,10 @@ class KRATOS_API(KRATOS_CORE) Node final * to the given size @p NewBufferSize. * @param NewBufferSize New size for the buffer. */ - void SetBufferSize(IndexType NewBufferSize); + void SetBufferSize(IndexType NewBufferSize) + { + SolutionStepData().Resize(NewBufferSize); + } ///@} ///@name Access @@ -803,7 +957,12 @@ class KRATOS_API(KRATOS_CORE) Node final * @details This function sets the initial position of the node by copying the values from the given `NewInitialPosition`. * @param NewInitialPosition The new initial position to be set. */ - void SetInitialPosition(const Point& NewInitialPosition); + void SetInitialPosition(const Point& NewInitialPosition) + { + mInitialPosition.X() = NewInitialPosition.X(); + mInitialPosition.Y() = NewInitialPosition.Y(); + mInitialPosition.Z() = NewInitialPosition.Z(); + } /** * @brief Sets the initial position of the node using X, Y, and Z coordinates. @@ -812,21 +971,32 @@ class KRATOS_API(KRATOS_CORE) Node final * @param Y The Y coordinate of the new initial position. * @param Z The Z coordinate of the new initial position. */ - void SetInitialPosition(double X,double Y, double Z); + void SetInitialPosition(double X,double Y, double Z) + { + mInitialPosition.X() = X; + mInitialPosition.Y() = Y; + mInitialPosition.Z() = Z; + } /** * @brief Returns the pointer to the list of variables associated with the node. * @details This function provides access to the list of variables for the current solution step. * @return A pointer to the list of variables. */ - VariablesList::Pointer pGetVariablesList(); + VariablesList::Pointer pGetVariablesList() + { + return SolutionStepData().pGetVariablesList(); + } /** * @brief Returns the pointer to the list of variables associated with the node (const version). * @details This function provides read-only access to the list of variables for the current solution step. * @return A const pointer to the list of variables. */ - const VariablesList::Pointer pGetVariablesList() const; + const VariablesList::Pointer pGetVariablesList() const + { + return SolutionStepData().pGetVariablesList(); + } ///@} ///@name Dofs @@ -907,7 +1077,10 @@ class KRATOS_API(KRATOS_CORE) Node final * (DOFs) for the node. The returned container is mutable, allowing modifications to the DOFs. * @return A reference to the container of DOFs. */ - DofsContainerType& GetDofs(); + DofsContainerType& GetDofs() + { + return mDofs; + } /** * @brief Returns all the degrees of freedom (DOFs) associated with the node (const version). @@ -915,7 +1088,10 @@ class KRATOS_API(KRATOS_CORE) Node final * (DOFs) for the node. The returned container cannot be modified. * @return A const reference to the container of DOFs. */ - const DofsContainerType& GetDofs() const; + const DofsContainerType& GetDofs() const + { + return mDofs; + } /** * @brief Get DoF counted pointer for a given variable @@ -1184,13 +1360,28 @@ class KRATOS_API(KRATOS_CORE) Node final ///@{ /// Turn back information as a string. - std::string Info() const override; + std::string Info() const override + { + std::stringstream buffer; + buffer << "Node #" << Id(); + return buffer.str(); + } /// Print information about this object. - void PrintInfo(std::ostream& rOStream) const override; + void PrintInfo(std::ostream& rOStream) const override + { + rOStream << Info(); + } /// Print object's data. - void PrintData(std::ostream& rOStream) const override; + void PrintData(std::ostream& rOStream) const override + { + BaseType::PrintData(rOStream); + if(!mDofs.empty()) + rOStream << std::endl << " Dofs :" << std::endl; + for(typename DofsContainerType::const_iterator i = mDofs.begin() ; i != mDofs.end() ; i++) + rOStream << " " << (*i)->Info() << std::endl; + } ///@} ///@name Friends @@ -1288,7 +1479,12 @@ class KRATOS_API(KRATOS_CORE) Node final * in ascending order of the keys of their associated variables. The sorting is done using * the `std::sort` algorithm and compares the `Key()` of the `GetVariable()` for each DOF. */ - void SortDofs(); + void SortDofs() + { + std::sort(mDofs.begin(), mDofs.end(), [](Kratos::unique_ptr const& First, Kratos::unique_ptr const& Second)->bool{ + return First->GetVariable().Key() < Second->GetVariable().Key(); + }); + } ///@} ///@name Private Operations @@ -1304,13 +1500,30 @@ class KRATOS_API(KRATOS_CORE) Node final * @brief The save operation which copies the database of the class * @param rSerializer The serializer used to preserve the information */ - void save(Serializer& rSerializer) const override; + void save(Serializer& rSerializer) const override + { + KRATOS_SERIALIZE_SAVE_BASE_CLASS(rSerializer, Point ); + KRATOS_SERIALIZE_SAVE_BASE_CLASS(rSerializer, Flags ); + rSerializer.save("NodalData", &mNodalData); // Storing it as pointer to be shared by Dof pointer + rSerializer.save("Data", mData); + rSerializer.save("Initial Position", mInitialPosition); + rSerializer.save("Data", mDofs); + } /** * The load operation which restores the database of the class * @param rSerializer The serializer used to preserve the information */ - void load(Serializer& rSerializer) override; + void load(Serializer& rSerializer) override + { + KRATOS_SERIALIZE_LOAD_BASE_CLASS(rSerializer, Point ); + KRATOS_SERIALIZE_LOAD_BASE_CLASS(rSerializer, Flags ); + NodalData* p_nodal_data = &mNodalData; + rSerializer.load("NodalData", p_nodal_data); + rSerializer.load("Data", mData); + rSerializer.load("Initial Position", mInitialPosition); + rSerializer.load("Data", mDofs); + } ///@} ///@name Private Access diff --git a/kratos/sources/node.cpp b/kratos/sources/node.cpp deleted file mode 100644 index faf4c8d92d51..000000000000 --- a/kratos/sources/node.cpp +++ /dev/null @@ -1,415 +0,0 @@ -// | / | -// ' / __| _` | __| _ \ __| -// . \ | ( | | ( |\__ ` -// _|\_\_| \__,_|\__|\___/ ____/ -// Multi-Physics -// -// License: BSD License -// Kratos default license: kratos/license.txt -// -// Main authors: Pooyan Dadvand -// Riccardo Rossi -// - -// System includes - -// External includes - -// Project includes -#include "includes/node.h" - -namespace Kratos -{ - -Node::Node() - : BaseType() - , Flags() - , mNodalData(0) - , mDofs() - , mData() - , mInitialPosition() - , mNodeLock() -{ - CreateSolutionStepData(); -} - -/***********************************************************************************/ -/***********************************************************************************/ - -Node::Node(IndexType NewId ) - : BaseType() - , Flags() - , mNodalData(NewId) - , mDofs() - , mData() - , mInitialPosition() - , mNodeLock() -{ - KRATOS_ERROR << "Calling the default constructor for the node ... illegal operation!!" << std::endl; - CreateSolutionStepData(); -} - -/***********************************************************************************/ -/***********************************************************************************/ - -Node::Node(IndexType NewId, const double NewX) - : BaseType(NewX) - , Flags() - , mNodalData(NewId) - , mDofs() - , mData() - , mInitialPosition(NewX) - , mNodeLock() -{ - CreateSolutionStepData(); -} - -/***********************************************************************************/ -/***********************************************************************************/ - -Node::Node(IndexType NewId, const double NewX, const double NewY) - : BaseType(NewX, NewY) - , Flags() - , mNodalData(NewId) - , mDofs() - , mData() - , mInitialPosition(NewX, NewY) - , mNodeLock() -{ - CreateSolutionStepData(); -} - -/***********************************************************************************/ -/***********************************************************************************/ - -Node::Node(IndexType NewId, const double NewX, const double NewY, const double NewZ) - : BaseType(NewX, NewY, NewZ) - , Flags() - , mNodalData(NewId) - , mDofs() - , mData() - , mInitialPosition(NewX, NewY, NewZ) - , mNodeLock() -{ - CreateSolutionStepData(); -} - -/***********************************************************************************/ -/***********************************************************************************/ - -Node::Node(IndexType NewId, Point const& rThisPoint) - : BaseType(rThisPoint) - , Flags() - , mNodalData(NewId) - , mDofs() - , mData() - , mInitialPosition(rThisPoint) - , mNodeLock() -{ - CreateSolutionStepData(); -} - -/***********************************************************************************/ -/***********************************************************************************/ - -Node::Node(IndexType NewId, std::vector const& rOtherCoordinates) - : BaseType(rOtherCoordinates) - , Flags() - , mNodalData(NewId) - , mDofs() - , mData() - , mInitialPosition() - , mNodeLock() -{ - CreateSolutionStepData(); -} - -/***********************************************************************************/ -/***********************************************************************************/ - -Node::Node(IndexType NewId, const double NewX, const double NewY, const double NewZ, VariablesList::Pointer pVariablesList, BlockType const * ThisData, SizeType NewQueueSize) - : BaseType(NewX, NewY, NewZ) - , Flags() - , mNodalData(NewId, pVariablesList,ThisData,NewQueueSize) - , mDofs() - , mData() - , mInitialPosition(NewX, NewY, NewZ) - , mNodeLock() -{ -} - -/***********************************************************************************/ -/***********************************************************************************/ - -typename Node::Pointer Node::Clone() -{ - Node::Pointer p_new_node = Kratos::make_intrusive( this->Id(), (*this)[0], (*this)[1], (*this)[2]); - p_new_node->mNodalData = this->mNodalData; - - Node::DofsContainerType& my_dofs = (this)->GetDofs(); - for (typename DofsContainerType::const_iterator it_dof = my_dofs.begin(); it_dof != my_dofs.end(); it_dof++) { - p_new_node->pAddDof(**it_dof); - } - - p_new_node->mData = this->mData; - p_new_node->mInitialPosition = this->mInitialPosition; - - p_new_node->Set(Flags(*this)); - - return p_new_node; -} - -/***********************************************************************************/ -/***********************************************************************************/ - -Node::~Node() -{ - ClearSolutionStepsData(); -} - -/***********************************************************************************/ -/***********************************************************************************/ - -Node& Node::operator=(const Node& rOther) -{ - BaseType::operator=(rOther); - Flags::operator =(rOther); - - mNodalData = rOther.mNodalData; - - // Deep copying the dofs - for(typename DofsContainerType::const_iterator it_dof = rOther.mDofs.begin() ; it_dof != rOther.mDofs.end() ; it_dof++) { - pAddDof(**it_dof); - } - - mData = rOther.mData; - mInitialPosition = rOther.mInitialPosition; - - return *this; -} - -/***********************************************************************************/ -/***********************************************************************************/ - -bool Node::operator==(const Node& rOther) -{ - return Point::operator ==(rOther); -} - -/***********************************************************************************/ -/***********************************************************************************/ - -double& Node::operator[](IndexType ThisIndex) -{ - return BaseType::operator[](ThisIndex); -} - -/***********************************************************************************/ -/***********************************************************************************/ - -double Node::operator[](IndexType ThisIndex) const -{ - return BaseType::operator[](ThisIndex); -} - -/***********************************************************************************/ -/***********************************************************************************/ - -void Node::CreateSolutionStepData() -{ - SolutionStepData().PushFront(); -} - -/***********************************************************************************/ -/***********************************************************************************/ - -void Node::CloneSolutionStepData() -{ - SolutionStepData().CloneFront(); -} - -/***********************************************************************************/ -/***********************************************************************************/ - -void Node::OverwriteSolutionStepData(IndexType SourceSolutionStepIndex, IndexType DestinationSourceSolutionStepIndex) -{ - SolutionStepData().AssignData(SolutionStepData().Data(SourceSolutionStepIndex), DestinationSourceSolutionStepIndex); -} - -/***********************************************************************************/ -/***********************************************************************************/ - -void Node::ClearSolutionStepsData() -{ - SolutionStepData().Clear(); -} - -/***********************************************************************************/ -/***********************************************************************************/ - -void Node::SetSolutionStepVariablesList(VariablesList::Pointer pVariablesList) -{ - SolutionStepData().SetVariablesList(pVariablesList); -} - -/***********************************************************************************/ -/***********************************************************************************/ - -VariablesListDataValueContainer& Node::SolutionStepData() -{ - return mNodalData.GetSolutionStepData(); -} - -/***********************************************************************************/ -/***********************************************************************************/ - -const VariablesListDataValueContainer& Node::SolutionStepData() const -{ - return mNodalData.GetSolutionStepData(); -} - -/***********************************************************************************/ -/***********************************************************************************/ - -bool Node::SolutionStepsDataHas(const VariableData& rThisVariable) const -{ - return SolutionStepData().Has(rThisVariable); -} - -/***********************************************************************************/ -/***********************************************************************************/ - -IndexType Node::GetBufferSize() const -{ - return SolutionStepData().QueueSize(); -} - -/***********************************************************************************/ -/***********************************************************************************/ - -void Node::SetBufferSize(IndexType NewBufferSize) -{ - SolutionStepData().Resize(NewBufferSize); -} - -/***********************************************************************************/ -/***********************************************************************************/ - -void Node::SetInitialPosition(const Point& NewInitialPosition) -{ - mInitialPosition.X() = NewInitialPosition.X(); - mInitialPosition.Y() = NewInitialPosition.Y(); - mInitialPosition.Z() = NewInitialPosition.Z(); -} - -/***********************************************************************************/ -/***********************************************************************************/ - -void Node::SetInitialPosition(double X,double Y, double Z) -{ - mInitialPosition.X() = X; - mInitialPosition.Y() = Y; - mInitialPosition.Z() = Z; -} - -/***********************************************************************************/ -/***********************************************************************************/ - -VariablesList::Pointer Node::pGetVariablesList() -{ - return SolutionStepData().pGetVariablesList(); -} - -/***********************************************************************************/ -/***********************************************************************************/ - -const VariablesList::Pointer Node::pGetVariablesList() const -{ - return SolutionStepData().pGetVariablesList(); -} - -/***********************************************************************************/ -/***********************************************************************************/ - -Node::DofsContainerType& Node::GetDofs() -{ - return mDofs; -} - -/***********************************************************************************/ -/***********************************************************************************/ - -const Node::DofsContainerType& Node::GetDofs() const -{ - return mDofs; -} - -/***********************************************************************************/ -/***********************************************************************************/ - -std::string Node::Info() const -{ - std::stringstream buffer; - buffer << "Node #" << Id(); - return buffer.str(); -} - -/***********************************************************************************/ -/***********************************************************************************/ - -void Node::PrintInfo(std::ostream& rOStream) const -{ - rOStream << Info(); -} - -/***********************************************************************************/ -/***********************************************************************************/ - -void Node::PrintData(std::ostream& rOStream) const -{ - BaseType::PrintData(rOStream); - if(!mDofs.empty()) - rOStream << std::endl << " Dofs :" << std::endl; - for(typename DofsContainerType::const_iterator i = mDofs.begin() ; i != mDofs.end() ; i++) - rOStream << " " << (*i)->Info() << std::endl; -} - -/***********************************************************************************/ -/***********************************************************************************/ - -void Node::SortDofs() -{ - std::sort(mDofs.begin(), mDofs.end(), [](Kratos::unique_ptr const& First, Kratos::unique_ptr const& Second)->bool{ - return First->GetVariable().Key() < Second->GetVariable().Key(); - }); -} - -/***********************************************************************************/ -/***********************************************************************************/ - -void Node::save(Serializer& rSerializer) const -{ - KRATOS_SERIALIZE_SAVE_BASE_CLASS(rSerializer, Point ); - KRATOS_SERIALIZE_SAVE_BASE_CLASS(rSerializer, Flags ); - rSerializer.save("NodalData", &mNodalData); // Storing it as pointer to be shared by Dof pointer - rSerializer.save("Data", mData); - rSerializer.save("Initial Position", mInitialPosition); - rSerializer.save("Data", mDofs); - -} - -/***********************************************************************************/ -/***********************************************************************************/ - -void Node::load(Serializer& rSerializer) -{ - KRATOS_SERIALIZE_LOAD_BASE_CLASS(rSerializer, Point ); - KRATOS_SERIALIZE_LOAD_BASE_CLASS(rSerializer, Flags ); - NodalData* p_nodal_data = &mNodalData; - rSerializer.load("NodalData", p_nodal_data); - rSerializer.load("Data", mData); - rSerializer.load("Initial Position", mInitialPosition); - rSerializer.load("Data", mDofs); -} - -} // namespace Kratos. From 6a4cec43f5e9fa9df3120bed6811b85040643fac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vicente=20Mataix=20Ferr=C3=A1ndiz?= Date: Wed, 26 Feb 2025 13:16:26 +0100 Subject: [PATCH 12/12] Revert KRATOS_API --- kratos/includes/node.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kratos/includes/node.h b/kratos/includes/node.h index e23237657a6a..0df98c9db42c 100755 --- a/kratos/includes/node.h +++ b/kratos/includes/node.h @@ -62,7 +62,7 @@ namespace Kratos * @author Pooyan Dadvand * @author Riccardo Rossi */ -class KRATOS_API(KRATOS_CORE) Node final +class Node final : public Point, public Flags { public: