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

some optimizations for speed up the computations

parent 36a63523
No related branches found
No related tags found
No related merge requests found
......@@ -16,6 +16,7 @@
// BaseLib
#include "logog/include/logog.hpp"
#include "StringTools.h"
// GeoLib
#include "AABB.h"
......@@ -79,18 +80,9 @@ void Mesh2MeshPropertyInterpolation::interpolatePropertiesForMesh(Mesh *dest_mes
// compute axis aligned bounding box around the current element
const GeoLib::AABB<MeshLib::Node> elem_aabb(dest_elements[k]->getNodes(), dest_elements[k]->getNodes()+dest_elements[k]->getNNodes());
// compute parameters for requesting "interesting" nodes from the grid
double center[3] = {(elem_aabb.getMaxPoint()[0] + elem_aabb.getMinPoint()[0]) / 2,
(elem_aabb.getMaxPoint()[1] + elem_aabb.getMinPoint()[1]) / 2,
(elem_aabb.getMaxPoint()[2] + elem_aabb.getMinPoint()[2]) / 2};
double half_len(std::max(elem_aabb.getMaxPoint()[0] - elem_aabb.getMinPoint()[0],
elem_aabb.getMaxPoint()[1] - elem_aabb.getMinPoint()[1]));
half_len = std::max(half_len, elem_aabb.getMaxPoint()[2] - elem_aabb.getMinPoint()[2]);
half_len /= 2;
// request "interesting" nodes from grid
std::vector<std::vector<MeshLib::Node*> const*> nodes;
src_grid.getVecsOfGridCellsIntersectingCube(center, half_len, nodes);
src_grid.getPntVecsOfGridCellsIntersectingCuboid(elem_aabb.getMinPoint(), elem_aabb.getMaxPoint(), nodes);
size_t cnt(0);
dest_properties[k] = 0.0;
......@@ -100,15 +92,48 @@ void Mesh2MeshPropertyInterpolation::interpolatePropertiesForMesh(Mesh *dest_mes
const size_t n_nodes_in_vec(i_th_vec->size());
for (size_t j(0); j<n_nodes_in_vec; j++) {
MeshLib::Node const*const j_th_node((*i_th_vec)[j]);
if (dynamic_cast<MeshLib::Face*>(dest_elements[k])->isPntInside(* dynamic_cast<GeoLib::Point const*>(j_th_node))) {
dest_properties[k] += interpolated_src_node_properties[(*i_th_vec)[j]->getID()];
cnt++;
if (elem_aabb.containsPoint(*j_th_node)) {
if (dynamic_cast<MeshLib::Face*>(dest_elements[k])->isPntInside(* dynamic_cast<GeoLib::Point const*>(j_th_node), 30)) {
dest_properties[k] += interpolated_src_node_properties[(*i_th_vec)[j]->getID()];
cnt++;
}
}
}
}
dest_properties[k] /= cnt;
dest_elements[k]->setValue(k);
if (cnt == 0) {
std::string base_name("DebugData/Element-");
base_name += BaseLib::number2str(k);
std::string aabb_fname(base_name + "-aabb.gli");
std::ofstream out_aabb(aabb_fname.c_str());
out_aabb << "#POINTS" << std::endl;
out_aabb << "0 " << elem_aabb.getMinPoint() << std::endl;
out_aabb << "1 " << elem_aabb.getMaxPoint() << std::endl;
out_aabb << "#STOP" << std::endl;
out_aabb.close();
std::string source_fname(base_name + "-SourceNodes.gli");
std::ofstream out_src(source_fname.c_str());
out_src << "#POINTS" << std::endl;
size_t nodes_cnt(0);
for (size_t i(0); i<nodes.size(); ++i) {
std::vector<MeshLib::Node*> const* i_th_vec(nodes[i]);
const size_t n_nodes_in_vec(i_th_vec->size());
for (size_t j(0); j<n_nodes_in_vec; j++) {
MeshLib::Node const*const j_th_node((*i_th_vec)[j]);
out_src << nodes_cnt << " " << *(dynamic_cast<GeoLib::Point const*>(j_th_node)) << std::endl;
nodes_cnt++;
}
}
out_src << "#STOP" << std::endl;
out_src.close();
std::cerr << "no source nodes in dest element " << k << std::endl;
}
}
}
......
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