OGS
DataHolderLib::Project Class Referencefinal

Detailed Description

The ProjectData Object contains all the data needed for a certain project, i.e. all geometric data (stored in a GEOObjects-object), all the meshes, processes, and process variables.

Definition at line 28 of file Project.h.

#include <Project.h>

Collaboration diagram for DataHolderLib::Project:
[legend]

Public Member Functions

 Project ()=default
 Constructor.
 Project (Project &)=delete
 ~Project ()=default
GeoLib::GEOObjectsgetGEOObjects ()
 Returns the GEOObjects containing all points, polylines and surfaces.
void addMesh (std::unique_ptr< MeshLib::Mesh > mesh)
const MeshLib::MeshgetMesh (const std::string &name) const
const std::vector< std::unique_ptr< MeshLib::Mesh > > & getMeshObjects () const
 Returns all the meshes with their respective names.
bool removeMesh (const std::string &name)
void addBoundaryCondition (std::unique_ptr< BoundaryCondition > bc)
 Adds a boundary condition to the project.
void addSourceTerm (std::unique_ptr< SourceTerm > st)
 Adds a source term to the project.
std::vector< std::unique_ptr< BoundaryCondition > > const & getBoundaryConditions () const
 Returns the vector of boundary conditions.
std::vector< std::unique_ptr< SourceTerm > > const & getSourceTerms () const
 Returns the vector of source terms.
void removePrimaryVariable (std::string const &primary_var_name)
 Removes a primary variable incl. all associated conditions.
void removeBoundaryCondition (std::string const &primary_var_name, std::string const &param_name)
 Removes one boundary condition.
void removeSourceTerm (std::string const &primary_var_name, std::string const &param_name)
 Remove one source term.

Private Member Functions

bool getUniqueName (std::string &name) const
std::vector< std::unique_ptr< MeshLib::Mesh > >::const_iterator findMeshByName (std::string const &name) const
 Returns an iterator to the first found mesh with the given name.
std::vector< std::unique_ptr< MeshLib::Mesh > >::iterator findMeshByName (std::string const &name)

Private Attributes

GeoLib::GEOObjects _geoObjects
std::vector< std::unique_ptr< MeshLib::Mesh > > _mesh_vec
std::vector< std::unique_ptr< BoundaryCondition > > _boundary_conditions
std::vector< std::unique_ptr< SourceTerm > > _source_terms

Constructor & Destructor Documentation

◆ Project() [1/2]

DataHolderLib::Project::Project ( )
default

Constructor.

Referenced by Project(), and findMeshByName().

◆ Project() [2/2]

DataHolderLib::Project::Project ( Project & )
delete

References Project().

◆ ~Project()

DataHolderLib::Project::~Project ( )
default

Member Function Documentation

◆ addBoundaryCondition()

void DataHolderLib::Project::addBoundaryCondition ( std::unique_ptr< BoundaryCondition > bc)
inline

Adds a boundary condition to the project.

Definition at line 61 of file Project.h.

62 {
63 _boundary_conditions.push_back(std::move(bc));
64 }
std::vector< std::unique_ptr< BoundaryCondition > > _boundary_conditions
Definition Project.h:110

References _boundary_conditions.

◆ addMesh()

void DataHolderLib::Project::addMesh ( std::unique_ptr< MeshLib::Mesh > mesh)

Adds a new mesh under a (possibly new) unique name.

Attention
This might change the given mesh's name.

Definition at line 14 of file Project.cpp.

15{
16 std::string name = mesh->getName();
17 getUniqueName(name);
18 mesh->setName(name);
19 _mesh_vec.push_back(std::move(mesh));
20}
bool getUniqueName(std::string &name) const
Definition Project.cpp:54
std::vector< std::unique_ptr< MeshLib::Mesh > > _mesh_vec
Definition Project.h:109

References _mesh_vec, and getUniqueName().

◆ addSourceTerm()

void DataHolderLib::Project::addSourceTerm ( std::unique_ptr< SourceTerm > st)
inline

Adds a source term to the project.

Definition at line 67 of file Project.h.

68 {
69 _source_terms.push_back(std::move(st));
70 }
std::vector< std::unique_ptr< SourceTerm > > _source_terms
Definition Project.h:111

References _source_terms.

◆ findMeshByName() [1/2]

std::vector< std::unique_ptr< MeshLib::Mesh > >::iterator DataHolderLib::Project::findMeshByName ( std::string const & name)
private

Definition at line 28 of file Project.cpp.

30{
31 return std::find_if(_mesh_vec.begin(), _mesh_vec.end(),
32 [&name](std::unique_ptr<MeshLib::Mesh>& mesh)
33 { return mesh && (name == mesh->getName()); });
34}

References _mesh_vec.

◆ findMeshByName() [2/2]

std::vector< std::unique_ptr< MeshLib::Mesh > >::const_iterator DataHolderLib::Project::findMeshByName ( std::string const & name) const
private

Returns an iterator to the first found mesh with the given name.

Definition at line 23 of file Project.cpp.

24{
25 return const_cast<Project&>(*this).findMeshByName(name);
26}
Project()=default
Constructor.

References Project().

Referenced by getMesh(), and removeMesh().

◆ getBoundaryConditions()

std::vector< std::unique_ptr< BoundaryCondition > > const & DataHolderLib::Project::getBoundaryConditions ( ) const
inline

Returns the vector of boundary conditions.

Definition at line 74 of file Project.h.

75 {
77 }

References _boundary_conditions.

◆ getGEOObjects()

GeoLib::GEOObjects & DataHolderLib::Project::getGEOObjects ( )
inline

Returns the GEOObjects containing all points, polylines and surfaces.

Definition at line 39 of file Project.h.

39{ return _geoObjects; }
GeoLib::GEOObjects _geoObjects
Definition Project.h:108

References _geoObjects.

◆ getMesh()

const MeshLib::Mesh * DataHolderLib::Project::getMesh ( const std::string & name) const

Returns the mesh with the given name or a nullptr if the mesh was not found.

Definition at line 36 of file Project.cpp.

37{
38 auto it = findMeshByName(name);
39 return (it == _mesh_vec.end() ? nullptr : it->get());
40}
std::vector< std::unique_ptr< MeshLib::Mesh > >::const_iterator findMeshByName(std::string const &name) const
Returns an iterator to the first found mesh with the given name.
Definition Project.cpp:23

References _mesh_vec, and findMeshByName().

◆ getMeshObjects()

const std::vector< std::unique_ptr< MeshLib::Mesh > > & DataHolderLib::Project::getMeshObjects ( ) const
inline

Returns all the meshes with their respective names.

Definition at line 50 of file Project.h.

51 {
52 return _mesh_vec;
53 }

References _mesh_vec.

◆ getSourceTerms()

std::vector< std::unique_ptr< SourceTerm > > const & DataHolderLib::Project::getSourceTerms ( ) const
inline

Returns the vector of source terms.

Definition at line 80 of file Project.h.

81 {
82 return _source_terms;
83 }

References _source_terms.

◆ getUniqueName()

bool DataHolderLib::Project::getUniqueName ( std::string & name) const
private

Checks if a mesh with the same name exists and provides a unique name in case of already existing mesh. Returns true if the mesh name is unique. Returns false and changes the provided name to a unique name otherwise.

Definition at line 54 of file Project.cpp.

55{
56 int count(0);
57 bool isUnique(false);
58 std::string cpName;
59
60 while (!isUnique)
61 {
62 isUnique = true;
63 cpName = name;
64
65 count++;
66 // If the original name already exists we start to add numbers to name
67 // for as long as it takes to make the name unique.
68 if (count > 1)
69 {
70 cpName = cpName + "-" + std::to_string(count);
71 }
72
73 for (auto const& mesh : _mesh_vec)
74 {
75 if (cpName == mesh->getName())
76 {
77 isUnique = false;
78 }
79 }
80 }
81
82 // At this point cpName is a unique name and isUnique is true.
83 // If cpName is not the original name, "name" is changed and isUnique is set
84 // to false, indicating that a vector with the original name already exists.
85 if (count > 1)
86 {
87 isUnique = false;
88 name = cpName;
89 }
90 return isUnique;
91}

References _mesh_vec.

Referenced by addMesh().

◆ removeBoundaryCondition()

void DataHolderLib::Project::removeBoundaryCondition ( std::string const & primary_var_name,
std::string const & param_name )

Removes one boundary condition.

Definition at line 116 of file Project.cpp.

118{
119 std::size_t const n_bc(_boundary_conditions.size());
120 for (std::size_t i = 0; i < n_bc; ++i)
121 {
122 if (_boundary_conditions[i]->getProcessVarName() == primary_var_name &&
123 _boundary_conditions[i]->getParamName() == param_name)
124 {
125 _boundary_conditions[i].reset();
127 return;
128 }
129 }
130}

References _boundary_conditions.

Referenced by removePrimaryVariable().

◆ removeMesh()

bool DataHolderLib::Project::removeMesh ( const std::string & name)

Deletes all meshes with the given name and removes them from the list of saved meshes. If any mesh was found for removal, true is returned and false otherwise.

Definition at line 42 of file Project.cpp.

43{
44 auto it = findMeshByName(name);
45 if (it != _mesh_vec.end())
46 {
47 delete it->release();
48 _mesh_vec.erase(it);
49 return true;
50 }
51 return false;
52}

References _mesh_vec, and findMeshByName().

◆ removePrimaryVariable()

void DataHolderLib::Project::removePrimaryVariable ( std::string const & primary_var_name)

Removes a primary variable incl. all associated conditions.

Definition at line 93 of file Project.cpp.

94{
95 std::size_t const n_bc(_boundary_conditions.size());
96 for (int i = n_bc - 1; i >= 0; --i)
97 {
98 if (_boundary_conditions[i]->getProcessVarName() == primary_var_name)
99 {
100 removeBoundaryCondition(primary_var_name,
101 _boundary_conditions[i]->getParamName());
102 }
103 }
104
105 std::size_t const n_st(_source_terms.size());
106 for (int i = n_st - 1; i >= 0; --i)
107 {
108 if (_source_terms[i]->getProcessVarName() == primary_var_name)
109 {
110 removeSourceTerm(primary_var_name,
111 _source_terms[i]->getParamName());
112 }
113 }
114}
void removeSourceTerm(std::string const &primary_var_name, std::string const &param_name)
Remove one source term.
Definition Project.cpp:132
void removeBoundaryCondition(std::string const &primary_var_name, std::string const &param_name)
Removes one boundary condition.
Definition Project.cpp:116

References _boundary_conditions, _source_terms, removeBoundaryCondition(), and removeSourceTerm().

◆ removeSourceTerm()

void DataHolderLib::Project::removeSourceTerm ( std::string const & primary_var_name,
std::string const & param_name )

Remove one source term.

Definition at line 132 of file Project.cpp.

134{
135 std::size_t const n_st(_source_terms.size());
136 for (std::size_t i = 0; i < n_st; ++i)
137 {
138 if (_source_terms[i]->getProcessVarName() == primary_var_name &&
139 _source_terms[i]->getParamName() == param_name)
140 {
141 _source_terms[i].reset();
142 _source_terms.erase(_source_terms.begin() + i);
143 return;
144 }
145 }
146}

References _source_terms.

Referenced by removePrimaryVariable().

Member Data Documentation

◆ _boundary_conditions

std::vector<std::unique_ptr<BoundaryCondition> > DataHolderLib::Project::_boundary_conditions
private

◆ _geoObjects

GeoLib::GEOObjects DataHolderLib::Project::_geoObjects
private

Definition at line 108 of file Project.h.

Referenced by getGEOObjects().

◆ _mesh_vec

std::vector<std::unique_ptr<MeshLib::Mesh> > DataHolderLib::Project::_mesh_vec
private

Definition at line 109 of file Project.h.

Referenced by addMesh(), findMeshByName(), getMesh(), getMeshObjects(), getUniqueName(), and removeMesh().

◆ _source_terms

std::vector<std::unique_ptr<SourceTerm> > DataHolderLib::Project::_source_terms
private

Definition at line 111 of file Project.h.

Referenced by addSourceTerm(), getSourceTerms(), removePrimaryVariable(), and removeSourceTerm().


The documentation for this class was generated from the following files: