Skip to content
Snippets Groups Projects
Commit 45758543 authored by Dmitri Naumov's avatar Dmitri Naumov
Browse files

[PL] Store vector of unique ptr to meshes in prj.

parent 52487299
No related branches found
No related tags found
No related merge requests found
......@@ -120,7 +120,8 @@ ProjectData::ProjectData(BaseLib::ConfigTree const& project_config,
std::string const mesh_file = BaseLib::copyPathToFileName(
mesh_param.getValue<std::string>(), project_directory);
MeshLib::Mesh* const mesh = MeshLib::IO::readMeshFromFile(mesh_file);
auto mesh = std::unique_ptr<MeshLib::Mesh>(
MeshLib::IO::readMeshFromFile(mesh_file));
if (!mesh)
{
OGS_FATAL("Could not read mesh from \'%s\' file. No mesh added.",
......@@ -133,7 +134,7 @@ ProjectData::ProjectData(BaseLib::ConfigTree const& project_config,
{
mesh->setAxiallySymmetric(*axially_symmetric);
}
_mesh_vec.push_back(mesh);
_mesh_vec.push_back(std::move(mesh));
}
std::unique_ptr<MeshGeoToolsLib::SearchLength> search_length_algorithm =
......@@ -143,11 +144,8 @@ ProjectData::ProjectData(BaseLib::ConfigTree const& project_config,
MeshGeoToolsLib::constructAdditionalMeshesFromGeoObjects(
*_geoObjects, *_mesh_vec[0], std::move(search_length_algorithm));
// release the unique_ptr's while copying to the raw pointers storage.
// TODO (naumov) Store unique_ptr's in _mesh_vec.
std::transform(begin(additional_meshes), end(additional_meshes),
std::back_inserter(_mesh_vec),
[](auto&& mesh) { return mesh.release(); });
std::move(begin(additional_meshes), end(additional_meshes),
std::back_inserter(_mesh_vec));
//! \ogs_file_param{prj__curves}
parseCurves(project_config.getConfigSubtreeOptional("curves"));
......@@ -176,9 +174,6 @@ ProjectData::ProjectData(BaseLib::ConfigTree const& project_config,
ProjectData::~ProjectData()
{
delete _geoObjects;
for (MeshLib::Mesh* m : _mesh_vec)
delete m;
}
void ProjectData::parseProcessVariables(
......
......@@ -117,7 +117,7 @@ private:
void parseCurves(boost::optional<BaseLib::ConfigTree> const& config);
GeoLib::GEOObjects* _geoObjects = new GeoLib::GEOObjects();
std::vector<MeshLib::Mesh*> _mesh_vec;
std::vector<std::unique_ptr<MeshLib::Mesh>> _mesh_vec;
std::map<std::string, std::unique_ptr<ProcessLib::Process>> _processes;
std::vector<ProcessLib::ProcessVariable> _process_variables;
......
......@@ -21,7 +21,7 @@ namespace ProcessLib
{
std::unique_ptr<ParameterBase> createParameter(
BaseLib::ConfigTree const& config,
std::vector<MeshLib::Mesh*> const& meshes,
std::vector<std::unique_ptr<MeshLib::Mesh>> const& meshes,
std::map<std::string,
std::unique_ptr<MathLib::PiecewiseLinearInterpolation>> const&
curves)
......
......@@ -121,7 +121,7 @@ struct Parameter : public ParameterBase
//! The \c meshes vector is used to set up parameters from mesh input data.
std::unique_ptr<ParameterBase> createParameter(
BaseLib::ConfigTree const& config,
const std::vector<MeshLib::Mesh*>& meshes,
const std::vector<std::unique_ptr<MeshLib::Mesh>>& meshes,
std::map<std::string,
std::unique_ptr<MathLib::PiecewiseLinearInterpolation>> const&
curves);
......
......@@ -23,7 +23,7 @@ namespace ProcessLib
{
ProcessVariable::ProcessVariable(
BaseLib::ConfigTree const& config,
std::vector<MeshLib::Mesh*> const& meshes,
std::vector<std::unique_ptr<MeshLib::Mesh>> const& meshes,
std::vector<std::unique_ptr<ParameterBase>> const& parameters)
: //! \ogs_file_param{prj__process_variables__process_variable__name}
_name(config.getConfigParameter<std::string>("name")),
......@@ -62,7 +62,7 @@ ProcessVariable::ProcessVariable(
geometrical_set_name + "_" + geometry_name;
auto const mesh_it =
std::find_if(begin(meshes), end(meshes),
[&full_geometry_name](MeshLib::Mesh* const mesh) {
[&full_geometry_name](auto const& mesh) {
assert(mesh != nullptr);
return mesh->getName() == full_geometry_name;
});
......@@ -111,7 +111,7 @@ ProcessVariable::ProcessVariable(
geometrical_set_name + "_" + geometry_name;
auto const mesh_it =
std::find_if(begin(meshes), end(meshes),
[&full_geometry_name](MeshLib::Mesh* const mesh) {
[&full_geometry_name](auto const& mesh) {
assert(mesh != nullptr);
return mesh->getName() == full_geometry_name;
});
......
......@@ -39,7 +39,7 @@ class ProcessVariable
public:
ProcessVariable(
BaseLib::ConfigTree const& config,
std::vector<MeshLib::Mesh*> const& meshes,
std::vector<std::unique_ptr<MeshLib::Mesh>> const& meshes,
std::vector<std::unique_ptr<ParameterBase>> const& parameters);
ProcessVariable(ProcessVariable&&);
......
......@@ -29,7 +29,8 @@
using namespace ProcessLib;
std::unique_ptr<Parameter<double>> constructParameterFromString(
std::string const& xml, std::vector<MeshLib::Mesh*> const meshes,
std::string const& xml,
std::vector<std::unique_ptr<MeshLib::Mesh>> const& meshes,
std::map<std::string,
std::unique_ptr<MathLib::PiecewiseLinearInterpolation>> const&
curves = {})
......@@ -47,15 +48,15 @@ struct ProcessLibParameter : public ::testing::Test
void SetUp() override
{
// A mesh with four elements, five points.
mesh.reset(MeshLib::MeshGenerator::generateLineMesh(4u, 1.0));
meshes.emplace_back(MeshLib::MeshGenerator::generateLineMesh(4u, 1.0));
}
std::unique_ptr<MeshLib::Mesh> mesh;
std::vector<std::unique_ptr<MeshLib::Mesh>> meshes;
};
TEST_F(ProcessLibParameter, GroupBasedParameterElement)
{
std::vector<int> mat_ids({0, 1, 2, 3});
MeshLib::addPropertyToMesh(*mesh, "MaterialIDs",
MeshLib::addPropertyToMesh(*meshes[0], "MaterialIDs",
MeshLib::MeshItemType::Cell, 1, mat_ids);
auto parameter = constructParameterFromString(
......@@ -65,7 +66,7 @@ TEST_F(ProcessLibParameter, GroupBasedParameterElement)
"<index_values><index>0</index><value>0</value></index_values>"
"<index_values><index>1</index><value>100</value></index_values>"
"<index_values><index>3</index><value>300</value></index_values>",
{mesh.get()});
meshes);
double t = 0;
ProcessLib::SpatialPosition x;
......@@ -83,7 +84,7 @@ TEST_F(ProcessLibParameter, GroupBasedParameterElement)
TEST_F(ProcessLibParameter, GroupBasedParameterNode)
{
std::vector<int> group_ids({0, 1, 2, 3, 4});
MeshLib::addPropertyToMesh(*mesh, "PointGroupIDs",
MeshLib::addPropertyToMesh(*meshes[0], "PointGroupIDs",
MeshLib::MeshItemType::Node, 1, group_ids);
auto parameter = constructParameterFromString(
......@@ -93,7 +94,7 @@ TEST_F(ProcessLibParameter, GroupBasedParameterNode)
"<index_values><index>0</index><value>0</value></index_values>"
"<index_values><index>1</index><value>100</value></index_values>"
"<index_values><index>3</index><value>300</value></index_values>",
{mesh.get()});
meshes);
double t = 0;
ProcessLib::SpatialPosition x;
......@@ -151,12 +152,11 @@ bool testNodalValuesOfElement(
// For all elements all nodes have a constant value.
TEST_F(ProcessLibParameter, GetNodalValuesOnElement_constant)
{
auto const parameter = constructParameterFromString(
"<name>parameter</name>"
"<type>Constant</type>"
"<value>42.23</value>",
{mesh.get()});
meshes);
double const t = 0;
auto expected_value = [](MeshLib::Element* const /*e*/,
......@@ -164,21 +164,21 @@ TEST_F(ProcessLibParameter, GetNodalValuesOnElement_constant)
return 42.23;
};
ASSERT_TRUE(testNodalValuesOfElement(mesh->getElements(), expected_value,
*parameter, t));
ASSERT_TRUE(testNodalValuesOfElement(meshes[0]->getElements(),
expected_value, *parameter, t));
}
TEST_F(ProcessLibParameter, GetNodalValuesOnElement_node)
{
std::vector<double> node_ids({0, 1, 2, 3, 4});
MeshLib::addPropertyToMesh(*mesh, "NodeIDs", MeshLib::MeshItemType::Node, 1,
node_ids);
MeshLib::addPropertyToMesh(*meshes[0], "NodeIDs",
MeshLib::MeshItemType::Node, 1, node_ids);
auto const parameter = constructParameterFromString(
"<name>parameter</name>"
"<type>MeshNode</type>"
"<field_name>NodeIDs</field_name>",
{mesh.get()});
meshes);
double const t = 0;
......@@ -188,21 +188,21 @@ TEST_F(ProcessLibParameter, GetNodalValuesOnElement_node)
return static_cast<double>(e->getNode(local_node_id)->getID());
};
ASSERT_TRUE(testNodalValuesOfElement(mesh->getElements(), expected_value,
*parameter, t));
ASSERT_TRUE(testNodalValuesOfElement(meshes[0]->getElements(),
expected_value, *parameter, t));
}
TEST_F(ProcessLibParameter, GetNodalValuesOnElement_element)
{
std::vector<double> element_ids({0, 1, 2, 3});
MeshLib::addPropertyToMesh(*mesh, "ElementIDs", MeshLib::MeshItemType::Cell,
1, element_ids);
MeshLib::addPropertyToMesh(*meshes[0], "ElementIDs",
MeshLib::MeshItemType::Cell, 1, element_ids);
auto const parameter = constructParameterFromString(
"<name>parameter</name>"
"<type>MeshElement</type>"
"<field_name>ElementIDs</field_name>",
{mesh.get()});
meshes);
double const t = 0;
......@@ -212,22 +212,22 @@ TEST_F(ProcessLibParameter, GetNodalValuesOnElement_element)
return static_cast<double>(e->getID());
};
ASSERT_TRUE(testNodalValuesOfElement(mesh->getElements(), expected_value,
*parameter, t));
ASSERT_TRUE(testNodalValuesOfElement(meshes[0]->getElements(),
expected_value, *parameter, t));
}
TEST_F(ProcessLibParameter, GetNodalValuesOnElement_curveScaledNode)
{
std::vector<double> node_ids({0, 1, 2, 3, 4});
MeshLib::addPropertyToMesh(*mesh, "NodeIDs", MeshLib::MeshItemType::Node, 1,
node_ids);
MeshLib::addPropertyToMesh(*meshes[0], "NodeIDs",
MeshLib::MeshItemType::Node, 1, node_ids);
std::vector<std::unique_ptr<ParameterBase>> parameters;
parameters.emplace_back(
constructParameterFromString("<name>NodeIDs</name>"
"<type>MeshNode</type>"
"<field_name>NodeIDs</field_name>",
{mesh.get()}));
meshes));
std::map<std::string,
std::unique_ptr<MathLib::PiecewiseLinearInterpolation>>
......@@ -241,7 +241,7 @@ TEST_F(ProcessLibParameter, GetNodalValuesOnElement_curveScaledNode)
"<type>CurveScaled</type>"
"<curve>linear_curve</curve>"
"<parameter>NodeIDs</parameter>",
{mesh.get()}, curves);
meshes, curves);
parameter->initialize(parameters);
......@@ -253,6 +253,6 @@ TEST_F(ProcessLibParameter, GetNodalValuesOnElement_curveScaledNode)
return static_cast<double>(e->getNode(local_node_id)->getID()) * t;
};
ASSERT_TRUE(testNodalValuesOfElement(mesh->getElements(), expected_value,
*parameter, t));
ASSERT_TRUE(testNodalValuesOfElement(meshes[0]->getElements(),
expected_value, *parameter, t));
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment