-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding ModelPart #84
Merged
Merged
Adding ModelPart #84
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
0500725
initial version of CoSimIO::ModelPart
philbucher 76eb3fd
Merge branch 'master' into model-part
philbucher 04b9568
adding empty test file
philbucher 6afe340
Merge branch 'master' into model-part
philbucher 7cc8d33
Improvements
philbucher 502086d
minor
philbucher 4e4e819
only allowing const version
philbucher 4a51eef
commenting suite
philbucher 27ae3b2
Merge remote-tracking branch 'origin/master' into model-part
philbucher d2ddaf1
using IdType
philbucher b1e0ee0
missing
philbucher 39abf73
storing nodes instead of connectivities
philbucher 1bf6175
fixes
philbucher 978c336
finished node
philbucher dbbdf94
finished Element
philbucher ba739a4
more advances
philbucher 779172b
replaced container access
philbucher eb50f89
added test for Node
philbucher 7b22f3f
adding test for Element
philbucher 6701609
fix
philbucher 1543868
added another test
philbucher a846ec7
explicitly using const iterator
philbucher 1f3a66a
delegating ctor
philbucher 0c01881
checks and corresponding tests
philbucher e5f38fc
minor fix
philbucher 014ab56
adding Name to ModelPart
philbucher e8c4b17
add test for ModelPart basics
philbucher 71a2069
missing paranthesis in Macro
philbucher eae0a91
testing invalid names in Modelpart
philbucher a9aec96
more tests
philbucher 782cac2
missing implementation
philbucher 16187d5
update after discussing with Pooyan
philbucher 1c281f8
updated pointer types
philbucher dda9ba9
intrnal refactor
philbucher dcc34be
fix
philbucher 4ff7286
missing tests I
philbucher affe7c8
missing tests II
philbucher File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,240 @@ | ||
// ______ _____ _ ________ | ||
// / ____/___ / ___/(_)___ ___ / _/ __ | | ||
// / / / __ \\__ \/ / __ `__ \ / // / / / | ||
// / /___/ /_/ /__/ / / / / / / // // /_/ / | ||
// \____/\____/____/_/_/ /_/ /_/___/\____/ | ||
// Kratos CoSimulationApplication | ||
// | ||
// License: BSD License, see license.txt | ||
// | ||
// Main authors: Philipp Bucher (https://github.com/philbucher) | ||
// | ||
|
||
#ifndef CO_SIM_IO_MODEL_PART_H_INCLUDED | ||
#define CO_SIM_IO_MODEL_PART_H_INCLUDED | ||
|
||
/* This file contains the implementation of th CoSimIO::ModelPart | ||
It serves as a data container when exchanging data | ||
Also it is used in order to be consistent with Kratos to reduce compatibility problems | ||
This is a simplified version of Kratos::ModelPart | ||
see https://github.com/KratosMultiphysics/Kratos/blob/master/kratos/includes/model_part.h | ||
*/ | ||
|
||
// System includes | ||
#include <memory> | ||
#include <vector> | ||
#include <string> | ||
#include <functional> | ||
#include <algorithm> | ||
|
||
// Project includes | ||
#include "define.hpp" | ||
#include "macros.hpp" | ||
|
||
namespace CoSimIO { | ||
class Node | ||
{ | ||
public: | ||
Node( | ||
const IdType I_Id, | ||
const double I_X, | ||
const double I_Y, | ||
const double I_Z) | ||
: mId(I_Id), | ||
mX(I_X), | ||
mY(I_Y), | ||
mZ(I_Z) | ||
{ | ||
CO_SIM_IO_ERROR_IF(I_Id < 1) << "Id must be >= 1!" << std::endl; | ||
} | ||
|
||
Node( | ||
const IdType I_Id, | ||
const CoordinatesType& I_Coordinates) | ||
: Node(I_Id, I_Coordinates[0], I_Coordinates[1], I_Coordinates[2]) | ||
{ } | ||
|
||
// delete copy and assignment CTor | ||
Node(const Node&) = delete; | ||
Node& operator=(Node const&) = delete; | ||
|
||
IdType Id() const { return mId; } | ||
double X() const { return mX; } | ||
double Y() const { return mY; } | ||
double Z() const { return mZ; } | ||
CoordinatesType Coordinates() const { return {mX, mY, mZ}; } | ||
|
||
private: | ||
IdType mId; | ||
double mX; | ||
double mY; | ||
double mZ; | ||
}; | ||
|
||
class Element | ||
{ | ||
public: | ||
using ElementType = std::size_t; | ||
using NodesContainerType = std::vector<Node*>; | ||
using ConnectivitiesType = std::vector<IdType>; | ||
|
||
Element( | ||
const IdType I_Id, | ||
const ElementType I_Type, | ||
const NodesContainerType& I_Nodes) | ||
: mId(I_Id), | ||
mType(I_Type), | ||
mNodes(I_Nodes) | ||
{ | ||
CO_SIM_IO_ERROR_IF(I_Id < 1) << "Id must be >= 1!" << std::endl; | ||
CO_SIM_IO_ERROR_IF(NumberOfNodes() < 1) << "No nodes were passed!" << std::endl; | ||
} | ||
|
||
// delete copy and assignment CTor | ||
Element(const Element&) = delete; | ||
Element& operator=(Element const&) = delete; | ||
|
||
IdType Id() const { return mId; } | ||
ElementType Type() const { return mType; } | ||
std::size_t NumberOfNodes() const { return mNodes.size(); } | ||
NodesContainerType::const_iterator NodesBegin() const { return mNodes.begin(); } | ||
NodesContainerType::const_iterator NodesEnd() const { return mNodes.end(); } | ||
|
||
private: | ||
IdType mId; | ||
ElementType mType; | ||
NodesContainerType mNodes; | ||
}; | ||
|
||
class ModelPart | ||
{ | ||
public: | ||
|
||
using NodePointerType = std::shared_ptr<Node>; // TODO switch to intrusive_ptr | ||
using ElementPointerType = std::shared_ptr<Element>; // TODO switch to intrusive_ptr | ||
using NodesContainerType = std::vector<NodePointerType>; | ||
using ElementsContainerType = std::vector<ElementPointerType>; | ||
|
||
explicit ModelPart(const std::string& I_Name) : mName(I_Name) | ||
{ | ||
CO_SIM_IO_ERROR_IF(I_Name.empty()) << "Please don't use empty names (\"\") when creating a ModelPart" << std::endl; | ||
CO_SIM_IO_ERROR_IF_NOT(I_Name.find(".") == std::string::npos) << "Please don't use names containing (\".\") when creating a ModelPart (used in \"" << I_Name << "\")" << std::endl; | ||
} | ||
|
||
// delete copy and assignment CTor | ||
ModelPart(const ModelPart&) = delete; | ||
ModelPart& operator=(ModelPart const&) = delete; | ||
|
||
std::string Name() const { return mName; } | ||
std::size_t NumberOfNodes() const { return mNodes.size(); } | ||
std::size_t NumberOfElements() const { return mElements.size(); } | ||
|
||
Node& CreateNewNode( | ||
const IdType I_Id, | ||
const double I_X, | ||
const double I_Y, | ||
const double I_Z) | ||
{ | ||
CO_SIM_IO_ERROR_IF(HasNode(I_Id)) << "The Node with Id " << I_Id << " exists already!" << std::endl; | ||
|
||
mNodes.push_back(std::make_shared<Node>(I_Id, I_X, I_Y, I_Z)); | ||
return *(mNodes.back()); | ||
} | ||
|
||
Element& CreateNewElement( | ||
const IdType I_Id, | ||
const Element::ElementType I_Type, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and here |
||
const Element::ConnectivitiesType& I_Connectivities) | ||
{ | ||
CO_SIM_IO_ERROR_IF(HasElement(I_Id)) << "The Element with Id " << I_Id << " exists already!" << std::endl; | ||
|
||
Element::NodesContainerType nodes; | ||
nodes.reserve(I_Connectivities.size()); | ||
for (const IdType node_id : I_Connectivities) { | ||
nodes.push_back(&GetNode(node_id)); | ||
} | ||
mElements.push_back(std::make_shared<Element>(I_Id, I_Type, nodes)); | ||
return *(mElements.back()); | ||
} | ||
|
||
NodesContainerType::const_iterator NodesBegin() const { return mNodes.begin(); } | ||
ElementsContainerType::const_iterator ElementsBegin() const { return mElements.begin(); } | ||
|
||
NodesContainerType::const_iterator NodesEnd() const { return mNodes.end(); } | ||
ElementsContainerType::const_iterator ElementsEnd() const { return mElements.end(); } | ||
|
||
Node& GetNode(const IdType I_Id) | ||
{ | ||
auto it_node = FindNode(I_Id); | ||
CO_SIM_IO_ERROR_IF(it_node == mNodes.end()) << "Node with Id " << I_Id << " does not exist!" << std::endl; | ||
return **it_node; | ||
} | ||
|
||
const Node& GetNode(const IdType I_Id) const | ||
{ | ||
auto it_node = FindNode(I_Id); | ||
CO_SIM_IO_ERROR_IF(it_node == mNodes.end()) << "Node with Id " << I_Id << " does not exist!" << std::endl; | ||
return **it_node; | ||
} | ||
|
||
Element& GetElement(const IdType I_Id) | ||
{ | ||
auto it_elem = FindElement(I_Id); | ||
CO_SIM_IO_ERROR_IF(it_elem == mElements.end()) << "Element with Id " << I_Id << " does not exist!" << std::endl; | ||
return **it_elem; | ||
} | ||
|
||
const Element& GetElement(const IdType I_Id) const | ||
{ | ||
auto it_elem = FindElement(I_Id); | ||
CO_SIM_IO_ERROR_IF(it_elem == mElements.end()) << "Element with Id " << I_Id << " does not exist!" << std::endl; | ||
return **it_elem; | ||
} | ||
|
||
private: | ||
std::string mName; | ||
NodesContainerType mNodes; | ||
ElementsContainerType mElements; | ||
|
||
NodesContainerType::const_iterator FindNode(const IdType I_Id) const | ||
{ | ||
return std::find_if( | ||
mNodes.begin(), mNodes.end(), | ||
[I_Id](const NodePointerType& rp_node) { return rp_node->Id() == I_Id;}); | ||
} | ||
|
||
NodesContainerType::iterator FindNode(const IdType I_Id) | ||
{ | ||
return std::find_if( | ||
mNodes.begin(), mNodes.end(), | ||
[I_Id](const NodePointerType& rp_node) { return rp_node->Id() == I_Id;}); | ||
} | ||
|
||
ElementsContainerType::const_iterator FindElement(const IdType I_Id) const | ||
{ | ||
return std::find_if( | ||
mElements.begin(), mElements.end(), | ||
[I_Id](const ElementPointerType& rp_elem) { return rp_elem->Id() == I_Id;}); | ||
} | ||
|
||
ElementsContainerType::iterator FindElement(const IdType I_Id) | ||
{ | ||
return std::find_if( | ||
mElements.begin(), mElements.end(), | ||
[I_Id](const ElementPointerType& rp_elem) { return rp_elem->Id() == I_Id;}); | ||
} | ||
|
||
bool HasNode(const IdType I_Id) const | ||
{ | ||
return FindNode(I_Id) != mNodes.end(); | ||
} | ||
|
||
bool HasElement(const IdType I_Id) const | ||
{ | ||
return FindElement(I_Id) != mElements.end(); | ||
} | ||
}; | ||
|
||
} //namespace CoSimIO | ||
|
||
#endif // CO_SIM_IO_MODEL_PART_H_INCLUDED |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is here