diff --git a/ProcessLib/SourceTerms/CreateNodalSourceTerm.cpp b/ProcessLib/SourceTerms/CreateNodalSourceTerm.cpp index 635d1d430d2c75fa8ba8bcef866d7f2fd4f8438b..9c44b09f1a35ea009eb5d87365a80542147bde3c 100644 --- a/ProcessLib/SourceTerms/CreateNodalSourceTerm.cpp +++ b/ProcessLib/SourceTerms/CreateNodalSourceTerm.cpp @@ -16,9 +16,10 @@ namespace ProcessLib { std::unique_ptr<NodalSourceTerm> createNodalSourceTerm( - BaseLib::ConfigTree const& config, - const NumLib::LocalToGlobalIndexMap& dof_table, std::size_t const mesh_id, - std::size_t const node_id, const int variable_id, const int component_id, + BaseLib::ConfigTree const& config, MeshLib::Mesh& st_mesh, + const NumLib::LocalToGlobalIndexMap& dof_table, + std::size_t const bulk_mesh_id, const int variable_id, + const int component_id, std::vector<std::unique_ptr<ProcessLib::ParameterBase>> const& parameters) { DBUG("Constructing NodalSourceTerm from config."); @@ -31,8 +32,8 @@ std::unique_ptr<NodalSourceTerm> createNodalSourceTerm( auto& param = findParameter<double>(param_name, parameters, 1); - return std::make_unique<NodalSourceTerm>( - dof_table, mesh_id, node_id, variable_id, component_id, param); + return std::make_unique<NodalSourceTerm>(dof_table, bulk_mesh_id, st_mesh, + variable_id, component_id, param); } } // namespace ProcessLib diff --git a/ProcessLib/SourceTerms/CreateNodalSourceTerm.h b/ProcessLib/SourceTerms/CreateNodalSourceTerm.h index 7a8bfa7adc64aac4b579861fc4c95f2d11c8ae58..b3f23605d8722c95d81d9bf790cfd72c02729350 100644 --- a/ProcessLib/SourceTerms/CreateNodalSourceTerm.h +++ b/ProcessLib/SourceTerms/CreateNodalSourceTerm.h @@ -15,9 +15,9 @@ namespace ProcessLib { std::unique_ptr<NodalSourceTerm> createNodalSourceTerm( - BaseLib::ConfigTree const& config, + BaseLib::ConfigTree const& config, MeshLib::Mesh& st_mesh, const NumLib::LocalToGlobalIndexMap& dof_table, std::size_t mesh_id, - std::size_t const node_id, const int variable_id, const int component_id, + const int variable_id, const int component_id, std::vector<std::unique_ptr<ProcessLib::ParameterBase>> const& parameters); } // namespace ProcessLib diff --git a/ProcessLib/SourceTerms/NodalSourceTerm.cpp b/ProcessLib/SourceTerms/NodalSourceTerm.cpp index 6811bf8c952e6d80f9fa82deaa5fffd0fb0d92a2..87a1a96b4a818bd9133729e4e266df24d90cdfbc 100644 --- a/ProcessLib/SourceTerms/NodalSourceTerm.cpp +++ b/ProcessLib/SourceTerms/NodalSourceTerm.cpp @@ -14,18 +14,26 @@ namespace ProcessLib { NodalSourceTerm::NodalSourceTerm(const NumLib::LocalToGlobalIndexMap& dof_table, - std::size_t const mesh_id, - std::size_t const node_id, - const int variable_id, const int component_id, + std::size_t const bulk_mesh_id, + MeshLib::Mesh& st_mesh, + const int variable_id, + const int component_id, Parameter<double> const& parameter) : _dof_table(dof_table), - _mesh_id(mesh_id), - _node_id(node_id), + _bulk_mesh_id(bulk_mesh_id), + _st_mesh(st_mesh), _variable_id(variable_id), _component_id(component_id), _parameter(parameter) { DBUG("Create NodalSourceTerm."); + if (!_st_mesh.getProperties().template existsPropertyVector<std::size_t>( + "bulk_node_ids")) + { + OGS_FATAL( + "Required mesh property \"bulk_node_ids\" does not exists on the " + "source term mesh."); + } } void NodalSourceTerm::integrateNodalSourceTerm(const double t, @@ -33,14 +41,22 @@ void NodalSourceTerm::integrateNodalSourceTerm(const double t, { DBUG("Assemble NodalSourceTerm."); - MeshLib::Location const l{_mesh_id, MeshLib::MeshItemType::Node, _node_id}; - auto const index = - _dof_table.getGlobalIndex(l, _variable_id, _component_id); - - SpatialPosition pos; - pos.setNodeID(_node_id); - - b.add(index, _parameter(t, pos).front()); + auto const& bulk_node_ids_map = + *_st_mesh.getProperties().template getPropertyVector<std::size_t>( + "bulk_node_ids"); + for (MeshLib::Node const* const node : _st_mesh.getNodes()) + { + auto const node_id = node->getID(); + MeshLib::Location const l{_bulk_mesh_id, MeshLib::MeshItemType::Node, + bulk_node_ids_map[node_id]}; + auto const index = + _dof_table.getGlobalIndex(l, _variable_id, _component_id); + + SpatialPosition pos; + pos.setNodeID(node_id); + + b.add(index, _parameter(t, pos).front()); + } } } // namespace ProcessLib diff --git a/ProcessLib/SourceTerms/NodalSourceTerm.h b/ProcessLib/SourceTerms/NodalSourceTerm.h index 9ee08a61e01e6d8e62bc26d029f8457671694d65..356550f94fa5c5cf97114abeeaac21cf028f1db6 100644 --- a/ProcessLib/SourceTerms/NodalSourceTerm.h +++ b/ProcessLib/SourceTerms/NodalSourceTerm.h @@ -18,21 +18,19 @@ class NodalSourceTerm final { public: NodalSourceTerm(const NumLib::LocalToGlobalIndexMap& dof_table, - std::size_t const mesh_id, std::size_t const node_id, + std::size_t const bulk_mesh_id, MeshLib::Mesh& st_mesh, const int variable_id, const int component_id, Parameter<double> const& parameter); - void integrateNodalSourceTerm( - const double t, - GlobalVector& b) const; + void integrateNodalSourceTerm(const double t, GlobalVector& b) const; private: NumLib::LocalToGlobalIndexMap const& _dof_table; - std::size_t const _mesh_id; - std::size_t const _node_id; + std::size_t const _bulk_mesh_id; + MeshLib::Mesh& _st_mesh; int const _variable_id; int const _component_id; Parameter<double> const& _parameter; }; -} // namespace ProcessLib +} // namespace ProcessLib diff --git a/ProcessLib/SourceTerms/SourceTermBuilder.cpp b/ProcessLib/SourceTerms/SourceTermBuilder.cpp index 9f2bfeb5c0db3ab7b423771b7723859b08abde12..45d67c87c97c1ea2f382232cf53cb2ea38c1674a 100644 --- a/ProcessLib/SourceTerms/SourceTermBuilder.cpp +++ b/ProcessLib/SourceTerms/SourceTermBuilder.cpp @@ -11,10 +11,6 @@ #include "SourceTermConfig.h" #include "CreateNodalSourceTerm.h" #include "NodalSourceTerm.h" -#include "MeshGeoToolsLib/BoundaryElementsSearcher.h" -#include "MeshGeoToolsLib/CreateSearchLength.h" -#include "MeshGeoToolsLib/MeshNodeSearcher.h" -#include "MeshGeoToolsLib/SearchLength.h" namespace ProcessLib { @@ -45,53 +41,8 @@ std::unique_ptr<NodalSourceTerm> SourceTermBuilder::createNodalSourceTerm( const unsigned /*shapefunction_order*/, std::vector<std::unique_ptr<ProcessLib::ParameterBase>> const& parameters) { - std::unique_ptr<MeshGeoToolsLib::SearchLength> search_length_algorithm = - MeshGeoToolsLib::createSearchLengthAlgorithm(config.config, mesh); - - MeshGeoToolsLib::MeshNodeSearcher const& mesh_node_searcher = - MeshGeoToolsLib::MeshNodeSearcher::getMeshNodeSearcher( - mesh, std::move(search_length_algorithm)); - - // Find nodes' ids on the given mesh on which this source term is defined. - std::vector<std::size_t> ids = - mesh_node_searcher.getMeshNodeIDs(config.geometry); - - // Filter out ids, which are not part of mesh subsets corresponding to - // the variable_id and component_id. - - // Sorted ids of all mesh_subsets. - std::vector<std::size_t> sorted_nodes_ids; - - auto const& mesh_subset = - dof_table.getMeshSubset(variable_id, *config.component_id); - auto const& nodes = mesh_subset.getNodes(); - sorted_nodes_ids.reserve(sorted_nodes_ids.size() + nodes.size()); - std::transform(std::begin(nodes), std::end(nodes), - std::back_inserter(sorted_nodes_ids), - [](MeshLib::Node* const n) { return n->getID(); }); - std::sort(std::begin(sorted_nodes_ids), std::end(sorted_nodes_ids)); - - auto ids_new_end_iterator = std::end(ids); - ids_new_end_iterator = std::remove_if( - std::begin(ids), ids_new_end_iterator, - [&sorted_nodes_ids](std::size_t const node_id) { - return !std::binary_search(std::begin(sorted_nodes_ids), - std::end(sorted_nodes_ids), node_id); - }); - ids.erase(ids_new_end_iterator, std::end(ids)); - - DBUG( - "Found %d nodes for nodal source term for the variable %d and " - "component %d", - ids.size(), variable_id, *config.component_id); - - if (ids.size() != 1) - OGS_FATAL( - "Found %d nodes for nodal source term, but exactly one node is " - "required.", ids.size()); - return ProcessLib::createNodalSourceTerm( - config.config, dof_table, mesh.getID(), ids[0], variable_id, + config.config, config.mesh, dof_table, mesh.getID(), variable_id, *config.component_id, parameters); } diff --git a/ProcessLib/SourceTerms/SourceTermBuilder.h b/ProcessLib/SourceTerms/SourceTermBuilder.h index ba060dd534067ca3e5e583253a673ba9794ca79f..76b8373f9188447ce278189beffeef914e9a2972 100644 --- a/ProcessLib/SourceTerms/SourceTermBuilder.h +++ b/ProcessLib/SourceTerms/SourceTermBuilder.h @@ -12,22 +12,11 @@ #include "NodalSourceTerm.h" #include "ProcessLib/Parameter/Parameter.h" -namespace GeoLib -{ -class GeoObject; -} - namespace MeshLib { -class Element; class Mesh; } -namespace MeshGeoToolsLib -{ -class BoundaryElementsSearcher; -} - namespace NumLib { class LocalToGlobalIndexMap; diff --git a/ProcessLib/SourceTerms/SourceTermConfig.h b/ProcessLib/SourceTerms/SourceTermConfig.h index c18ab2db0990b5b5353c5a3e4c29b1515b927df2..935aab28cf7dc1bd129cc3a7f5d547f6e3b233f1 100644 --- a/ProcessLib/SourceTerms/SourceTermConfig.h +++ b/ProcessLib/SourceTerms/SourceTermConfig.h @@ -10,30 +10,28 @@ #pragma once #include "BaseLib/ConfigTree.h" -#include "GeoLib/GEOObjects.h" +#include "MeshLib/Mesh.h" namespace ProcessLib { struct SourceTermConfig final { SourceTermConfig(BaseLib::ConfigTree&& config_, - GeoLib::GeoObject const& geometry_, + MeshLib::Mesh& mesh_, boost::optional<int> const component_id_) - : config(std::move(config_)), - geometry(geometry_), - component_id(component_id_) + : config(std::move(config_)), mesh(mesh_), component_id(component_id_) { } SourceTermConfig(SourceTermConfig&& other) : config(std::move(other.config)), - geometry(other.geometry), + mesh(other.mesh), component_id(other.component_id) { } BaseLib::ConfigTree config; - GeoLib::GeoObject const& geometry; + MeshLib::Mesh& mesh; boost::optional<int> const component_id; };