25 std::unique_ptr<ProcessLib::AbstractJacobianAssembler>&& jacobian_assembler,
26 std::vector<std::unique_ptr<ParameterLib::ParameterBase>>
const& parameters,
27 unsigned const integration_order,
28 std::vector<std::vector<std::reference_wrapper<ProcessVariable>>>&&
33 :
Process(std::move(
name), mesh, std::move(jacobian_assembler), parameters,
34 integration_order, std::move(process_variables),
35 std::move(secondary_variables)),
37 process_data._is_linear,
39 _process_data(std::move(process_data)),
40 _bheMeshData(std::move(bhe_mesh_data))
43 this->_jacobian_assembler->setNonDeformationComponentIDs(
46 if (_bheMeshData.BHE_mat_IDs.size() !=
47 _process_data._vec_BHE_property.size())
50 "The number of the given BHE properties ({:d}) are not consistent "
51 "with the number of BHE groups in the mesh ({:d}).",
52 _process_data._vec_BHE_property.size(),
53 _bheMeshData.BHE_mat_IDs.size());
57 if (material_ids ==
nullptr)
59 OGS_FATAL(
"Not able to get material IDs! ");
62 _process_data._mesh_prop_materialIDs = material_ids;
65 for (
int i = 0; i < static_cast<int>(_bheMeshData.BHE_mat_IDs.size()); i++)
68 _process_data._map_materialID_to_BHE_ID[_bheMeshData.BHE_mat_IDs[i]] =
77 std::make_unique<MeshLib::MeshSubset>(
_mesh,
_mesh.getNodes());
83 std::make_unique<MeshLib::MeshSubset>(
_mesh,
_mesh.getNodes());
86 std::vector<std::vector<MeshLib::Element*>
const*> vec_var_elements;
87 vec_var_elements.push_back(&(
_mesh.getElements()));
89 std::vector<int> vec_n_components{
96 assert(n_BHEs ==
static_cast<int>(
_bheMeshData.BHE_mat_IDs.size()));
97 assert(n_BHEs ==
static_cast<int>(
_bheMeshData.BHE_nodes.size()));
98 assert(n_BHEs ==
static_cast<int>(
_bheMeshData.BHE_elements.size()));
101 for (
int i = 0; i < n_BHEs; i++)
103 auto const number_of_unknowns =
104 visit([](
auto const& bhe) {
return bhe.number_of_unknowns; },
107 auto const& bhe_elements =
_bheMeshData.BHE_elements[i];
111 std::make_unique<MeshLib::MeshSubset const>(
_mesh, bhe_nodes));
113 std::generate_n(std::back_inserter(all_mesh_subsets),
120 vec_n_components.push_back(number_of_unknowns);
121 vec_var_elements.push_back(&bhe_elements);
125 std::make_unique<NumLib::LocalToGlobalIndexMap>(
126 std::move(all_mesh_subsets),
138 unsigned const integration_order)
141 std::unordered_map<std::size_t, BHE::BHETypes*> element_to_bhe_map;
143 for (
int i = 0; i < n_BHEs; i++)
145 auto const& bhe_elements =
_bheMeshData.BHE_elements[i];
146 for (
auto const& e : bhe_elements)
148 element_to_bhe_map[e->getID()] =
177 ranges::to<std::vector>();
187 ranges::to<std::vector>();
192 std::vector<std::size_t>
const bhes_node_ids =
194 ranges::views::transform([](
auto const*
const node)
195 {
return node->getID(); }) |
196 ranges::to<std::vector>;
205 for (
auto const id : es.getSearchedElementIDs())
212std::vector<std::vector<std::string>>
214 std::vector<std::reference_wrapper<MeshLib::Mesh>>
const& meshes)
216 DBUG(
"T-BHE process initializeSubmeshOutput().");
218 namespace R = ranges;
219 namespace RV = ranges::views;
221 auto get_residuum_name =
224 std::string
const& pv_name = pv.getName();
225 if (pv_name.starts_with(
"temperature_"))
227 using namespace std::literals;
228 auto const len_temp =
"temperature_"s.size();
230 return "HeatFlowRate_" + pv_name.substr(len_temp);
233 OGS_FATAL(
"Unexpected process variable name '{}'.", pv_name);
236 auto get_residuum_names = [get_residuum_name](
auto const& pvs)
237 {
return pvs | RV::transform(get_residuum_name); };
240 RV::transform(get_residuum_names) |
241 R::to<std::vector<std::vector<std::string>>>();
244 meshes, residuum_names);
246 return residuum_names;
250 const double t,
double const dt, std::vector<GlobalVector*>
const& x,
251 std::vector<GlobalVector*>
const& x_prev,
int const process_id,
254 DBUG(
"Assemble HeatTransportBHE process.");
261 "Domain Deactivation is currently not implemented with "
262 "linear optimization.");
276 std::vector<NumLib::LocalToGlobalIndexMap const*> dof_table = {
281 process_id, &M, &K, &b);
287 process_id, M, K, b);
300 const double t,
double const dt, std::vector<GlobalVector*>
const& x,
301 std::vector<GlobalVector*>
const& x_prev,
int const process_id,
304 DBUG(
"AssembleWithJacobian HeatTransportBHE process.");
307 t, dt, x, x_prev, process_id, b, Jac);
311 double const t,
double const dt, std::vector<GlobalVector*>
const& x,
314 DBUG(
"Compute heat flux for HeatTransportBHE process.");
316 std::vector<NumLib::LocalToGlobalIndexMap const*> dof_tables;
317 dof_tables.reserve(x.size());
318 std::generate_n(std::back_inserter(dof_tables), x.size(),
319 [&]() { return _local_to_global_index_map.get(); });
336 auto const Tout_nodes_id =
338 const std::size_t n_bc_nodes = Tout_nodes_id.size();
340 for (std::size_t i = 0; i < n_bc_nodes; i++)
343 std::get<2>(
_process_data.py_bc_object->dataframe_network)[i] =
347 auto const tespy_result =
_process_data.py_bc_object->tespySolver(
353 DBUG(
"Method `tespySolver' not overridden in Python script.");
357 for (std::size_t i = 0; i < n_bc_nodes; i++)
359 std::get<1>(
_process_data.py_bc_object->dataframe_network)[i] =
360 std::get<2>(tespy_result)[i];
361 std::get<4>(
_process_data.py_bc_object->dataframe_network)[i] =
362 std::get<3>(tespy_result)[i];
364 auto const tespy_has_converged = std::get<1>(tespy_result);
365 if (tespy_has_converged ==
true)
372 std::vector<GlobalVector*>
const& x,
const double t,
const double dt,
373 int const process_id)
383 auto& [time, Tin_value, Tout_value, Tout_nodes_ids, flowrate] =
391 auto const& solution = *x[process_id];
394 const std::size_t n_bc_nodes = Tout_nodes_ids.size();
395 for (std::size_t i = 0; i < n_bc_nodes; i++)
398 Tout_value[i] = solution[Tout_nodes_ids[i]];
402 auto const server_communication_result =
404 t, dt, Tin_value, Tout_value, flowrate);
406 ->isOverriddenServerCommunicationPreTimestep())
408 DBUG(
"Method `serverCommunication' not overridden in Python script.");
411 auto const& [server_communication_Tin_value,
412 server_communication_flowrate] = server_communication_result;
414 std::copy(begin(server_communication_Tin_value),
415 end(server_communication_Tin_value),
417 std::copy(begin(server_communication_flowrate),
418 end(server_communication_flowrate),
423 std::vector<GlobalVector*>
const& x,
424 std::vector<GlobalVector*>
const& ,
const double t,
425 const double dt,
int const process_id)
433 auto& [time, Tin_value, Tout_value, Tout_nodes_ids, flowrate] =
441 auto const& solution = *x[process_id];
444 const std::size_t n_bc_nodes = Tout_nodes_ids.size();
445 for (std::size_t i = 0; i < n_bc_nodes; i++)
448 Tout_value[i] = solution[Tout_nodes_ids[i]];
453 t, dt, Tin_value, Tout_value, flowrate);
455 ->isOverriddenServerCommunicationPostTimestep())
457 DBUG(
"Method `serverCommunication' not overridden in Python script.");
462 [[maybe_unused]]
const double t,
double const ,
463 [[maybe_unused]] std::vector<GlobalVector*>
const& x,
464 std::vector<GlobalVector*>
const& ,
int const ,
469 auto M_normal = M.getRawMatrix();
470 auto K_normal = K.getRawMatrix();
471 auto n_original_rows = K_normal.rows();
477 const double w_val =
_process_data._algebraic_BC_Setting._weighting_factor;
479 M_normal.conservativeResize(
480 M_normal.rows() + n_BHE_bottom_pairs + n_BHE_top_pairs,
482 K_normal.conservativeResize(
483 K_normal.rows() + n_BHE_bottom_pairs + n_BHE_top_pairs,
486 for (std::size_t i = 0; i < n_BHE_bottom_pairs; i++)
488 Eigen::SparseVector<double> M_Plus(M_normal.cols());
490 M_normal.row(n_original_rows + i) = M_Plus;
492 Eigen::SparseVector<double> K_Plus(K_normal.cols());
495 auto const [bhe_idx, first_BHE_bottom_index, second_BHE_bottom_index] =
498 K_Plus.insert(first_BHE_bottom_index) = w_val;
499 K_Plus.insert(second_BHE_bottom_index) = -w_val;
501 K_normal.row(n_original_rows + i) = K_Plus;
504 auto b_normal = b.getRawVector();
505 Eigen::SparseVector<double> b_Plus(b_normal.rows() + n_BHE_bottom_pairs +
510 for (
int i = 0; i < b_normal.innerSize(); ++i)
512 b_Plus.insert(i) = b_normal.coeff(i);
515 for (std::size_t i = 0; i < n_BHE_top_pairs; i++)
517 Eigen::SparseVector<double> M_Plus(M_normal.cols());
519 M_normal.row(n_original_rows + n_BHE_bottom_pairs + i) = M_Plus;
521 Eigen::SparseVector<double> K_Plus(K_normal.cols());
524 auto const [bhe_idx, first_BHE_top_index, second_BHE_top_index] =
527 auto first_BHE_top_index_pair = first_BHE_top_index;
528 auto second_BHE_top_index_pair = second_BHE_top_index;
530 K_Plus.insert(first_BHE_top_index_pair) =
532 K_Plus.insert(second_BHE_top_index_pair) =
535 K_normal.row(n_original_rows + n_BHE_bottom_pairs + i) = K_Plus;
538 double const T_out = (*x[0])[second_BHE_top_index_pair];
540 auto calculate_delta_T = [&](
auto& bhe)
542 auto const T_in = bhe.updateFlowRateAndTemperature(T_out, t);
545 auto delta_T = std::visit(calculate_delta_T,
548 b_Plus.insert(n_original_rows + n_BHE_bottom_pairs + i) =
552 M.getRawMatrix() = M_normal;
553 K.getRawMatrix() = K_normal;
554 b.getRawVector() = b_Plus;
557 "The Algebraic Boundary Condition is not implemented for use with "
558 "PETsc Library! Simulation will be terminated.");
563 std::vector<std::vector<MeshLib::Node*>>
const& all_bhe_nodes)
565 const int process_id = 0;
568 std::size_t
const n_BHEs =
_process_data._vec_BHE_property.size();
571 for (std::size_t bhe_i = 0; bhe_i < n_BHEs; bhe_i++)
573 auto const& bhe_nodes = all_bhe_nodes[bhe_i];
577 const int variable_id = bhe_i + 1;
579 std::vector<MeshLib::Node*> bhe_boundary_nodes;
583 for (
auto const& bhe_node : bhe_nodes)
586 auto const& connected_elements =
587 _mesh.getElementsConnectedToNode(*bhe_node);
588 const std::size_t n_line_elements = std::count_if(
589 connected_elements.begin(), connected_elements.end(),
591 { return (elem->getDimension() == 1); });
593 if (n_line_elements == 1)
595 bhe_boundary_nodes.push_back(bhe_node);
599 if (bhe_boundary_nodes.size() != 2)
602 "Error!!! The BHE boundary nodes are not correctly found, "
603 "for every single BHE, there should be 2 boundary nodes.");
618 if ((*bhe_boundary_nodes[0])[2] == (*bhe_boundary_nodes[1])[2])
621 "For 1P-type BHE, the BHE inflow and outflow "
622 "nodes are identified according to their mesh node id in "
630 if ((*bhe_boundary_nodes[0])[2] < (*bhe_boundary_nodes[1])[2])
632 std::swap(bhe_boundary_nodes[0], bhe_boundary_nodes[1]);
636 auto get_global_index =
637 [&](std::size_t
const node_id,
int const component)
641 variable_id, component);
644 auto get_global_bhe_bc_indices =
646 std::pair<std::size_t ,
int >, 2>
647 nodes_and_components)
649 return std::make_pair(
650 get_global_index(nodes_and_components[0].first,
651 nodes_and_components[0].second),
652 get_global_index(nodes_and_components[1].first,
653 nodes_and_components[1].second));
656 auto get_global_bhe_bc_indices_with_bhe_idx =
657 [&](std::size_t bhe_idx,
659 std::pair<std::size_t ,
int >, 2>
660 nodes_and_components)
662 return std::make_tuple(
664 get_global_index(nodes_and_components[0].first,
665 nodes_and_components[0].second),
666 get_global_index(nodes_and_components[1].first,
667 nodes_and_components[1].second));
671 [&, bc_top_node_id = bhe_boundary_nodes[0]->getID(),
672 bc_bottom_node_id = bhe_boundary_nodes[1]->getID()](
auto& bhe)
674 for (
auto const& in_out_component_id :
675 bhe.inflow_outflow_bc_component_ids)
677 if (bhe.use_python_bcs ||
678 this->_process_data._use_server_communication)
685 bcs.addBoundaryCondition(
687 get_global_bhe_bc_indices(
688 bhe.getBHEInflowDirichletBCNodesAndComponents(
689 bc_top_node_id, bc_bottom_node_id,
690 in_out_component_id.first)),
697 "The Python Boundary Condition was switched on, "
698 "but the data object does not exist! ");
704 ._use_algebraic_bc &&
710 get_global_bhe_bc_indices_with_bhe_idx(
712 {{{bc_top_node_id, in_out_component_id.first},
714 in_out_component_id.second}}}));
719 bcs.addBoundaryCondition(
721 get_global_bhe_bc_indices(
722 bhe.getBHEInflowDirichletBCNodesAndComponents(
723 bc_top_node_id, bc_bottom_node_id,
724 in_out_component_id.first)),
725 [&bhe](
double const T,
double const t)
727 return bhe.updateFlowRateAndTemperature(T,
733 auto const bottom_nodes_and_components =
734 bhe.getBHEBottomDirichletBCNodesAndComponents(
736 in_out_component_id.first,
737 in_out_component_id.second);
739 if (bottom_nodes_and_components &&
745 bcs.addBoundaryCondition(
747 get_global_bhe_bc_indices(
748 {{{bc_bottom_node_id,
749 in_out_component_id.first},
751 in_out_component_id.second}}})));
753 else if (bottom_nodes_and_components &&
760 get_global_bhe_bc_indices_with_bhe_idx(
762 {{{bc_bottom_node_id, in_out_component_id.first},
764 in_out_component_id.second}}}));
MathLib::EigenMatrix GlobalMatrix
MathLib::EigenVector GlobalVector
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
std::size_t searchByNodeIDs(const std::vector< std::size_t > &nodes)
Marks all elements connecting to any of the given nodes.
bool isAxiallySymmetric() const
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
unsigned getDimension() const
Returns the dimension of the mesh (determined by the maximum dimension over all elements).
std::size_t getNumberOfElements() const
Get the number of elements.
void assemble(double const t, double const dt, std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &x_prev, int const process_id, GlobalMatrix &M, GlobalMatrix &K, GlobalVector &b, std::vector< std::size_t > const *const sorted_element_subset=nullptr, bool const copy_residua_to_mesh=false)
void updateActiveElements()
void initializeAssemblyOnSubmeshes(std::vector< std::reference_wrapper< MeshLib::Mesh > > const &submeshes, std::vector< std::vector< std::string > > const &residuum_names)
void assembleWithJacobian(double const t, double const dt, std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &x_prev, int const process_id, GlobalVector &b, GlobalMatrix &Jac, std::vector< std::size_t > const *const sorted_element_subset=nullptr, bool const copy_residua_to_mesh=false)
std::unique_ptr< MeshLib::MeshSubset const > _mesh_subset_soil_nodes
const BHEMeshData _bheMeshData
void assembleConcreteProcess(const double t, double const dt, std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &x_prev, int const process_id, GlobalMatrix &M, GlobalMatrix &K, GlobalVector &b) override
std::vector< std::unique_ptr< MeshLib::MeshSubset const > > _mesh_subset_BHE_nodes
std::vector< std::tuple< std::size_t, GlobalIndexType, GlobalIndexType > > _vec_bottom_BHE_node_indices
std::vector< std::vector< std::string > > initializeAssemblyOnSubmeshes(std::vector< std::reference_wrapper< MeshLib::Mesh > > const &meshes) override
void computeSecondaryVariableConcrete(double const t, double const dt, std::vector< GlobalVector * > const &x, GlobalVector const &x_prev, int const process_id) override
HeatTransportBHEProcess(std::string name, MeshLib::Mesh &mesh, std::unique_ptr< ProcessLib::AbstractJacobianAssembler > &&jacobian_assembler, std::vector< std::unique_ptr< ParameterLib::ParameterBase > > const ¶meters, unsigned const integration_order, std::vector< std::vector< std::reference_wrapper< ProcessVariable > > > &&process_variables, HeatTransportBHEProcessData &&process_data, SecondaryVariableCollection &&secondary_variables, BHEMeshData &&bhe_mesh_data)
HeatTransportBHEProcessData _process_data
std::vector< std::size_t > _bhes_element_ids
NumLib::IterationResult postIterationConcreteProcess(GlobalVector const &x) override
std::vector< std::unique_ptr< HeatTransportBHELocalAssemblerInterface > > local_assemblers_
void preTimestepConcreteProcess(std::vector< GlobalVector * > const &x, const double t, const double dt, int const process_id) override
std::vector< std::tuple< std::size_t, GlobalIndexType, GlobalIndexType > > _vec_top_BHE_node_indices
void constructDofTable() override
void initializeConcreteProcess(NumLib::LocalToGlobalIndexMap const &dof_table, MeshLib::Mesh const &mesh, unsigned const integration_order) override
Process specific initialization called by initialize().
void algebraicBcConcreteProcess(const double t, double const dt, std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &xdot, int const process_id, GlobalMatrix &M, GlobalMatrix &K, GlobalVector &b)
void assembleWithJacobianConcreteProcess(const double t, double const dt, std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &x_prev, int const process_id, GlobalVector &b, GlobalMatrix &Jac) override
void postTimestepConcreteProcess(std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &x_prev, const double t, const double dt, int const process_id) override
void createBHEBoundaryConditionTopBottom(std::vector< std::vector< MeshLib::Node * > > const &all_bhe_nodes)
std::vector< std::size_t > _soil_element_ids
virtual void computeSecondaryVariable(std::size_t const mesh_item_id, std::vector< NumLib::LocalToGlobalIndexMap const * > const &dof_tables, double const t, double const dt, std::vector< GlobalVector * > const &x, GlobalVector const &x_prev, int const process_id)
std::vector< BoundaryConditionCollection > _boundary_conditions
Process(std::string name_, MeshLib::Mesh &mesh, std::unique_ptr< AbstractJacobianAssembler > &&jacobian_assembler, std::vector< std::unique_ptr< ParameterLib::ParameterBase > > const ¶meters, unsigned const integration_order, std::vector< std::vector< std::reference_wrapper< ProcessVariable > > > &&process_variables, SecondaryVariableCollection &&secondary_variables, const bool use_monolithic_scheme=true)
std::unique_ptr< MeshLib::MeshSubset const > _mesh_subset_all_nodes
std::vector< std::vector< std::reference_wrapper< ProcessVariable > > > _process_variables
std::vector< std::size_t > const & getActiveElementIDs() const
VectorMatrixAssembler _global_assembler
std::unique_ptr< NumLib::LocalToGlobalIndexMap > _local_to_global_index_map
std::unique_ptr< ProcessLib::AbstractJacobianAssembler > _jacobian_assembler
MathLib::MatrixSpecifications getMatrixSpecifications(const int process_id) const override
Handles configuration of several secondary variables from the project file.
void assemble(std::size_t const mesh_item_id, LocalAssemblerInterface &local_assembler, std::vector< NumLib::LocalToGlobalIndexMap const * > const &dof_tables, double const t, double const dt, std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &x_prev, int const process_id, GlobalMatrix *M, GlobalMatrix *K, GlobalVector *b)
IterationResult
Status flags telling the NonlinearSolver if an iteration succeeded.
void setMatrixSparsity(MATRIX &matrix, SPARSITY_PATTERN const &sparsity_pattern)
constexpr ranges::views::view_closure ids
For an element of a range view return its id.
PropertyVector< int > const * materialIDs(Mesh const &mesh)
@ BY_COMPONENT
Ordering data by component type.
std::unique_ptr< BHEInflowDirichletBoundaryCondition< BHEUpdateCallback > > createBHEInflowDirichletBoundaryCondition(std::pair< GlobalIndexType, GlobalIndexType > &&in_out_global_indices, BHEUpdateCallback bhe_update_callback)
std::unique_ptr< BHEBottomDirichletBoundaryCondition > createBHEBottomDirichletBoundaryCondition(std::pair< GlobalIndexType, GlobalIndexType > &&in_out_global_indices)
void createLocalAssemblers(std::vector< MeshLib::Element * > const &mesh_elements, NumLib::LocalToGlobalIndexMap const &dof_table, std::vector< std::unique_ptr< LocalAssemblerInterface > > &local_assemblers, NumLib::IntegrationOrder const integration_order, ExtraCtorArgs &&... extra_ctor_args)
std::unique_ptr< BHEInflowPythonBoundaryCondition< BHEType > > createBHEInflowPythonBoundaryCondition(std::pair< GlobalIndexType, GlobalIndexType > &&in_out_global_indices, BHEType &bhe, BHEInflowPythonBoundaryConditionPythonSideInterface &py_bc_object)
static void executeSelectedMemberOnDereferenced(Method method, Container const &container, std::vector< std::size_t > const &active_container_ids, Args &&... args)
static void executeSelectedMemberDereferenced(Object &object, Method method, Container const &container, std::vector< std::size_t > const &active_container_ids, Args &&... args)