Skip to content

Commit

Permalink
Merge branch 'BHE_ID_PRJ' into 'master'
Browse files Browse the repository at this point in the history
Improvement of BHEs definition in prj-file

See merge request ogs/ogs!5106
  • Loading branch information
endJunction committed Oct 28, 2024
2 parents 4fec75f + 993024a commit 366528d
Show file tree
Hide file tree
Showing 11 changed files with 776 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
The "id" is an optional parameter.
It starts with 0, and is referring to different BHEs based on their "MaterialID".
Then those BHEs will follow the configurations defined in this block.
A mixed definition with and without id is not supported.
If "id" is not given, then it will be set automatically with an ascending order, also starting from 0.
With the "id" present, multiple BHEs can share the same configurations defined in a single block without repeating it.
To specify the same definition for all BHE in the project, the notation id="*" can be used.
153 changes: 117 additions & 36 deletions ProcessLib/HeatTransportBHE/CreateHeatTransportBHEProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@

#include "CreateHeatTransportBHEProcess.h"

#include <algorithm>
#include <pybind11/pybind11.h>

#include <algorithm>
#include <map>
#include <ranges>
#include <vector>

#include "BHE/BHETypes.h"
Expand All @@ -21,13 +23,82 @@
#include "BHE/CreateBHEUType.h"
#include "HeatTransportBHEProcess.h"
#include "HeatTransportBHEProcessData.h"
#include "MaterialLib/Utils/MediaCreation.h"
#include "ParameterLib/Utils.h"
#include "ProcessLib/HeatTransportBHE/BHE/MeshUtils.h"
#include "ProcessLib/Output/CreateSecondaryVariables.h"

namespace ProcessLib
{
namespace HeatTransportBHE
{
std::map<std::string_view,
std::function<BHE::BHETypes(
BaseLib::ConfigTree const&,
std::map<std::string,
std::unique_ptr<
MathLib::PiecewiseLinearInterpolation>> const&)>>
bheCreators = {{"1U",
[](auto& config, auto& curves) {
return BHE::BHE_1U(
BHE::createBHEUType<BHE::BHE_1U>(config, curves));
}},
{"2U",
[](auto& config, auto& curves) {
return BHE::BHE_2U(
BHE::createBHEUType<BHE::BHE_2U>(config, curves));
}},
{"CXA",
[](auto& config, auto& curves) {
return BHE::BHE_CXA(BHE::createBHECoaxial<BHE::BHE_CXA>(
config, curves));
}},
{"CXC",
[](auto& config, auto& curves) {
return BHE::BHE_CXC(BHE::createBHECoaxial<BHE::BHE_CXC>(
config, curves));
}},
{"1P", [](auto& config, auto& curves) {
return BHE::BHE_1P(
BHE::createBHE1PType<BHE::BHE_1P>(config, curves));
}}};

void createAndInsertBHE(
const std::string& bhe_type, const std::vector<int>& bhe_ids_of_this_bhe,
const BaseLib::ConfigTree& bhe_config,
std::map<std::string,
std::unique_ptr<MathLib::PiecewiseLinearInterpolation>> const&
curves,
std::map<int, BHE::BHETypes>& bhes_map)
{
auto bhe_creator_it = bheCreators.find(bhe_type);
if (bhe_creator_it == bheCreators.end())
{
OGS_FATAL("Unknown BHE type: {:s}", bhe_type);
}
for (auto const& id : bhe_ids_of_this_bhe)
{
std::pair<std::map<int, BHE::BHETypes>::iterator, bool> result;
if (id == bhe_ids_of_this_bhe[0])
{
result = bhes_map.try_emplace(
id, bhe_creator_it->second(bhe_config, curves));
}
else
{
result = bhes_map.try_emplace(
id, bhes_map.find(bhe_ids_of_this_bhe[0])->second);
}
if (!result.second)
{
OGS_FATAL(
"BHE with id '{:d}' is already present in the list! Check for "
"duplicate definitions of BHE ids.",
id);
}
}
}

std::unique_ptr<Process> createHeatTransportBHEProcess(
std::string const& name,
MeshLib::Mesh& mesh,
Expand Down Expand Up @@ -94,7 +165,8 @@ std::unique_ptr<Process> createHeatTransportBHEProcess(

/// \section parametersbhe Process Parameters
// reading BHE parameters --------------------------------------------------
std::vector<BHE::BHETypes> bhes;

auto bhe_mesh_data = getBHEDataInMesh(mesh);

auto const& bhe_configs =
//! \ogs_file_param{prj__processes__process__HEAT_TRANSPORT_BHE__borehole_heat_exchangers}
Expand Down Expand Up @@ -137,53 +209,61 @@ std::unique_ptr<Process> createHeatTransportBHEProcess(
}
}

std::map<int, BHE::BHETypes> bhes_map;

int bhe_iterator = 0;

for (
auto const& bhe_config :
//! \ogs_file_param{prj__processes__process__HEAT_TRANSPORT_BHE__borehole_heat_exchangers__borehole_heat_exchanger}
bhe_configs.getConfigSubtreeList("borehole_heat_exchanger"))
{
// read in the parameters
const std::string bhe_type =
//! \ogs_file_param{prj__processes__process__HEAT_TRANSPORT_BHE__borehole_heat_exchangers__borehole_heat_exchanger__type}
bhe_config.getConfigParameter<std::string>("type");
auto bhe_id_string =
//! \ogs_file_attr{prj__processes__process__HEAT_TRANSPORT_BHE__borehole_heat_exchangers__borehole_heat_exchanger__id}
bhe_config.getConfigAttribute<std::string>(
"id", std::to_string(bhe_iterator));

if (bhe_type == "1U")
{
bhes.emplace_back(
BHE::createBHEUType<BHE::BHE_1U>(bhe_config, curves));
continue;
}
std::vector<int> bhe_ids_of_this_bhe;

if (bhe_type == "CXA")
if (bhe_id_string == "*")
{
bhes.emplace_back(
BHE::createBHECoaxial<BHE::BHE_CXA>(bhe_config, curves));
continue;
int size = static_cast<int>(bhe_mesh_data.BHE_mat_IDs.size());
bhe_ids_of_this_bhe.resize(size);
std::iota(bhe_ids_of_this_bhe.begin(), bhe_ids_of_this_bhe.end(),
0);
}

if (bhe_type == "CXC")
else
{
bhes.emplace_back(
BHE::createBHECoaxial<BHE::BHE_CXC>(bhe_config, curves));
continue;
bhe_ids_of_this_bhe =
MaterialLib::splitMaterialIdString(bhe_id_string);
}

if (bhe_type == "2U")
{
bhes.emplace_back(
BHE::createBHEUType<BHE::BHE_2U>(bhe_config, curves));
continue;
}
// read in the parameters
const std::string bhe_type =
//! \ogs_file_param{prj__processes__process__HEAT_TRANSPORT_BHE__borehole_heat_exchangers__borehole_heat_exchanger__type}
bhe_config.getConfigParameter<std::string>("type");

if (bhe_type == "1P")
{
bhes.emplace_back(
BHE::createBHE1PType<BHE::BHE_1P>(bhe_config, curves));
continue;
}
OGS_FATAL("Unknown BHE type '{:s}'.", bhe_type);
createAndInsertBHE(bhe_type, bhe_ids_of_this_bhe, bhe_config, curves,
bhes_map);
bhe_iterator++;
}
// end of reading BHE parameters -------------------------------------------

if (static_cast<int>(bhes_map.size()) - 1 != bhes_map.rbegin()->first)
{
OGS_FATAL(
"The maximum given BHE id '{:d}' did not match the number of given "
"BHE definitions '{:d}'. The BHE ids needs to be defined starting "
"from 0, so the maximum BHE id needs to be number of BHE "
"definitions minus 1. After all definitions there are no gaps "
"allowed between the given ids.",
bhes_map.rbegin()->first, bhes_map.size());
}

std::vector<BHE::BHETypes> bhes;
bhes.reserve(bhes_map.size());
std::ranges::copy(bhes_map | std::views::values, std::back_inserter(bhes));
// end of reading BHE parameters
// -------------------------------------------

auto media_map =
MaterialPropertyLib::createMaterialSpatialDistributionMap(media, mesh);
Expand Down Expand Up @@ -261,7 +341,8 @@ std::unique_ptr<Process> createHeatTransportBHEProcess(
return std::make_unique<HeatTransportBHEProcess>(
std::move(name), mesh, std::move(jacobian_assembler), parameters,
integration_order, std::move(process_variables),
std::move(process_data), std::move(secondary_variables));
std::move(process_data), std::move(secondary_variables),
std::move(bhe_mesh_data));
}
} // namespace HeatTransportBHE
} // namespace ProcessLib
5 changes: 3 additions & 2 deletions ProcessLib/HeatTransportBHE/HeatTransportBHEProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ HeatTransportBHEProcess::HeatTransportBHEProcess(
std::vector<std::vector<std::reference_wrapper<ProcessVariable>>>&&
process_variables,
HeatTransportBHEProcessData&& process_data,
SecondaryVariableCollection&& secondary_variables)
SecondaryVariableCollection&& secondary_variables,
BHEMeshData&& bhe_mesh_data)
: Process(std::move(name), mesh, std::move(jacobian_assembler), parameters,
integration_order, std::move(process_variables),
std::move(secondary_variables)),
_process_data(std::move(process_data)),
_bheMeshData(getBHEDataInMesh(mesh))
_bheMeshData(std::move(bhe_mesh_data))
{
if (_bheMeshData.BHE_mat_IDs.size() !=
_process_data._vec_BHE_property.size())
Expand Down
3 changes: 2 additions & 1 deletion ProcessLib/HeatTransportBHE/HeatTransportBHEProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class HeatTransportBHEProcess final : public Process
std::vector<std::vector<std::reference_wrapper<ProcessVariable>>>&&
process_variables,
HeatTransportBHEProcessData&& process_data,
SecondaryVariableCollection&& secondary_variables);
SecondaryVariableCollection&& secondary_variables,
BHEMeshData&& bhe_mesh_data);

//! \name ODESystem interface
//! @{
Expand Down
54 changes: 54 additions & 0 deletions ProcessLib/HeatTransportBHE/Tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,60 @@ AddTest(
3bhes_1_ts_10_t_600.000000.vtu 3bhes_1U_BHE_1_mesh_ts_10_t_600.000000.vtu temperature_BHE1 temperature_BHE1 2e-13 1e-12
)

AddTest(
NAME HeatTransportBHE_3D_3BHEs_BHE_id
PATH Parabolic/T/3D_3BHEs
RUNTIME 14
EXECUTABLE ogs
EXECUTABLE_ARGS 3bhes_id_1U_2U_1U.prj
WRAPPER time
TESTER vtkdiff
REQUIREMENTS NOT OGS_USE_MPI
DIFF_DATA
3bhes_ts_10_t_600.000000.vtu 3bhes_id_ts_10_t_600.000000.vtu temperature_BHE1 temperature_BHE1 0 1e-12
3bhes_ts_10_t_600.000000.vtu 3bhes_id_ts_10_t_600.000000.vtu temperature_BHE2 temperature_BHE2 0 1e-12
3bhes_ts_10_t_600.000000.vtu 3bhes_id_ts_10_t_600.000000.vtu temperature_BHE3 temperature_BHE3 0 1e-12
3bhes_ts_10_t_600.000000.vtu 3bhes_id_ts_10_t_600.000000.vtu temperature_soil temperature_soil 0 1e-12
)

AddTest(
NAME HeatTransportBHE_3D_3BHEs_BHE_id_failcase_id_out_of_range
PATH Parabolic/T/3D_3BHEs
RUNTIME 1
EXECUTABLE ogs
EXECUTABLE_ARGS id_out_of_range.xml
REQUIREMENTS NOT OGS_USE_MPI
PROPERTIES
PASS_REGULAR_EXPRESSION "The maximum given BHE id '100' did not match the number of given BHE definitions '3'. The BHE ids needs to be defined starting from 0, so the maximum BHE id needs to be number of BHE definitions minus 1. After all definitions there are no gaps allowed between the given ids."
)

AddTest(
NAME HeatTransportBHE_3D_3BHEs_BHE_id_failcase_duplicate_id
PATH Parabolic/T/3D_3BHEs
RUNTIME 1
EXECUTABLE ogs
EXECUTABLE_ARGS duplicate_id.xml
REQUIREMENTS NOT OGS_USE_MPI
PROPERTIES
PASS_REGULAR_EXPRESSION "BHE with id '1' is already present in the list! Check for duplicate definitions of BHE ids."
)

AddTest(
NAME HeatTransportBHE_3D_3BHEs_BHE_id_1U
PATH Parabolic/T/3D_3BHEs
RUNTIME 14
EXECUTABLE ogs
EXECUTABLE_ARGS 3bhes_id_1U.prj
WRAPPER time
TESTER vtkdiff
REQUIREMENTS NOT OGS_USE_MPI
DIFF_DATA
3bhes_1U_ts_10_t_600.000000.vtu 3bhes_1U_id_ts_10_t_600.000000.vtu temperature_BHE1 temperature_BHE1 0 1e-12
3bhes_1U_ts_10_t_600.000000.vtu 3bhes_1U_id_ts_10_t_600.000000.vtu temperature_BHE2 temperature_BHE2 0 1e-12
3bhes_1U_ts_10_t_600.000000.vtu 3bhes_1U_id_ts_10_t_600.000000.vtu temperature_BHE3 temperature_BHE3 0 1e-12
3bhes_1U_ts_10_t_600.000000.vtu 3bhes_1U_id_ts_10_t_600.000000.vtu temperature_soil temperature_soil 0 1e-12
)

AddTest(
NAME HeatTransportBHE_3D_BHE_groundwater_advection
PATH Parabolic/T/3D_BHE_GW_advection
Expand Down
29 changes: 29 additions & 0 deletions Tests/Data/Parabolic/T/3D_3BHEs/3bhes_1U_ts_10_t_600.000000.vtu

Large diffs are not rendered by default.

Loading

0 comments on commit 366528d

Please sign in to comment.