36 #include "FineCoarseMeshPair.hpp"
38 template<
unsigned DIM>
40 : mrFineMesh(rFineMesh),
41 mrCoarseMesh(rCoarseMesh),
42 mpFineMeshBoxCollection(NULL),
43 mpCoarseMeshBoxCollection(NULL)
48 template<
unsigned DIM>
54 template<
unsigned DIM>
60 template<
unsigned DIM>
63 DeleteFineBoxCollection();
64 DeleteCoarseBoxCollection();
67 template<
unsigned DIM>
70 if (mpFineMeshBoxCollection != NULL)
72 delete mpFineMeshBoxCollection;
73 mpFineMeshBoxCollection = NULL;
77 template<
unsigned DIM>
80 if (mpCoarseMeshBoxCollection != NULL)
82 delete mpCoarseMeshBoxCollection;
83 mpCoarseMeshBoxCollection = NULL;
91 template<
unsigned DIM>
94 SetUpBoxes(mrFineMesh, boxWidth, mpFineMeshBoxCollection);
97 template<
unsigned DIM>
100 SetUpBoxes(mrCoarseMesh, boxWidth, mpCoarseMeshBoxCollection);
103 template<
unsigned DIM>
110 delete rpBoxCollection;
111 rpBoxCollection = NULL;
118 c_vector<double,2*DIM> extended_min_and_max;
119 for (
unsigned i=0; i<DIM; i++)
121 double width = bounding_box.
GetWidth(i);
124 extended_min_and_max(2*i) = bounding_box.
rGetLowerCorner()[i] - 0.05*width;
127 extended_min_and_max(2*i+1) = bounding_box.
rGetUpperCorner()[i] + 0.05*width;
139 boxWidth = (extended_min_and_max(1) - extended_min_and_max(0))/19.000000001;
144 if (boxWidth < min_max_edge_length[1])
146 boxWidth = 1.1*min_max_edge_length[1];
158 std::set<unsigned> box_indices_each_node_this_elem;
159 for (
unsigned j=0; j<DIM+1; j++)
163 box_indices_each_node_this_elem.insert(box_index);
166 for (std::set<unsigned>::iterator iter = box_indices_each_node_this_elem.begin();
167 iter != box_indices_each_node_this_elem.end();
170 rpBoxCollection->
rGetBox( *iter ).AddElement(p_element);
183 template<
unsigned DIM>
187 if (mpFineMeshBoxCollection == NULL)
189 EXCEPTION(
"Call SetUpBoxesOnFineMesh() before ComputeFineElementsAndWeightsForCoarseQuadPoints()");
196 mFineMeshElementsAndWeights.resize(quad_point_posns.
Size());
198 #define COVERAGE_IGNORE
201 std::cout <<
"\nComputing fine elements and weights for coarse quad points\n";
203 #undef COVERAGE_IGNORE
206 ResetStatisticsVariables();
207 for (
unsigned i=0; i<quad_point_posns.
Size(); i++)
209 #define COVERAGE_IGNORE
212 std::cout <<
"\t" << i <<
" of " << quad_point_posns.
Size() << std::flush;
214 #undef COVERAGE_IGNORE
217 unsigned box_for_this_point = mpFineMeshBoxCollection->CalculateContainingBox( quad_point_posns.
rGet(i) );
222 ComputeFineElementAndWeightForGivenPoint(point, safeMode, box_for_this_point, i);
225 if (mStatisticsCounters[1] > 0)
227 WARNING(mStatisticsCounters[1] <<
" of " << quad_point_posns.
Size() <<
" coarse-mesh quadrature points were outside the fine mesh");
231 template<
unsigned DIM>
234 if (mpFineMeshBoxCollection==NULL)
236 EXCEPTION(
"Call SetUpBoxesOnFineMesh() before ComputeFineElementsAndWeightsForCoarseNodes()");
240 mFineMeshElementsAndWeights.resize(mrCoarseMesh.GetNumNodes());
242 #define COVERAGE_IGNORE
245 std::cout <<
"\nComputing fine elements and weights for coarse nodes\n";
247 #undef COVERAGE_IGNORE
250 ResetStatisticsVariables();
251 for (
unsigned i=0; i<mrCoarseMesh.GetNumNodes(); i++)
253 #define COVERAGE_IGNORE
256 std::cout <<
"\t" << i <<
" of " << mrCoarseMesh.GetNumNodes() << std::flush;
258 #undef COVERAGE_IGNORE
260 Node<DIM>* p_node = mrCoarseMesh.GetNode(i);
263 unsigned box_for_this_point = mpFineMeshBoxCollection->CalculateContainingBox( p_node->
rGetModifiableLocation() );
268 ComputeFineElementAndWeightForGivenPoint(point, safeMode, box_for_this_point, i);
278 template<
unsigned DIM>
281 unsigned boxForThisPoint,
284 std::set<unsigned> test_element_indices;
292 CollectElementsInContainingBox(mpFineMeshBoxCollection, boxForThisPoint, test_element_indices);
295 c_vector<double,DIM+1> weight;
301 elem_index = mrFineMesh.GetContainingElementIndex(rPoint,
303 test_element_indices,
305 weight = mrFineMesh.GetElement(elem_index)->CalculateInterpolationWeights(rPoint);
307 mStatisticsCounters[0]++;
312 test_element_indices.clear();
314 CollectElementsInLocalBoxes(mpFineMeshBoxCollection, boxForThisPoint, test_element_indices);
318 elem_index = mrFineMesh.GetContainingElementIndex(rPoint,
false, test_element_indices,
true);
319 weight = mrFineMesh.GetElement(elem_index)->CalculateInterpolationWeights(rPoint);
320 mStatisticsCounters[0]++;
329 elem_index = mrFineMesh.GetContainingElementIndex(rPoint,
false);
330 weight = mrFineMesh.GetElement(elem_index)->CalculateInterpolationWeights(rPoint);
331 mStatisticsCounters[0]++;
337 elem_index = mrFineMesh.GetNearestElementIndexFromTestElements(rPoint,test_element_indices);
338 weight = mrFineMesh.GetElement(elem_index)->CalculateInterpolationWeights(rPoint);
340 mNotInMesh.push_back(index);
341 mNotInMeshNearestElementWeights.push_back(weight);
342 mStatisticsCounters[1]++;
347 assert(test_element_indices.size() > 0);
354 elem_index = mrFineMesh.GetNearestElementIndexFromTestElements(rPoint,test_element_indices);
355 weight = mrFineMesh.GetElement(elem_index)->CalculateInterpolationWeights(rPoint);
357 mNotInMesh.push_back(index);
358 mNotInMeshNearestElementWeights.push_back(weight);
359 mStatisticsCounters[1]++;
364 mFineMeshElementsAndWeights[index].ElementNum = elem_index;
365 mFineMeshElementsAndWeights[index].Weights = weight;
376 template<
unsigned DIM>
379 if (mpCoarseMeshBoxCollection==NULL)
381 EXCEPTION(
"Call SetUpBoxesOnCoarseMesh() before ComputeCoarseElementsForFineNodes()");
384 #define COVERAGE_IGNORE
387 std::cout <<
"\nComputing coarse elements for fine nodes\n";
389 #undef COVERAGE_IGNORE
391 mCoarseElementsForFineNodes.resize(mrFineMesh.GetNumNodes());
393 ResetStatisticsVariables();
394 for (
unsigned i=0; i<mCoarseElementsForFineNodes.size(); i++)
396 #define COVERAGE_IGNORE
399 std::cout <<
"\t" << i <<
" of " << mCoarseElementsForFineNodes.size() << std::flush;
401 #undef COVERAGE_IGNORE
406 unsigned box_for_this_point = mpCoarseMeshBoxCollection->CalculateContainingBox(mrFineMesh.GetNode(i)->rGetModifiableLocation());
408 mCoarseElementsForFineNodes[i] = ComputeCoarseElementForGivenPoint(point, safeMode, box_for_this_point);
412 template<
unsigned DIM>
415 if (mpCoarseMeshBoxCollection==NULL)
417 EXCEPTION(
"Call SetUpBoxesOnCoarseMesh() before ComputeCoarseElementsForFineElementCentroids()");
420 #define COVERAGE_IGNORE
423 std::cout <<
"\nComputing coarse elements for fine element centroids\n";
425 #undef COVERAGE_IGNORE
427 mCoarseElementsForFineElementCentroids.resize(mrFineMesh.GetNumElements());
429 ResetStatisticsVariables();
430 for (
unsigned i=0; i<mrFineMesh.GetNumElements(); i++)
432 #define COVERAGE_IGNORE
435 std::cout <<
"\t" << i <<
" of " << mrFineMesh.GetNumElements() << std::flush;
437 #undef COVERAGE_IGNORE
439 c_vector<double,DIM> point_cvec = mrFineMesh.GetElement(i)->CalculateCentroid();
443 unsigned box_for_this_point = mpCoarseMeshBoxCollection->CalculateContainingBox( point_cvec );
445 mCoarseElementsForFineElementCentroids[i] = ComputeCoarseElementForGivenPoint(point, safeMode, box_for_this_point);
449 template<
unsigned DIM>
452 unsigned boxForThisPoint)
460 std::set<unsigned> test_element_indices;
461 CollectElementsInContainingBox(mpCoarseMeshBoxCollection, boxForThisPoint, test_element_indices);
467 elem_index = mrCoarseMesh.GetContainingElementIndex(rPoint,
469 test_element_indices,
472 mStatisticsCounters[0]++;
477 test_element_indices.clear();
478 CollectElementsInLocalBoxes(mpCoarseMeshBoxCollection, boxForThisPoint, test_element_indices);
482 elem_index = mrCoarseMesh.GetContainingElementIndex(rPoint,
false, test_element_indices,
true);
483 mStatisticsCounters[0]++;
492 elem_index = mrCoarseMesh.GetContainingElementIndex(rPoint,
false);
494 mStatisticsCounters[0]++;
499 elem_index = mrCoarseMesh.GetNearestElementIndexFromTestElements(rPoint,test_element_indices);
500 mStatisticsCounters[1]++;
505 assert(test_element_indices.size() > 0);
512 elem_index = mrCoarseMesh.GetNearestElementIndexFromTestElements(rPoint,test_element_indices);
513 mStatisticsCounters[1]++;
525 template<
unsigned DIM>
528 std::set<unsigned>& rElementIndices)
530 for (
typename std::set<
Element<DIM,DIM>*>::iterator elem_iter = rpBoxCollection->
rGetBox(boxIndex).rGetElementsContained().begin();
531 elem_iter != rpBoxCollection->
rGetBox(boxIndex).rGetElementsContained().end();
534 rElementIndices.insert((*elem_iter)->GetIndex());
538 template<
unsigned DIM>
541 std::set<unsigned>& rElementIndices)
543 std::set<unsigned> local_boxes = rpBoxCollection->
GetLocalBoxes(boxIndex);
544 for (std::set<unsigned>::iterator local_box_iter = local_boxes.begin();
545 local_box_iter != local_boxes.end();
548 for (
typename std::set<
Element<DIM,DIM>*>::iterator elem_iter = rpBoxCollection->
rGetBox(*local_box_iter).rGetElementsContained().begin();
549 elem_iter != rpBoxCollection->
rGetBox(*local_box_iter).rGetElementsContained().end();
552 rElementIndices.insert((*elem_iter)->GetIndex());
561 template<
unsigned DIM>
565 mNotInMeshNearestElementWeights.clear();
566 mStatisticsCounters.resize(2, 0u);
569 template<
unsigned DIM>
572 std::cout <<
"\nFineCoarseMeshPair statistics for the last-called method:\n";
579 std::cout <<
"\tNum points for which containing element was found: " << mStatisticsCounters[0] <<
"\n";
580 std::cout <<
"\tNum points for which no containing element was found = " << mStatisticsCounters[1] <<
"\n";
582 if (mNotInMesh.size() > 0)
584 std::cout <<
"\tIndices and weights for points (nodes/quad points) for which no containing element was found:\n";
585 for (
unsigned i=0; i<mNotInMesh.size(); i++)
587 std::cout <<
"\t\t" << mNotInMesh[i] <<
", " << mNotInMeshNearestElementWeights[i] <<
"\n";
void ComputeFineElementAndWeightForGivenPoint(ChastePoint< DIM > &rPoint, bool safeMode, unsigned boxForThisPoint, unsigned index)
FineCoarseMeshPair(AbstractTetrahedralMesh< DIM, DIM > &rFineMesh, AbstractTetrahedralMesh< DIM, DIM > &rCoarseMesh)
void ResetStatisticsVariables()
void ComputeFineElementsAndWeightsForCoarseNodes(bool safeMode)
virtual unsigned GetNumElements() const
#define EXCEPTION(message)
void DeleteCoarseBoxCollection()
Element< ELEMENT_DIM, SPACE_DIM > * GetElement(unsigned index) const
const AbstractTetrahedralMesh< DIM, DIM > & GetCoarseMesh() const
unsigned ComputeCoarseElementForGivenPoint(ChastePoint< DIM > &rPoint, bool safeMode, unsigned boxForThisPoint)
std::set< unsigned > GetLocalBoxes(unsigned boxIndex)
bool OptionExists(const std::string &rOption)
void ComputeFineElementsAndWeightsForCoarseQuadPoints(GaussianQuadratureRule< DIM > &rQuadRule, bool safeMode)
Node< SPACE_DIM > * GetNode(unsigned localIndex) const
void CollectElementsInContainingBox(BoxCollection< DIM > *&rpBoxCollection, unsigned boxIndex, std::set< unsigned > &rElementIndices)
const ChastePoint< SPACE_DIM > & rGetUpperCorner() const
double GetWidth(unsigned rDimension) const
unsigned CalculateContainingBox(Node< DIM > *pNode)
void SetUpBoxes(AbstractTetrahedralMesh< DIM, DIM > &rMesh, double boxWidth, BoxCollection< DIM > *&rpBoxCollection)
const c_vector< double, SPACE_DIM > & rGetLocation() const
void SetupAllLocalBoxes()
c_vector< double, DIM > & rGet(unsigned elementIndex, unsigned quadIndex)
void SetUpBoxesOnCoarseMesh(double boxWidth=-1)
Box< DIM > & rGetBox(unsigned boxIndex)
static CommandLineArguments * Instance()
ChasteCuboid< SPACE_DIM > CalculateBoundingBox(const std::vector< Node< SPACE_DIM > * > &rNodes) const
void DeleteFineBoxCollection()
void SetUpBoxesOnFineMesh(double boxWidth=-1)
void ComputeCoarseElementsForFineNodes(bool safeMode)
virtual c_vector< double, 2 > CalculateMinMaxEdgeLengths()
c_vector< double, SPACE_DIM > & rGetModifiableLocation()
const AbstractTetrahedralMesh< DIM, DIM > & GetFineMesh() const
void CollectElementsInLocalBoxes(BoxCollection< DIM > *&rpBoxCollection, unsigned boxIndex, std::set< unsigned > &rElementIndices)
void ComputeCoarseElementsForFineElementCentroids(bool safeMode)
const ChastePoint< SPACE_DIM > & rGetLowerCorner() const