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

[ParL] Remove setAll(); use RAII

Improves constness of the local SpatialPosition variables.
parent 17a96c89
No related branches found
No related tags found
No related merge requests found
......@@ -170,11 +170,11 @@ struct Parameter : public ParameterBase
n_components);
// Column vector of values, copied for each node.
SpatialPosition x_position;
auto const nodes = element.getNodes();
for (int i = 0; i < n_nodes; ++i)
{
x_position.setAll(nodes[i]->getID(), element.getID(), *nodes[i]);
SpatialPosition const x_position{nodes[i]->getID(), element.getID(),
*nodes[i]};
auto const& values = this->operator()(t, x_position);
auto const row_values =
Eigen::Map<Eigen::Matrix<T, Eigen::Dynamic, 1> const>(
......
......@@ -22,7 +22,7 @@ namespace ParameterLib
//!
//! The setters of this class make sure that only compatible information can be
//! stored at the same time; e.g., it is not possible to specify an element ID
//! and a node ID at the same time (the setAll() method being an exception to
//! and a node ID at the same time (the constructor being an exception to
//! that rule).
class SpatialPosition
{
......@@ -33,7 +33,22 @@ public:
std::optional<std::size_t> const& element_id,
std::optional<MathLib::Point3d> const& coordinates)
{
setAll(node_id, element_id, coordinates);
if (node_id)
{
_node_id = *node_id;
flags.set(node_bit);
}
if (element_id)
{
_element_id = *element_id;
flags.set(element_bit);
}
if (coordinates)
{
_coordinates = *coordinates;
flags.set(coordinates_bit);
}
}
std::optional<std::size_t> getNodeID() const
......@@ -71,29 +86,6 @@ public:
flags.set(coordinates_bit);
}
void setAll(std::optional<std::size_t> const& node_id,
std::optional<std::size_t> const& element_id,
std::optional<MathLib::Point3d> const& coordinates)
{
flags.reset();
if (node_id)
{
_node_id = *node_id;
flags.set(node_bit);
}
if (element_id)
{
_element_id = *element_id;
flags.set(element_bit);
}
if (coordinates)
{
_coordinates = *coordinates;
flags.set(coordinates_bit);
}
}
private:
std::size_t _node_id = 0;
std::size_t _element_id = 0;
......
......@@ -128,8 +128,6 @@ void ConstraintDirichletBoundaryCondition::getEssentialBCValues(
const double t, const GlobalVector& /*x*/,
NumLib::IndexValueVector<GlobalIndexType>& bc_values) const
{
ParameterLib::SpatialPosition pos;
bc_values.ids.clear();
bc_values.values.clear();
......@@ -153,8 +151,10 @@ void ConstraintDirichletBoundaryCondition::getEssentialBCValues(
unsigned const number_nodes = boundary_element->getNumberOfNodes();
for (unsigned i = 0; i < number_nodes; ++i)
{
auto const id = boundary_element->getNode(i)->getID();
pos.setAll(id, boundary_element->getID(), {});
auto const& node = *boundary_element->getNode(i);
auto const id = node.getID();
ParameterLib::SpatialPosition const pos{
id, boundary_element->getID(), node};
MeshLib::Location l(_bc_mesh.getID(), MeshLib::MeshItemType::Node,
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