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

[MeshLib] Added a utility of getElementRotationMatrices

parent 46b7f1a0
No related branches found
No related tags found
No related merge requests found
/**
* \file
* \copyright
* Copyright (c) 2012-2021, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
* Created on May 14, 2021, 2:38 PM
*/
#include "GetElementRotationMatrices.h"
#include "GetSpaceDimension.h"
#include "MeshLib/ElementCoordinatesMappingLocal.h"
#include "MeshLib/Elements/Elements.h"
#include "MeshLib/Mesh.h"
namespace MeshLib
{
std::vector<Eigen::MatrixXd> getElementRotationMatrices(
int const space_dimension, int const mesh_dimension,
std::vector<Element*> const& elements)
{
std::vector<Eigen::MatrixXd> element_rotation_matrices;
element_rotation_matrices.reserve(elements.size());
for (auto const& element : elements)
{
int const element_dimension = static_cast<int>(element->getDimension());
if (element_dimension == space_dimension)
{
element_rotation_matrices.emplace_back(Eigen::MatrixXd::Identity(
element_dimension, element_dimension));
}
else
{
MeshLib::ElementCoordinatesMappingLocal coordinates_mapping(
*element, mesh_dimension);
element_rotation_matrices.emplace_back(
coordinates_mapping.getRotationMatrixToGlobal().topLeftCorner(
space_dimension, element_dimension));
}
}
return element_rotation_matrices;
}
} // namespace MeshLib
/**
* \file
* \copyright
* Copyright (c) 2012-2021, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
* Created on May 14, 2021, 2:38 PM
*/
#pragma once
#include <Eigen/Dense>
#include <vector>
namespace MeshLib
{
class Element;
std::vector<Eigen::MatrixXd> getElementRotationMatrices(
int const space_dimension, int const mesh_dimension,
std::vector<Element*> const& elements);
} // namespace MeshLib
/**
* \file
* \copyright
* Copyright (c) 2012-2021, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
* Created on June 8, 2021, 12:16 PM
*/
#include "GetSpaceDimension.h"
#include <algorithm>
#include <array>
#include <limits>
#include "BaseLib/Error.h"
#include "MeshLib/Node.h"
namespace MeshLib
{
int getSpaceDimension(std::vector<Node*> const& nodes)
{
std::array x_magnitude = {0.0, 0.0, 0.0};
double const* const x_ref = nodes[0]->getCoords();
for (auto const& node : nodes)
{
auto const x = node->getCoords();
for (int i = 0; i < 3; i++)
{
x_magnitude[i] += std::fabs(x[i] - x_ref[i]);
}
}
return static_cast<int>(std::count_if(
x_magnitude.begin(), x_magnitude.end(),
[](const double x_i_magnitude)
{ return x_i_magnitude > std::numeric_limits<double>::epsilon(); }));
}
}; // namespace MeshLib
/**
* \file
* \copyright
* Copyright (c) 2012-2021, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
* Created on June 8, 2021, 12:16 PM
*/
#pragma once
#include <vector>
namespace MeshLib
{
class Node;
/**
* \brief Computes dimension of the embedding space containing the set of given
* points.
*
* The space dimension is computed by accounting the non-zero norms of
* \f$\mathbf x\f$, \f$\mathbf y\f$, \f$\mathbf z\f$, which are
* the coordinates of all nodes of the mesh. With this concept,
* the space dimension of a mesh is:
* - 1, if the mesh is 1D and and the mesh is parallel either to
* \f$x\f$, \f$y\f$ or to \f$z\f$ axis.
* - 2, if the mesh is 1D but it contains inclined elements on the origin
* coordinate plane of \f$x-y,\, y-z,\, \text{or }\, x-z\f$.
* That means the coordinates of all nodes are
* \f$(x, y, 0)\f$, \f$(x, 0, z)\f$ or \f$(0, y, z)\f$.
* - 3, if the mesh is 1D and but it is not on any origin
* coordinate plane of \f$x-y,\, y-z,\, \text{or }\, x-z\f$.
* - 2, if the mesh is 2D and it is on the origin
* coordinate plane of \f$x-y,\, y-z,\, \text{or }\, x-z\f$.
* - 2, if the mesh is 2D and it is on vertical or horizontal plane
* that is parallel to the the origin coordinate
* plane of \f$x-y,\, y-z,\, \text{or }\, x-z\f$ but with an offset.
* - 3, if the mesh contains inclined 2D elements.
* - 3, if the mesh contains 3D elements.
*/
int getSpaceDimension(std::vector<Node*> const& nodes);
}; // namespace MeshLib
...@@ -11,41 +11,16 @@ ...@@ -11,41 +11,16 @@
#include "SetMeshSpaceDimension.h" #include "SetMeshSpaceDimension.h"
#include <algorithm> #include "GetSpaceDimension.h"
#include <array>
#include <limits>
#include "BaseLib/Error.h"
#include "MeshLib/Elements/Element.h" #include "MeshLib/Elements/Element.h"
#include "MeshLib/Mesh.h" #include "MeshLib/Mesh.h"
#include "MeshLib/Node.h"
namespace MeshLib namespace MeshLib
{ {
unsigned getSpaceDimension(Mesh const& mesh)
{
std::array x_magnitude = {0.0, 0.0, 0.0};
auto const nodes = mesh.getNodes();
for (auto const& node : nodes)
{
auto const x = node->getCoords();
for (int i = 0; i < 3; i++)
{
x_magnitude[i] += std::fabs(x[i]);
}
}
return static_cast<unsigned>(std::count_if(
x_magnitude.begin(), x_magnitude.end(), [](const double x_i_magnitude) {
return x_i_magnitude > std::numeric_limits<double>::epsilon();
}));
}
void setMeshSpaceDimension(std::vector<std::unique_ptr<Mesh>> const& meshes) void setMeshSpaceDimension(std::vector<std::unique_ptr<Mesh>> const& meshes)
{ {
// Get the space dimension from the bulk mesh: // Get the space dimension from the bulk mesh:
auto const space_dimension = getSpaceDimension(*meshes[0]); auto const space_dimension = getSpaceDimension(meshes[0]->getNodes());
for (auto& mesh : meshes) for (auto& mesh : meshes)
{ {
auto elements = mesh->getElements(); auto elements = mesh->getElements();
......
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