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

Merge branch 'ImplementMapBasedAccessInGroupBasedParameter' into 'master'

[ParamLib] Use map instead of vector in GroupedBasedParameter.

Closes #3180

See merge request !3833
parents 1568b83e 8c62075c
No related branches found
No related tags found
No related merge requests found
Showing
with 343 additions and 26 deletions
......@@ -34,8 +34,7 @@ std::unique_ptr<ParameterBase> createGroupBasedParameter(
// parse mapping data
using Values = std::vector<double>;
using Index_Values = std::pair<int, Values>;
std::vector<Index_Values> vec_index_values;
std::map<int, Values> vec_index_values;
//! \ogs_file_param{prj__parameters__parameter__Group__index_values}
for (auto p : config.getConfigSubtreeList("index_values"))
{
......@@ -48,7 +47,7 @@ std::unique_ptr<ParameterBase> createGroupBasedParameter(
if (value)
{
Values values(1, *value);
vec_index_values.emplace_back(index, values);
vec_index_values.emplace(index, values);
continue;
}
}
......@@ -62,53 +61,46 @@ std::unique_ptr<ParameterBase> createGroupBasedParameter(
OGS_FATAL("No value available for constant parameter.");
}
vec_index_values.emplace_back(index, values);
vec_index_values.emplace(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())
#ifndef USE_PETSC // In case of partitioned meshes not all of the material ids
// might be available in the particular partition, therefore
// the check is omitted.
if (std::find(group_id_property->begin(), group_id_property->end(),
p.first) == group_id_property->end())
{
OGS_FATAL(
"Specified property index {:d} does not exist in the property "
"vector {:s}",
p.first, group_id_property_name);
}
#endif
auto const n_values = vec_index_values.begin()->second.size();
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.",
"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);
name, mesh, *group_id_property, vec_index_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);
name, mesh, *group_id_property, vec_index_values);
}
OGS_FATAL("Mesh item type of the specified property is not supported.");
......
......@@ -41,7 +41,7 @@ struct GroupBasedParameter final : public Parameter<T>
GroupBasedParameter(std::string const& name_,
MeshLib::Mesh const& mesh,
MeshLib::PropertyVector<int> const& property,
std::vector<std::vector<double>>
std::map<int, std::vector<double>>
vec_values)
: Parameter<T>(name_, &mesh),
_property_index(property),
......@@ -55,7 +55,7 @@ struct GroupBasedParameter final : public Parameter<T>
{
return _vec_values.empty()
? 0
: static_cast<int>(_vec_values.front().size());
: static_cast<int>(_vec_values.begin()->second.size());
}
std::vector<T> operator()(double const /*t*/,
......@@ -64,11 +64,12 @@ struct GroupBasedParameter final : public Parameter<T>
auto const item_id = getMeshItemID(pos, type<MeshItemType>());
assert(item_id);
int const index = _property_index[item_id.value()];
auto const& values = _vec_values[index];
if (values.empty())
auto const v = _vec_values.find(index);
if (v == _vec_values.end())
{
OGS_FATAL("No data found for the group index {:d}", index);
}
auto const& values = v->second;
if (!this->_coordinate_system)
{
......@@ -99,7 +100,7 @@ private:
}
MeshLib::PropertyVector<int> const& _property_index;
std::vector<std::vector<T>> const _vec_values;
std::map<int, std::vector<T>> const _vec_values;
};
std::unique_ptr<ParameterBase> createGroupBasedParameter(
......
......@@ -487,6 +487,21 @@ AddTest(
square_1e1_neumann_ts_1_t_1_000000_1.vtu square_1e1_neumann_ts_1_t_1_000000_1.vtu pressure pressure 1e-14 0
)
AddTest(
NAME ParallelFEM_SteadyStateDiffusion_cube_2
PATH EllipticPETSc/cube_1x1x1_SteadyStateDiffusion/2
EXECUTABLE ogs
EXECUTABLE_ARGS cube_1e4_anisotropic.prj
WRAPPER mpirun
WRAPPER_ARGS -np 2
TESTER vtkdiff
REQUIREMENTS OGS_USE_MPI
DIFF_DATA
cube_1e4_anisotropic_ts_1_t_1_000000_0.vtu cube_1e4_anisotropic_ts_1_t_1_000000_0.vtu pressure pressure 1e-14 0
cube_1e4_anisotropic_ts_1_t_1_000000_1.vtu cube_1e4_anisotropic_ts_1_t_1_000000_1.vtu pressure pressure 1e-14 0
)
#OgsTest(PROJECTFILE "EllipticPETSc/cube_1x1x1_SteadyStateDiffusion/2/cube_1e4_anisotropic.prj")
# Single core
# CUBE 1x1x1 GROUNDWATER FLOW TESTS
foreach(mesh_size 1e0 1e1 1e2 1e3)
......
<?xml version="1.0" encoding="ISO-8859-1"?>
<OpenGeoSysProject>
<meshes>
<mesh>cube_1x1x1_hex_1e4_material_groups.vtu</mesh>
<mesh>cube_1x1x1_geometry_left.vtu</mesh>
<mesh>cube_1x1x1_geometry_right.vtu</mesh>
</meshes>
<processes>
<process>
<name>SteadyStateDiffusion</name>
<type>STEADY_STATE_DIFFUSION</type>
<integration_order>2</integration_order>
<process_variables>
<process_variable>pressure</process_variable>
</process_variables>
<secondary_variables>
<secondary_variable internal_name="darcy_velocity" output_name="darcy_velocity"/>
</secondary_variables>
</process>
</processes>
<media>
<medium id="0,1,2,3">
<properties>
<property>
<name>diffusion</name>
<type>Parameter</type>
<parameter_name>K</parameter_name>
</property>
<property>
<name>reference_temperature</name>
<type>Constant</type>
<value>293.15</value>
</property>
</properties>
</medium>
</media>
<time_loop>
<processes>
<process ref="SteadyStateDiffusion">
<nonlinear_solver>basic_picard</nonlinear_solver>
<convergence_criterion>
<type>DeltaX</type>
<norm_type>NORM2</norm_type>
<abstol>1.e-6</abstol>
</convergence_criterion>
<time_discretization>
<type>BackwardEuler</type>
</time_discretization>
<time_stepping>
<type>SingleStep</type>
</time_stepping>
</process>
</processes>
<output>
<type>VTK</type>
<prefix>cube_1e4_anisotropic</prefix>
<variables>
<variable>pressure</variable>
<variable>darcy_velocity</variable>
</variables>
<suffix>_ts_{:timestep}_t_{:time}</suffix>
</output>
</time_loop>
<local_coordinate_system>
<basis_vector_0>e0</basis_vector_0>
<basis_vector_1>e1</basis_vector_1>
<basis_vector_2>e2</basis_vector_2>
</local_coordinate_system>
<parameters>
<parameter>
<name>e0</name>
<type>Constant</type>
<values>0.86602540378443864676 0 0.5</values>
</parameter>
<parameter>
<name>e1</name>
<type>Constant</type>
<values>0 1 0</values>
</parameter>
<parameter>
<name>e2</name>
<type>Constant</type>
<values>-0.5 0 0.86602540378443864676</values>
</parameter>
<parameter>
<name>K</name>
<type>Group</type>
<group_id_property>MaterialIDs</group_id_property>
<index_values>
<index>0</index>
<values>1 1 1</values>
</index_values>
<index_values>
<index>1</index>
<values>1 1 0.1</values>
</index_values>
<index_values>
<index>2</index>
<values>0.1 0.1 1</values>
</index_values>
<index_values>
<index>3</index>
<values>1 1 1</values>
</index_values>
<use_local_coordinate_system>true</use_local_coordinate_system>
</parameter>
<parameter>
<name>p0</name>
<type>Constant</type>
<value>0</value>
</parameter>
<parameter>
<name>p_Dirichlet_left</name>
<type>Constant</type>
<value>1</value>
</parameter>
<parameter>
<name>p_Dirichlet_right</name>
<type>Constant</type>
<value>-1</value>
</parameter>
</parameters>
<process_variables>
<process_variable>
<name>pressure</name>
<components>1</components>
<order>1</order>
<initial_condition>p0</initial_condition>
<boundary_conditions>
<boundary_condition>
<mesh>cube_1x1x1_geometry_left</mesh>
<type>Dirichlet</type>
<parameter>p_Dirichlet_left</parameter>
</boundary_condition>
<boundary_condition>
<mesh>cube_1x1x1_geometry_right</mesh>
<type>Dirichlet</type>
<parameter>p_Dirichlet_right</parameter>
</boundary_condition>
</boundary_conditions>
</process_variable>
</process_variables>
<nonlinear_solvers>
<nonlinear_solver>
<name>basic_picard</name>
<type>Picard</type>
<max_iter>10</max_iter>
<linear_solver>general_linear_solver</linear_solver>
</nonlinear_solver>
</nonlinear_solvers>
<linear_solvers>
<linear_solver>
<name>general_linear_solver</name>
<lis>-i cg -p jacobi -tol 1e-16 -maxiter 10000</lis>
<eigen>
<solver_type>CG</solver_type>
<precon_type>DIAGONAL</precon_type>
<max_iteration_step>10000</max_iteration_step>
<error_tolerance>1e-16</error_tolerance>
</eigen>
<petsc>
<prefix>gw</prefix>
<parameters>-gw_ksp_type cg -gw_pc_type bjacobi -gw_ksp_rtol 1e-16 -gw_ksp_max_it 10000</parameters>
</petsc>
</linear_solver>
</linear_solvers>
<test_definition>
<vtkdiff>
<file>cube_1e4_anisotropic_ts_1_t_1_000000_0.vtu</file>
<field>pressure</field>
<absolute_tolerance>1e-14</absolute_tolerance>
<relative_tolerance>0</relative_tolerance>
</vtkdiff>
<vtkdiff>
<file>cube_1e4_anisotropic_ts_1_t_1_000000_1.vtu</file>
<field>pressure</field>
<absolute_tolerance>1e-14</absolute_tolerance>
<relative_tolerance>0</relative_tolerance>
</vtkdiff>
<vtkdiff>
<file>cube_1e4_anisotropic_ts_1_t_1_000000_0.vtu</file>
<field>darcy_velocity</field>
<absolute_tolerance>1e-13</absolute_tolerance>
<relative_tolerance>0</relative_tolerance>
</vtkdiff>
<vtkdiff>
<file>cube_1e4_anisotropic_ts_1_t_1_000000_1.vtu</file>
<field>darcy_velocity</field>
<absolute_tolerance>1e-13</absolute_tolerance>
<relative_tolerance>0</relative_tolerance>
</vtkdiff>
</test_definition>
</OpenGeoSysProject>
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