Page MenuHomec4science

mesh.cc
No OneTemporary

File Metadata

Created
Thu, Aug 1, 16:54
/**
* @file mesh.cc
* @author Nicolas Richart <nicolas.richart@epfl.ch>
* @date Wed Jun 16 12:02:26 2010
*
* @brief class handling meshes
*
* @section LICENSE
*
* Copyright (©) 2010-2011 EPFL (Ecole Polytechnique Fédérale de Lausanne)
* Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides)
*
* Akantu is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* Akantu is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Akantu. If not, see <http://www.gnu.org/licenses/>.
*
*/
/* -------------------------------------------------------------------------- */
#include <sstream>
/* -------------------------------------------------------------------------- */
#include "mesh.hh"
#include "element_class.hh"
#include "static_communicator.hh"
/* -------------------------------------------------------------------------- */
__BEGIN_AKANTU__
const Element ElementNull(_not_defined, 0);
/* -------------------------------------------------------------------------- */
void Element::printself(std::ostream & stream, int indent) const {
std::string space;
for(Int i = 0; i < indent; i++, space += AKANTU_INDENT);
stream << space << "Element [" << type << ", " << element << "]";
}
/* -------------------------------------------------------------------------- */
Mesh::Mesh(UInt spatial_dimension,
const ID & id,
const MemoryID & memory_id) :
Memory(memory_id), id(id), nodes_global_ids(NULL), nodes_type(NULL),
created_nodes(true),
connectivities("connectivities", id),
normals("normals", id),
spatial_dimension(spatial_dimension),
internal_facets_mesh(NULL),
types_offsets(Vector<UInt>((UInt) _max_element_type + 1, 1)),
ghost_types_offsets(Vector<UInt>((UInt) _max_element_type + 1, 1)),
nb_surfaces(0),
surface_id("surface_id", id),
uint_data("by_element_uint_data", id) {
AKANTU_DEBUG_IN();
std::stringstream sstr;
sstr << id << ":coordinates";
this->nodes = &(alloc<Real>(sstr.str(), 0, this->spatial_dimension));
nb_global_nodes = 0;
init();
std::fill_n(lower_bounds, 3, 0.);
std::fill_n(upper_bounds, 3, 0.);
std::fill_n(size, 3, 0.);
std::fill_n(local_lower_bounds, 3, 0.);
std::fill_n(local_upper_bounds, 3, 0.);
AKANTU_DEBUG_OUT();
}
/* -------------------------------------------------------------------------- */
Mesh::Mesh(UInt spatial_dimension,
const ID & nodes_id,
const ID & id,
const MemoryID & memory_id) :
Memory(memory_id), id(id), nodes_global_ids(NULL), nodes_type(NULL),
created_nodes(false),
connectivities("connectivities", id),
normals("normals", id),
spatial_dimension(spatial_dimension),
internal_facets_mesh(NULL),
types_offsets(Vector<UInt>((UInt) _max_element_type + 1, 1)),
ghost_types_offsets(Vector<UInt>((UInt) _max_element_type + 1, 1)),
nb_surfaces(0),
surface_id("surface_id", id),
uint_data("by_element_uint_data", id) {
AKANTU_DEBUG_IN();
this->nodes = &(getVector<Real>(nodes_id));
nb_global_nodes = nodes->getSize();
init();
AKANTU_DEBUG_OUT();
}
/* -------------------------------------------------------------------------- */
Mesh::Mesh(UInt spatial_dimension,
Vector<Real> & nodes,
const ID & id,
const MemoryID & memory_id) :
Memory(memory_id), id(id), nodes_global_ids(NULL), nodes_type(NULL),
created_nodes(false),
connectivities("connectivities", id),
normals("normals", id),
spatial_dimension(spatial_dimension),
internal_facets_mesh(NULL),
types_offsets(Vector<UInt>(_max_element_type + 1, 1)),
ghost_types_offsets(Vector<UInt>(_max_element_type + 1, 1)),
nb_surfaces(0),
surface_id("surface_id", id),
uint_data("by_element_uint_data", id) {
AKANTU_DEBUG_IN();
this->nodes = &(nodes);
nb_global_nodes = nodes.getSize();
init();
AKANTU_DEBUG_OUT();
}
/* -------------------------------------------------------------------------- */
void Mesh::init() {
// this->types_offsets.resize(_max_element_type);
nodes_type = NULL;
computeBoundingBox();
}
/* -------------------------------------------------------------------------- */
Mesh::~Mesh() {
AKANTU_DEBUG_IN();
for(UInt g = _not_ghost; g <= _ghost; ++g) {
GhostType gt = (GhostType) g;
const ConnectivityTypeList & type_list = getConnectivityTypeList(gt);
ConnectivityTypeList::const_iterator it;
for(it = type_list.begin(); it != type_list.end(); ++it) {
UIntDataMap & map = uint_data(*it, gt);
UIntDataMap::iterator dit;
for (dit = map.begin(); dit != map.end(); ++dit) {
if(dit->second) delete dit->second;
}
map.clear();
}
}
AKANTU_DEBUG_OUT();
}
/* -------------------------------------------------------------------------- */
void Mesh::printself(std::ostream & stream, int indent) const {
std::string space;
for(Int i = 0; i < indent; i++, space += AKANTU_INDENT);
stream << space << "Mesh [" << std::endl;
stream << space << " + id : " << this->id << std::endl;
stream << space << " + spatial dimension : " << this->spatial_dimension << std::endl;
stream << space << " + nodes [" << std::endl;
nodes->printself(stream, indent+2);
stream << space << " ]" << std::endl;
stream << space << " + connectivities [" << std::endl;
connectivities.printself(stream, indent+2);
stream << space << "]" << std::endl;
}
/* -------------------------------------------------------------------------- */
void Mesh::computeBoundingBox(){
AKANTU_DEBUG_IN();
UInt dim = spatial_dimension;
for (UInt k = 0; k < dim; ++k) {
local_lower_bounds[k] = std::numeric_limits<double>::max();
local_upper_bounds[k] = - std::numeric_limits<double>::max();
}
Real * coords = nodes->storage();
for (UInt i = 0; i < nodes->getSize(); ++i) {
for (UInt k = 0; k < dim; ++k) {
local_lower_bounds[k] = std::min(local_lower_bounds[k], coords[dim*i+k]);
local_upper_bounds[k] = std::max(local_upper_bounds[k], coords[dim*i+k]);
}
}
StaticCommunicator * comm = StaticCommunicator::getStaticCommunicator();
for (UInt k = 0; k < dim; ++k) {
lower_bounds[k] = local_lower_bounds[k];
upper_bounds[k] = local_upper_bounds[k];
}
comm->allReduce(lower_bounds, dim, _so_min);
comm->allReduce(upper_bounds, dim, _so_max);
for (UInt k = 0; k < dim; ++k)
size[k] = upper_bounds[k] - lower_bounds[k];
AKANTU_DEBUG_OUT();
}
/* -------------------------------------------------------------------------- */
template<typename T>
void Mesh::initByElementTypeVector(ByElementTypeVector<T> & vect,
UInt nb_component,
UInt dim,
const bool & flag_nb_node_per_elem_multiply) const {
AKANTU_DEBUG_IN();
for(UInt g = _not_ghost; g <= _ghost; ++g) {
GhostType gt = (GhostType) g;
const Mesh::ConnectivityTypeList & type_list = getConnectivityTypeList(gt);
Mesh::ConnectivityTypeList::const_iterator it;
for(it = type_list.begin(); it != type_list.end(); ++it) {
ElementType type = *it;
if(dim > 0 && Mesh::getSpatialDimension(type) != dim) continue;
if (flag_nb_node_per_elem_multiply) nb_component *= Mesh::getNbNodesPerElement(*it);
vect.alloc(0, nb_component, type);
}
}
AKANTU_DEBUG_OUT();
}
/* -------------------------------------------------------------------------- */
template void Mesh::initByElementTypeVector<Real>(ByElementTypeVector<Real> & vect,
UInt nb_component,
UInt dim,
const bool & flag_nb_elem_multiply) const;
template void Mesh::initByElementTypeVector<Int>(ByElementTypeVector<Int> & vect,
UInt nb_component,
UInt dim,
const bool & flag_nb_elem_multiply) const;
template void Mesh::initByElementTypeVector<UInt>(ByElementTypeVector<UInt> & vect,
UInt nb_component,
UInt dim,
const bool & flag_nb_elem_multiply) const;
__END_AKANTU__

Event Timeline