Skip to content
Snippets Groups Projects
Commit 212115cf authored by Dmitri Naumov's avatar Dmitri Naumov Committed by Dmitri Naumov
Browse files

[PL] Update source terms to use meshes.

parent 963b2bd3
No related branches found
No related tags found
No related merge requests found
......@@ -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
......@@ -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
......@@ -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
......@@ -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
......@@ -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);
}
......
......@@ -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;
......
......@@ -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;
};
......
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