diff --git a/kratos/includes/io.h b/kratos/includes/io.h index 6ba39356d6a7..772d73e061ba 100644 --- a/kratos/includes/io.h +++ b/kratos/includes/io.h @@ -4,8 +4,8 @@ // _|\_\_| \__,_|\__|\___/ ____/ // Multi-Physics // -// License: BSD License -// Kratos default license: kratos/license.txt +// License: BSD License +// Kratos default license: kratos/license.txt // // Main authors: Pooyan Dadvand // @@ -13,8 +13,6 @@ #pragma once // System includes -#include -#include #include // External includes @@ -72,43 +70,66 @@ class KRATOS_API(KRATOS_CORE) IO KRATOS_DEFINE_LOCAL_FLAG( MESH_ONLY ); KRATOS_DEFINE_LOCAL_FLAG( SCIENTIFIC_PRECISION ); - typedef Node NodeType; + /// Node type definition + using NodeType = Node; - typedef Geometry GeometryType; + /// Geometry type definition + using GeometryType = Geometry; - typedef Mesh MeshType; + /// Mesh type definition + using MeshType = Mesh; - typedef MeshType::NodesContainerType NodesContainerType; + /// Nodes container type within MeshType + using NodesContainerType = typename MeshType::NodesContainerType; - typedef MeshType::PropertiesContainerType PropertiesContainerType; + /// Properties container type within MeshType + using PropertiesContainerType = typename MeshType::PropertiesContainerType; - typedef ModelPart::GeometryContainerType GeometryContainerType; + /// Geometry container type within ModelPart + using GeometryContainerType = typename ModelPart::GeometryContainerType; - typedef MeshType::ElementsContainerType ElementsContainerType; + /// The geometry map type within ModelPart + using GeometriesMapType = typename ModelPart::GeometriesMapType; - typedef MeshType::ConditionsContainerType ConditionsContainerType; + /// Elements container type within MeshType + using ElementsContainerType = typename MeshType::ElementsContainerType; - typedef std::vector > ConnectivitiesContainerType; + /// Conditions container type within MeshType + using ConditionsContainerType = typename MeshType::ConditionsContainerType; - typedef std::vector > PartitionIndicesContainerType; + /// MasterSlaveConstraint container type within MeshType + using MasterSlaveConstraintContainerType = typename MeshType::MasterSlaveConstraintContainerType; - typedef std::vector PartitionIndicesType; + /// Connectivities container type + using ConnectivitiesContainerType = std::vector>; - typedef std::size_t SizeType; + /// Partition indices container type + using PartitionIndicesContainerType = std::vector>; - typedef DenseMatrix GraphType; + /// Partition indices type + using PartitionIndicesType = std::vector; - // auxiliary struct containg information about the partitioning of the entities in a ModelPart + /// Size type definition + using SizeType = std::size_t; + + /// Graph type definition + using GraphType = DenseMatrix; + + // Auxiliary struct containing information about the partitioning of the entities in a ModelPart struct PartitioningInfo { GraphType Graph; - PartitionIndicesType NodesPartitions; // partition where the Node is local - PartitionIndicesType ElementsPartitions; // partition where the Element is local - PartitionIndicesType ConditionsPartitions; // partition where the Condition is local - PartitionIndicesContainerType NodesAllPartitions; // partitions, in which the Node is present (local & ghost) - PartitionIndicesContainerType ElementsAllPartitions; // partitions, in which the Element is present (local & ghost) - PartitionIndicesContainerType ConditionsAllPartitions; // partitions, in which the Condition is present (local & ghost) - }; + PartitionIndicesType NodesPartitions; // Partition where the Node is local + PartitionIndicesType ElementsPartitions; // Partition where the Element is local + PartitionIndicesType ConditionsPartitions; // Partition where the Condition is local + PartitionIndicesType ConstraintsPartitions; // Partition where the MasterSlaveConstraint is local + PartitionIndicesType GeometriesPartitions; // Partition where the Geometry is local + PartitionIndicesContainerType NodesAllPartitions; // Partitions, in which the Node is present (local & ghost) + PartitionIndicesContainerType ElementsAllPartitions; // Partitions, in which the Element is present (local & ghost) + PartitionIndicesContainerType ConditionsAllPartitions; // Partitions, in which the Condition is present (local & ghost) + PartitionIndicesContainerType ConstraintsAllPartitions; // Partitions, in which the MasterSlaveConstraint is present (local & ghost) + PartitionIndicesContainerType GeometriesAllPartitions; // Partitions, in which the Geometry is present (local & ghost) + };; ///@} ///@name Life Cycle @@ -349,6 +370,54 @@ class KRATOS_API(KRATOS_CORE) IO KRATOS_ERROR << "Calling base class method (WriteConditions). Please check the definition of derived class" << std::endl; } + /** + * @brief Reads the master-slave constraints from an input source. + * @details This method is intended to be overridden by derived classes to implement + * the specific logic for reading master-slave constraints into the provided + * container. The base class implementation throws an error, indicating that + * the method must be implemented in the derived class. + * @param rThisNodes The nodes to be used for associating the master-slave constraints. + * @param rConstraintContainer The container where the master-slave + * constraints will be stored. This container is expected to be populated + * by the derived class implementation. + * @throws Exception If the base class method is called directly, an error is + * thrown to indicate that the method must be implemented in a derived class. + */ + virtual void ReadConstraints( + NodesContainerType& rThisNodes, + MasterSlaveConstraintContainerType& rConstraintContainer + ) + { + KRATOS_ERROR << "Calling base class method (ReadConstraints). Please check the definition of derived class" << std::endl; + } + + /** + * @brief This method reads the constraints connectivities + * @param rConditionsConnectivities The constraints connectivities + * @return The number of constraints + */ + virtual std::size_t ReadConstraintsConnectivities(ConnectivitiesContainerType& rConstraintsConnectivities) + { + KRATOS_ERROR << "Calling base class method (ReadConstraintsConnectivities). Please check the definition of derived class" << std::endl; + } + + /** + * @brief Writes the master-slave constraints to the output. + * @details This method is intended to be overridden by derived classes to provide + * specific functionality for writing master-slave constraints. The base + * class implementation throws an error, indicating that the method must + * be implemented in the derived class. + * @param rConstraintContainer The container holding the master-slave + * constraints to be written. + * @throws Exception Always throws an error if called on the base class. + * Derived classes must override this method to provide the actual + * implementation. + */ + virtual void WriteConstraints(MasterSlaveConstraintContainerType const& rConstraintContainer) + { + KRATOS_ERROR << "Calling base class method (WriteNewConstraint). Please check the definition of derived class" << std::endl; + } + /** * @brief This method reads the initial values of the model part * @param rThisModelPart The model part with the initial values to be read @@ -564,22 +633,82 @@ class KRATOS_API(KRATOS_CORE) IO KRATOS_ERROR << "Calling base class method (DivideInputToPartitions). Please check the definition of derived class" << std::endl; } + /** + * @brief Virtual method to read element and condition IDs from a sub-model part. + * @details This method is intended to be overridden by derived classes. + * @param rModelPartName The name of the sub-model part to read from. + * @param rElementsIds Set to store element IDs. + * @param rConditionsIds Set to store condition IDs. + */ virtual void ReadSubModelPartElementsAndConditionsIds( std::string const& rModelPartName, - std::unordered_set &rElementsIds, - std::unordered_set &rConditionsIds) + std::unordered_set& rElementsIds, + std::unordered_set& rConditionsIds + ) { KRATOS_ERROR << "Calling base class method (ReadSubModelPartElementsAndConditionsIds). Please check the definition of derived class" << std::endl; } + /** + * @brief Virtual method to read element, condition, master-slave constraint, and geometry IDs from a sub-model part. + * @details This method is intended to be overridden by derived classes. + * @param rModelPartName The name of the sub-model part to read from. + * @param rElementsIds Set to store element IDs. + * @param rConditionsIds Set to store condition IDs. + * @param rConstraintIds Set to store master-slave constraint IDs. + * @param rGeometriesIds Set to store geometry IDs. + */ + virtual void ReadSubModelPartEntitiesIds( + std::string const& rModelPartName, + std::unordered_set& rElementsIds, + std::unordered_set& rConditionsIds, + std::unordered_set& rConstraintIds, + std::unordered_set& rGeometriesIds + ) + { + KRATOS_WARNING("IO") << " The method ReadSubModelPartEntitiesIds with Constraint and Geometries is not implemented. Only the elements and conditions are read." << std::endl; + return ReadSubModelPartElementsAndConditionsIds(rModelPartName, rElementsIds, rConditionsIds); + } + + /** + * @brief Virtual method to read nodal graph from entities list. + * @details This method is intended to be overridden by derived classes. + * @param rAuxConnectivities Container of connectivities. + * @param rElementsIds Set of element IDs. + * @param rConditionsIds Set of condition IDs. + * @return The size of the nodal graph. + */ virtual std::size_t ReadNodalGraphFromEntitiesList( ConnectivitiesContainerType& rAuxConnectivities, - std::unordered_set &rElementsIds, - std::unordered_set &rConditionsIds) + std::unordered_set& rElementsIds, + std::unordered_set& rConditionsIds + ) { KRATOS_ERROR << "Calling base class method (ReadNodalGraphFromEntitiesList). Please check the definition of derived class" << std::endl; } + /** + * @brief Virtual method to read nodal graph from entities list including master-slave constraints and geometries. + * @details This method is intended to be overridden by derived classes. + * @param rAuxConnectivities Container of connectivities. + * @param rElementsIds Set of element IDs. + * @param rConditionsIds Set of condition IDs. + * @param rConstraintIds Set of master-slave constraint IDs. + * @param rGeometriesIds Set of geometry IDs. + * @return The size of the nodal graph. + */ + virtual std::size_t ReadNodalGraphFromEntitiesList( + ConnectivitiesContainerType& rAuxConnectivities, + std::unordered_set& rElementsIds, + std::unordered_set& rConditionsIds, + std::unordered_set& rConstraintIds, + std::unordered_set& rGeometriesIds + ) + { + KRATOS_WARNING("IO") << " The method ReadNodalGraphFromEntitiesList with Constraint and Geometries is not implemented. Only the elements and conditions are read." << std::endl; + return ReadNodalGraphFromEntitiesList(rAuxConnectivities, rElementsIds, rConditionsIds); + } + ///@} ///@name Access ///@{ @@ -719,4 +848,4 @@ inline std::ostream& operator << (std::ostream& rOStream, ///@} -} // namespace Kratos. +} // namespace Kratos. \ No newline at end of file