Skip to content
Snippets Groups Projects
Commit 85cf56d2 authored by Norihiro Watanabe's avatar Norihiro Watanabe Committed by Dmitri Naumov
Browse files

Part of: add VecMatOnMeshLib toghether with tests

added by Norihiro Watanabe.
parent b17782d5
No related branches found
No related tags found
No related merge requests found
/**
* \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 "MeshItems.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 MeshItems* 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 MeshItems
*/
explicit ComponentDistribution(const std::vector<MeshItems*> &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 MeshItems* 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 MeshItems
const MeshItems& getMeshItems(std::size_t mesh_index) const { return *_mesh_items[mesh_index]; }
private:
std::vector<const MeshItems*> _mesh_items;
std::size_t _n_total_items;
};
}
#endif /* COMPONENTDISTRIBUTION_H_ */
/**
* \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 MESHITEM_H_
#define MESHITEM_H_
#include "MeshItemType.h"
namespace VecMatOnMeshLib
{
/**
* Mesh item data
*
* This data are used in VectorComposition
*/
struct MeshItem
{
std::size_t mesh_id;
MeshItemType::type item_type;
std::size_t item_id;
MeshItem(std::size_t meshid, MeshItemType::type itemtype, std::size_t itemid)
: mesh_id(meshid), item_type(itemtype), item_id(itemid){};
};
inline bool operator<(const MeshItem& left, const MeshItem& right)
{
if (left.mesh_id != right.mesh_id) return left.mesh_id < right.mesh_id;
if (left.item_type != right.item_type) return left.item_type < right.item_type;
return left.item_id < right.item_id;
}
}
#endif /* MESHITEM_H_ */
/**
* \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 MESHITEMTYPE_H_
#define MESHITEMTYPE_H_
namespace VecMatOnMeshLib
{
struct MeshItemType
{
enum type
{
Node,
Edge,
Face,
Cell
};
};
}
#endif /* MESHITEMTYPE_H_ */
/**
* \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 MESHITEMS_H_
#define MESHITEMS_H_
#include <vector>
#include <algorithm>
#include "MeshLib/Mesh.h"
#include "MeshLib/Node.h"
#include "MeshLib/Elements/Element.h"
namespace VecMatOnMeshLib
{
/**
* Collection of mesh items from a single mesh (nodes and elements are currently supported)
*
* Remark: At the moment, this class is only used to return the total number of mesh items
* on which data are assigned.
*/
class MeshItems
{
public:
/// construct from nodes
MeshItems(const MeshLib::Mesh* msh, std::vector<MeshLib::Node*> const& vec_items)
: _msh(msh), _nodes(&vec_items), _eles(nullptr)
{}
/// construct from elements
MeshItems(const MeshLib::Mesh* msh, std::vector<MeshLib::Element*> const& vec_items)
: _msh(msh), _nodes(nullptr), _eles(&vec_items)
{}
/// construct from both nodes and elements
MeshItems(const MeshLib::Mesh* msh,
std::vector<MeshLib::Node*> const& vec_nodes, std::vector<MeshLib::Element*> const& vec_eles)
: _msh(msh), _nodes(&vec_nodes), _eles(&vec_eles)
{}
~MeshItems() {};
/// return the total number of mesh items
std::size_t getNTotalItems() const { return getNNodes() + getNElements(); }
/// return this mesh ID
std::size_t getMeshID() const { return _msh->getID(); }
/// return the number of registered nodes
std::size_t getNNodes() const { return (_nodes==nullptr) ? 0 : _nodes->size(); }
/// return the number of registered elements
std::size_t getNElements() const { return (_eles==nullptr) ? 0 : _eles->size(); }
// const MeshLib::Node* getNode(std::size_t index) const { return (_nodes==nullptr) ? nullptr : (*_nodes)[index]; }
// const MeshLib::Element* getElement(std::size_t index) const { return (_eles==nullptr) ? nullptr : (*_eles)[index]; }
// bool has(const MeshLib::Node &item) const { return (std::count(_nodes->begin(), _nodes->end(), &item)>0); }
// bool has(const MeshLib::Element &item) const { return (std::count(_eles->begin(), _eles->end(), &item)>0); }
private:
const MeshLib::Mesh* _msh;
std::vector<MeshLib::Node*> const* _nodes;
std::vector<MeshLib::Element*> const* _eles;
};
}
#endif /* MESHITEMS_H_ */
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