Revision 71de76f6c662926f5da5408853e22786055a6194 authored by Thomas Fischer on 09 July 2021, 06:29:00 UTC, committed by Thomas Fischer on 30 August 2021, 05:26:04 UTC
The getContent() method is used only on very few places. Especially, it isn't used in the computation of any THMC processes. So the content doesn't need to be stored which saves memory. Furthermore, the time time for reading / initializing a mesh is reduced. In a hex mesh with 100x100x100 elements this saves 2.6% of storage and circa 25% time.
1 parent deb816d
GroupBasedParameter.cpp
/**
* \file
* \copyright
* Copyright (c) 2012-2021, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*/
#include "GroupBasedParameter.h"
#include "BaseLib/ConfigTree.h"
#include "BaseLib/Error.h"
#include "MeshLib/Mesh.h"
namespace ParameterLib
{
std::unique_ptr<ParameterBase> createGroupBasedParameter(
std::string const& name, BaseLib::ConfigTree const& config,
MeshLib::Mesh const& mesh)
{
//! \ogs_file_param{prj__parameters__parameter__type}
config.checkConfigParameter("type", "Group");
// get a property vector of group IDs
std::string const group_id_property_name =
//! \ogs_file_param{prj__parameters__parameter__Group__group_id_property}
config.getConfigParameter<std::string>("group_id_property");
DBUG("Using group_id_property {:s}", group_id_property_name);
auto const& group_id_property =
mesh.getProperties().getPropertyVector<int>(group_id_property_name);
// parse mapping data
using Values = std::vector<double>;
using Index_Values = std::pair<int, Values>;
std::vector<Index_Values> vec_index_values;
//! \ogs_file_param{prj__parameters__parameter__Group__index_values}
for (auto p : config.getConfigSubtreeList("index_values"))
{
//! \ogs_file_param{prj__parameters__parameter__Group__index_values__index}
auto const index = p.getConfigParameter<int>("index");
{
//! \ogs_file_param{prj__parameters__parameter__Group__index_values__value}
auto const value = p.getConfigParameterOptional<double>("value");
if (value)
{
Values values(1, *value);
vec_index_values.emplace_back(index, values);
continue;
}
}
// Value tag not available; continue with required values tag.
//! \ogs_file_param{prj__parameters__parameter__Group__index_values__values}
Values const values = p.getConfigParameter<Values>("values");
if (values.empty())
{
OGS_FATAL("No value available for constant parameter.");
}
vec_index_values.emplace_back(index, values);
}
// check the input
unsigned n_values = vec_index_values.front().second.size();
for (auto p : vec_index_values)
{
auto itr = std::find(group_id_property->begin(),
group_id_property->end(), p.first);
if (itr == group_id_property->end())
{
OGS_FATAL(
"Specified property index {:d} does not exist in the property "
"vector {:s}",
p.first, group_id_property_name);
}
if (p.second.size() != n_values)
{
OGS_FATAL(
"The length of some values ({:d}) is different from the first "
"one ({:d}). "
"The length should be same for all index_values.",
p.second.size(), n_values);
}
}
// create a mapping table
const int max_index =
*std::max_element(group_id_property->begin(), group_id_property->end());
std::vector<Values> vec_values(max_index + 1);
for (auto p : vec_index_values)
{
vec_values[p.first] = p.second;
}
if (group_id_property->getMeshItemType() == MeshLib::MeshItemType::Node)
{
return std::make_unique<
GroupBasedParameter<double, MeshLib::MeshItemType::Node>>(
name, mesh, *group_id_property, vec_values);
}
if (group_id_property->getMeshItemType() == MeshLib::MeshItemType::Cell)
{
return std::make_unique<
GroupBasedParameter<double, MeshLib::MeshItemType::Cell>>(
name, mesh, *group_id_property, vec_values);
}
OGS_FATAL("Mesh item type of the specified property is not supported.");
}
} // namespace ParameterLib
Computing file changes ...