Skip to content
Snippets Groups Projects
Commit 621165b1 authored by Tom Fischer's avatar Tom Fischer
Browse files

Merge branch 'SmallCompilationSpeedups' into 'master'

Compilation speedup, refactorings using ranges, remove dead code.

See merge request ogs/ogs!4650
parents ec016224 2f18c2b6
No related branches found
No related tags found
No related merge requests found
......@@ -20,6 +20,7 @@
#include <cctype>
#include <range/v3/action/sort.hpp>
#include <range/v3/action/unique.hpp>
#include <range/v3/algorithm/contains.hpp>
#include <range/v3/range/conversion.hpp>
#include <set>
......@@ -1157,10 +1158,9 @@ void ProjectData::parseProcesses(
OGS_FATAL("Unknown process type: {:s}", type);
}
if (BaseLib::containsIf(
_processes,
[&name](std::unique_ptr<ProcessLib::Process> const& p)
{ return p->name == name; }))
if (ranges::contains(_processes, name,
[](std::unique_ptr<ProcessLib::Process> const& p)
{ return p->name; }))
{
OGS_FATAL("The process name '{:s}' is not unique.", name);
}
......
......@@ -18,12 +18,15 @@
#include <spdlog/spdlog.h>
#include <numeric>
#include <range/v3/algorithm/copy.hpp>
#include <range/v3/numeric.hpp>
#include <range/v3/range/conversion.hpp>
#include <range/v3/view/enumerate.hpp>
#include <range/v3/view/indirect.hpp>
#include <range/v3/view/join.hpp>
#include <range/v3/view/map.hpp>
#include <range/v3/view/transform.hpp>
#include <span>
#include <vector>
#include "BaseLib/ExportSymbol.h"
......@@ -39,14 +42,8 @@ OGSMesh::OGSMesh(MeshLib::Mesh& mesh) : _mesh(mesh) {}
std::vector<double> OGSMesh::getPointCoordinates() const
{
auto const& nodes = _mesh.getNodes();
std::vector<double> coordinates;
for (auto const& coords : nodes | MeshLib::views::coords)
{
std::copy(coords.begin(), coords.end(),
std::back_inserter(coordinates));
}
return coordinates;
return ranges::to<std::vector>(_mesh.getNodes() | MeshLib::views::coords |
ranges::views::join);
}
std::pair<std::vector<int>, std::vector<int>> OGSMesh::getCells() const
......@@ -56,13 +53,9 @@ std::pair<std::vector<int>, std::vector<int>> OGSMesh::getCells() const
std::vector<int> cell_types;
for (auto const* element : elements)
{
auto const number_of_nodes =
static_cast<int>(element->getNumberOfNodes());
cells.push_back(number_of_nodes);
for (int i = 0; i < number_of_nodes; ++i)
{
cells.push_back(element->getNode(i)->getID());
}
cells.push_back(static_cast<int>(element->getNumberOfNodes()));
ranges::copy(element->nodes() | MeshLib::views::ids,
std::back_inserter(cells));
cell_types.push_back(OGSToVtkCellType(element->getCellType()));
}
return {cells, cell_types};
......@@ -97,11 +90,7 @@ std::vector<double> OGSMesh::getPointDataArray(
{
OGS_FATAL("Couldn't access point/node property '{}'.", name);
}
std::vector<double> data_array;
data_array.reserve(pv->getNumberOfTuples() * number_of_components);
std::copy(pv->begin(), pv->end(), std::back_inserter(data_array));
return data_array;
return ranges::to<std::vector>(std::span(pv->data(), pv->size()));
}
void OGSMesh::setCellDataArray(std::string const& name,
......@@ -133,9 +122,5 @@ std::vector<double> OGSMesh::getCellDataArray(
{
OGS_FATAL("Couldn't access cell/element property '{}'.", name);
}
std::vector<double> data_array;
data_array.reserve(pv->getNumberOfTuples() * number_of_components);
std::copy(pv->begin(), pv->end(), std::back_inserter(data_array));
return data_array;
return ranges::to<std::vector>(std::span(pv->data(), pv->size()));
}
......@@ -9,25 +9,16 @@
*
*/
#include <pybind11/eigen.h>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <spdlog/spdlog.h>
#include <numeric>
#include <range/v3/numeric.hpp>
#include <range/v3/range/conversion.hpp>
#include <range/v3/view/enumerate.hpp>
#include <range/v3/view/indirect.hpp>
#include <range/v3/view/map.hpp>
#include <range/v3/view/transform.hpp>
#include <string>
#include <utility>
#include <vector>
#include "BaseLib/ExportSymbol.h"
#include "BaseLib/Logging.h"
#include "InfoLib/GitInfo.h"
#include "MeshLib/Mesh.h"
#include "MeshLib/Node.h"
namespace MeshLib
{
class Mesh;
}
// Needs to be exported, see
// https://pybind11.readthedocs.io/en/stable/advanced/misc.html#partitioning-code-over-multiple-extension-modules
......
......@@ -78,25 +78,6 @@ typename std::iterator_traits<InputIt>::reference findElementOrError(
return *it;
}
//! Inserts the given \c key with the given \c value into the \c map if an entry
//! with the
//! given \c key does not yet exist; otherwise an \c error_message is printed
//! and the
//! program is aborted.
//! Note: The type of \c key must be std::type_index.
template <typename Map, typename Key, typename Value>
void insertIfTypeIndexKeyUniqueElseError(Map& map, Key const& key,
Value&& value,
std::string const& error_message)
{
auto const inserted = map.emplace(key, std::forward<Value>(value));
if (!inserted.second)
{ // insertion failed, i.e., key already exists
OGS_FATAL("{:s} Key `{:s}' already exists.", error_message,
std::to_string(key.hash_code()));
}
}
//! Inserts the given \c key with the given \c value into the \c map if an entry
//! with the
//! given \c key does not yet exist; otherwise an \c error_message is printed
......@@ -113,31 +94,6 @@ void insertIfKeyUniqueElseError(Map& map, Key const& key, Value&& value,
}
}
//! Inserts the given \c key with the given \c value into the \c map if neither
//! an entry
//! with the given \c key nor an entry with the given \c value already exists;
//! otherwise an \c error_message is printed and the program is aborted.
template <typename Map, typename Key, typename Value>
void insertIfKeyValueUniqueElseError(Map& map, Key const& key, Value&& value,
std::string const& error_message)
{
auto value_compare = [&value](typename Map::value_type const& elem)
{ return value == elem.second; };
if (std::find_if(map.cbegin(), map.cend(), value_compare) != map.cend())
{
OGS_FATAL("{:s} Value `{:s}' already exists.", error_message,
std::to_string(value));
}
auto const inserted = map.emplace(key, std::forward<Value>(value));
if (!inserted.second)
{ // insertion failed, i.e., key already exists
OGS_FATAL("{:s} Key `{:s}' already exists.", error_message,
std::to_string(key));
}
}
//! Returns the value of \c key from the given \c map if such an entry exists;
//! otherwise an \c error_message is printed and the program is aborted.
//! Cf. also the const overload below.
......@@ -252,21 +208,6 @@ void uniquePushBack(Container& container,
}
}
template <typename Container>
bool contains(Container const& container,
typename Container::value_type const& element)
{
return std::find(container.begin(), container.end(), element) !=
container.end();
}
template <typename Container, typename Predicate>
bool containsIf(Container const& container, Predicate&& predicate)
{
return std::find_if(container.begin(), container.end(), predicate) !=
container.end();
}
template <typename Container>
std::optional<typename Container::value_type> findFirstNotEqualElement(
Container const& container, typename Container::value_type const& element)
......
......@@ -12,6 +12,7 @@
#include "Component.h"
#include "BaseLib/Error.h"
#include "Components/Components.h"
#include "Properties/Properties.h"
......@@ -55,4 +56,18 @@ std::string Component::description() const
{
return "component '" + name + "'";
}
void checkRequiredProperties(
Component const& c, std::span<PropertyType const> const required_properties)
{
for (auto const& p : required_properties)
{
if (!c.hasProperty(p))
{
OGS_FATAL("The property '{:s}' is missing in the component '{:s}'.",
property_enum_to_string[p], c.name);
}
}
}
} // namespace MaterialPropertyLib
......@@ -11,7 +11,8 @@
*/
#pragma once
#include "BaseLib/Error.h"
#include <span>
#include "Property.h"
namespace MaterialPropertyLib
......@@ -92,18 +93,8 @@ protected:
std::unique_ptr<Component> newComponent(std::string const& component_name,
bool& isCustomComponent);
template <typename Container>
void checkRequiredProperties(Component const& c,
Container const& required_properties)
{
for (auto const& p : required_properties)
{
if (!c.hasProperty(p))
{
OGS_FATAL("The property '{:s}' is missing in the component '{:s}'.",
property_enum_to_string[p], c.name);
}
}
}
void checkRequiredProperties(
Component const& c,
std::span<PropertyType const> const required_properties);
} // namespace MaterialPropertyLib
......@@ -13,6 +13,7 @@
#include "Medium.h"
#include "BaseLib/Algorithm.h"
#include "BaseLib/Error.h"
#include "Properties/Properties.h"
namespace MaterialPropertyLib
......@@ -81,6 +82,21 @@ std::string Medium::description() const
return "medium " + std::to_string(material_id_);
}
void checkRequiredProperties(
Medium const& medium,
std::span<PropertyType const> const required_properties)
{
for (auto const& p : required_properties)
{
if (!medium.hasProperty(p))
{
OGS_FATAL(
"The property '{:s}' is missing in the medium definition.",
property_enum_to_string[p]);
}
}
}
Phase const& fluidPhase(Medium const& medium)
{
if (medium.hasPhase("Gas"))
......
......@@ -12,10 +12,10 @@
#pragma once
#include <memory>
#include <span>
#include <string>
#include <vector>
#include "BaseLib/Error.h"
#include "Phase.h"
namespace MaterialPropertyLib
......@@ -105,20 +105,9 @@ private:
int const material_id_;
};
template <typename Container>
void checkRequiredProperties(Medium const& medium,
Container const& required_properties)
{
for (auto const& p : required_properties)
{
if (!medium.hasProperty(p))
{
OGS_FATAL(
"The property '{:s}' is missing in the medium definition.",
property_enum_to_string[p]);
}
}
}
void checkRequiredProperties(
Medium const& medium,
std::span<PropertyType const> const required_properties);
/// Returns a gas or aqueous liquid phase of the given medium.
Phase const& fluidPhase(Medium const& medium);
......
......@@ -13,6 +13,7 @@
#include "Phase.h"
#include "BaseLib/Algorithm.h"
#include "BaseLib/Error.h"
#include "Component.h"
#include "Properties/Properties.h"
......@@ -78,4 +79,18 @@ std::string Phase::description() const
{
return "phase '" + name + "'";
}
void checkRequiredProperties(
Phase const& phase, std::span<PropertyType const> const required_properties)
{
for (auto const& p : required_properties)
{
if (!phase.hasProperty(p))
{
OGS_FATAL("The property '{:s}' is missing in the {:s} phase.",
property_enum_to_string[p], phase.name);
}
}
}
} // namespace MaterialPropertyLib
......@@ -12,6 +12,7 @@
#pragma once
#include <memory>
#include <span>
#include <string>
#include <vector>
......@@ -71,17 +72,8 @@ private:
PropertyArray properties_;
};
template <typename Container>
void checkRequiredProperties(Phase const& phase, Container const& required_properties)
{
for (auto const& p : required_properties)
{
if (!phase.hasProperty(p))
{
OGS_FATAL("The property '{:s}' is missing in the {:s} phase.",
property_enum_to_string[p], phase.name);
}
}
}
void checkRequiredProperties(
Phase const& phase,
std::span<PropertyType const> const required_properties);
} // namespace MaterialPropertyLib
......@@ -12,6 +12,8 @@
*/
#include "DeactivatedSubdomain.h"
#include <range/v3/algorithm/contains.hpp>
#include "BaseLib/Error.h"
#include "MeshLib/Elements/Element.h"
#include "MeshLib/Node.h"
......@@ -32,7 +34,7 @@ bool DeactivatedSubdomain::isDeactivated(MeshLib::Element const& element,
double const time) const
{
auto const& bulk_element_ids = deactivated_subdomain_mesh.bulk_element_ids;
if (!BaseLib::contains(bulk_element_ids, element.getID()))
if (!ranges::contains(bulk_element_ids, element.getID()))
{
return false;
}
......
......@@ -19,7 +19,6 @@
#include <vector>
#include "MathLib/InterpolationAlgorithms/PiecewiseLinearInterpolation.h"
#include "MathLib/Point3d.h"
#include "MeshLib/Mesh.h"
#include "processlib_export.h"
......
......@@ -11,8 +11,8 @@
#include <boost/math/special_functions/sign.hpp>
#include <numeric>
#include <range/v3/algorithm/contains.hpp>
#include "BaseLib/Algorithm.h"
#include "BranchProperty.h"
#include "FractureProperty.h"
#include "JunctionProperty.h"
......@@ -126,7 +126,7 @@ std::vector<double> duGlobalEnrichments(
for (unsigned i = 0; i < junction_props.size(); i++)
{
auto const* junction = junction_props[i];
if (!BaseLib::contains(junction->fracture_ids, this_frac.fracture_id))
if (!ranges::contains(junction->fracture_ids, this_frac.fracture_id))
{
continue;
}
......
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