From a12e8891a924bb4e6accc7dc63a8f8db0e7aa79b Mon Sep 17 00:00:00 2001 From: Dmitri Naumov <dmitri.naumov@ufz.de> Date: Wed, 17 Jul 2013 13:40:03 +0200 Subject: [PATCH] Rename ComponentDistribution to MeshSubsets. This reflects the purpouse of this class better. --- .../VecMeshItems/ComponentDistribution.h | 82 ------------------- VecMatOnMeshLib/VecMeshItems/MeshSubsets.h | 78 ++++++++++++++++++ 2 files changed, 78 insertions(+), 82 deletions(-) delete mode 100644 VecMatOnMeshLib/VecMeshItems/ComponentDistribution.h create mode 100644 VecMatOnMeshLib/VecMeshItems/MeshSubsets.h diff --git a/VecMatOnMeshLib/VecMeshItems/ComponentDistribution.h b/VecMatOnMeshLib/VecMeshItems/ComponentDistribution.h deleted file mode 100644 index 82ac8e58f9a..00000000000 --- a/VecMatOnMeshLib/VecMeshItems/ComponentDistribution.h +++ /dev/null @@ -1,82 +0,0 @@ -/** - * \file - * \author Norihiro Watanabe - * \date 2013-04-16 - * \brief - * - * \copyright - * Copyright (c) 2013, OpenGeoSys Community (http://www.opengeosys.org) - * Distributed under a Modified BSD License. - * See accompanying file LICENSE.txt or - * http://www.opengeosys.org/project/license - * - */ - -#ifndef COMPONENTDISTRIBUTION_H_ -#define COMPONENTDISTRIBUTION_H_ - -#include <vector> -#include <numeric> - -#include "MeshSubset.h" - -namespace VecMatOnMeshLib -{ - -/** - * Distribution information of a single data component - * - * This class contains information about on which mesh items a data component is - * assigned. - */ -class ComponentDistribution -{ -public: - - /** - * constructor for a single mesh use - * - * This data component is distributed over the given mesh items in a single mesh - * @param mesh_items - */ - explicit ComponentDistribution(const MeshSubset* mesh_items) - { - _mesh_items.push_back(mesh_items); - _n_total_items = mesh_items->getNTotalItems(); - } - - /** - * constructor for multiple-mesh use - * - * This data component is distributed over the given mesh items in multiple meshes - * @param vec_mesh_items a vector of MeshSubset - */ - explicit ComponentDistribution(const std::vector<MeshSubset*> &vec_mesh_items) - : _mesh_items(vec_mesh_items.begin(), vec_mesh_items.end()) - { - _n_total_items = std::accumulate(vec_mesh_items.begin(), vec_mesh_items.end(), - 0u, - [](std::size_t sum, const MeshSubset* items) - { - return sum+items->getNTotalItems(); - } - ); - } - - /// return the total number of mesh items (in all meshes) where this component is assigned - std::size_t getNMeshItems() const { return _n_total_items; } - - /// return the number of related meshes - unsigned getNMeshes() const { return _mesh_items.size(); } - - /// return MeshSubset - const MeshSubset& getMeshItems(std::size_t mesh_index) const { return *_mesh_items[mesh_index]; } - -private: - std::vector<const MeshSubset*> _mesh_items; - std::size_t _n_total_items; -}; - -} - -#endif /* COMPONENTDISTRIBUTION_H_ */ diff --git a/VecMatOnMeshLib/VecMeshItems/MeshSubsets.h b/VecMatOnMeshLib/VecMeshItems/MeshSubsets.h new file mode 100644 index 00000000000..2013d2a7e80 --- /dev/null +++ b/VecMatOnMeshLib/VecMeshItems/MeshSubsets.h @@ -0,0 +1,78 @@ +/** + * \file + * \author Norihiro Watanabe + * \date 2013-04-16 + * \brief + * + * \copyright + * Copyright (c) 2013, OpenGeoSys Community (http://www.opengeosys.org) + * Distributed under a Modified BSD License. + * See accompanying file LICENSE.txt or + * http://www.opengeosys.org/project/license + * + */ + +#ifndef MESHSUBSETS_H_ +#define MESHSUBSETS_H_ + +#include <vector> +#include <numeric> + +#include "MeshSubset.h" + +namespace VecMatOnMeshLib +{ + +/// Collection of mesh subsets. +class MeshSubsets +{ +public: + + /// Single mesh subset constructor. + explicit MeshSubsets(const MeshSubset* mesh_subset) + { + _mesh_subsets.push_back(mesh_subset); + _n_total_items = mesh_subset->getNTotalItems(); + } + + /// Construct MeshSubsets from a range of MeshSubset. InputIterator must + /// dereferece to MeshSubset*. + template <typename InputIterator> + explicit MeshSubsets(InputIterator const& first, InputIterator const& last) + : _mesh_subsets(first, last) + { + _n_total_items = std::accumulate(first, last, 0u, + [](std::size_t const& sum, MeshSubset const* const mesh_subset) + { + return sum + mesh_subset->getNTotalItems(); + }); + } + + /// return the total number of mesh items (in all meshes) where this component is assigned + std::size_t getNMeshItems() const + { + return _n_total_items; + } + + /// return the number of related meshes + unsigned getNMeshes() const + { + return _mesh_subsets.size(); + } + + /// return MeshSubset + const MeshSubset& getMeshSubset(std::size_t mesh_index) const + { + return *_mesh_subsets[mesh_index]; + } + +private: + std::vector<const MeshSubset*> _mesh_subsets; + + /// Number of all mesh entities on all subsets. + std::size_t _n_total_items; +}; + +} + +#endif // MESHSUBSETS_H_ -- GitLab