36 #include "FineCoarseMeshPair.hpp" 38 template<
unsigned DIM>
40 : mrFineMesh(rFineMesh),
41 mrCoarseMesh(rCoarseMesh),
42 mpFineMeshBoxCollection(nullptr),
43 mpCoarseMeshBoxCollection(nullptr)
48 template<
unsigned DIM>
54 template<
unsigned DIM>
60 template<
unsigned DIM>
67 template<
unsigned DIM>
77 template<
unsigned DIM>
91 template<
unsigned DIM>
97 template<
unsigned DIM>
103 template<
unsigned DIM>
110 delete rpBoxCollection;
111 rpBoxCollection =
nullptr;
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 if (rpBoxCollection->
IsOwned(p_node))
166 box_indices_each_node_this_elem.insert(box_index);
169 for (std::set<unsigned>::iterator iter = box_indices_each_node_this_elem.begin();
170 iter != box_indices_each_node_this_elem.end();
174 rpBoxCollection->
rGetBox( *iter ).AddElement(p_element);
187 template<
unsigned DIM>
193 EXCEPTION(
"Call SetUpBoxesOnFineMesh() before ComputeFineElementsAndWeightsForCoarseQuadPoints()");
212 std::cout <<
"\nComputing fine elements and weights for coarse quad points\n";
218 for (
unsigned i=0; i<quad_point_posns.
Size(); i++)
223 std::cout <<
"\t" << i <<
" of " << quad_point_posns.
Size() << std::flush;
245 WARNING(
mStatisticsCounters[1] <<
" of " << quad_point_posns.
Size() <<
" coarse-mesh quadrature points were outside the fine mesh");
249 template<
unsigned DIM>
254 EXCEPTION(
"Call SetUpBoxesOnFineMesh() before ComputeFineElementsAndWeightsForCoarseNodes()");
269 std::cout <<
"\nComputing fine elements and weights for coarse nodes\n";
305 template<
unsigned DIM>
308 unsigned boxForThisPoint,
311 std::set<unsigned> test_element_indices;
322 c_vector<double,DIM+1> weight;
330 test_element_indices,
339 test_element_indices.clear();
374 assert(test_element_indices.size() > 0);
403 template<
unsigned DIM>
408 EXCEPTION(
"Call SetUpBoxesOnCoarseMesh() before ComputeCoarseElementsForFineNodes()");
414 std::cout <<
"\nComputing coarse elements for fine nodes\n";
442 template<
unsigned DIM>
447 EXCEPTION(
"Call SetUpBoxesOnCoarseMesh() before ComputeCoarseElementsForFineElementCentroids()");
453 std::cout <<
"\nComputing coarse elements for fine element centroids\n";
484 template<
unsigned DIM>
487 unsigned boxForThisPoint)
495 std::set<unsigned> test_element_indices;
504 test_element_indices,
512 test_element_indices.clear();
540 assert(test_element_indices.size() > 0);
560 template<
unsigned DIM>
563 std::set<unsigned>& rElementIndices)
565 for (
typename std::set<
Element<DIM,DIM>*>::iterator elem_iter = rpBoxCollection->
rGetBox(boxIndex).rGetElementsContained().begin();
566 elem_iter != rpBoxCollection->
rGetBox(boxIndex).rGetElementsContained().end();
569 rElementIndices.insert((*elem_iter)->GetIndex());
573 template<
unsigned DIM>
576 std::set<unsigned>& rElementIndices)
578 std::set<unsigned> local_boxes = rpBoxCollection->
rGetLocalBoxes(boxIndex);
579 for (std::set<unsigned>::iterator local_box_iter = local_boxes.begin();
580 local_box_iter != local_boxes.end();
583 for (
typename std::set<
Element<DIM,DIM>*>::iterator elem_iter = rpBoxCollection->
rGetBox(*local_box_iter).rGetElementsContained().begin();
584 elem_iter != rpBoxCollection->
rGetBox(*local_box_iter).rGetElementsContained().end();
587 rElementIndices.insert((*elem_iter)->GetIndex());
596 template<
unsigned DIM>
604 template<
unsigned DIM>
615 MPI_Allreduce(&local_counters[0], &
mStatisticsCounters[0], 2u, MPI_UNSIGNED, MPI_SUM, PETSC_COMM_WORLD);
620 std::vector<unsigned> all_element_indices(elements_size);
621 unsigned weights_size = elements_size*(DIM+1);
622 std::vector<double> all_weights(weights_size);
626 for (
unsigned j=0; j<DIM+1; j++)
633 std::vector<unsigned> local_all_element_indices = all_element_indices;
634 std::vector<double> local_all_weights = all_weights;
635 MPI_Allreduce(&local_all_element_indices[0], &all_element_indices[0], elements_size, MPI_UNSIGNED, MPI_SUM, PETSC_COMM_WORLD);
636 MPI_Allreduce( &local_all_weights[0], &all_weights[0], weights_size, MPI_DOUBLE, MPI_SUM, PETSC_COMM_WORLD);
642 for (
unsigned j=0; j<DIM+1; j++)
649 template<
unsigned DIM>
660 MPI_Allreduce(&local_counters[0], &
mStatisticsCounters[0], 2u, MPI_UNSIGNED, MPI_SUM, PETSC_COMM_WORLD);
675 template<
unsigned DIM>
678 std::cout <<
"\nFineCoarseMeshPair statistics for the last-called method:\n";
685 std::cout <<
"\tNum points for which containing element was found: " <<
mStatisticsCounters[0] <<
"\n";
686 std::cout <<
"\tNum points for which no containing element was found = " << mStatisticsCounters[1] <<
"\n";
690 std::cout <<
"\tIndices and weights for points (nodes/quad points) for which no containing element was found:\n";
bool IsBoxOwned(unsigned globalIndex)
unsigned CalculateContainingBox(Node< DIM > *pNode)
void ShareCoarseElementData()
void ComputeFineElementAndWeightForGivenPoint(ChastePoint< DIM > &rPoint, bool safeMode, unsigned boxForThisPoint, unsigned index)
std::vector< unsigned > mNotInMesh
DistributedBoxCollection< DIM > * mpFineMeshBoxCollection
void ShareFineElementData()
FineCoarseMeshPair(AbstractTetrahedralMesh< DIM, DIM > &rFineMesh, AbstractTetrahedralMesh< DIM, DIM > &rCoarseMesh)
void ResetStatisticsVariables()
void ComputeFineElementsAndWeightsForCoarseNodes(bool safeMode)
Node< SPACE_DIM > * GetNode(unsigned index) const
virtual unsigned GetNumElements() const
#define EXCEPTION(message)
void DeleteCoarseBoxCollection()
Element< ELEMENT_DIM, SPACE_DIM > * GetElement(unsigned index) const
const AbstractTetrahedralMesh< DIM, DIM > & GetCoarseMesh() const
std::vector< unsigned > mCoarseElementsForFineElementCentroids
virtual unsigned GetNumNodes() const
unsigned ComputeCoarseElementForGivenPoint(ChastePoint< DIM > &rPoint, bool safeMode, unsigned boxForThisPoint)
std::vector< unsigned > mStatisticsCounters
AbstractTetrahedralMesh< DIM, DIM > & mrCoarseMesh
AbstractTetrahedralMesh< DIM, DIM > & mrFineMesh
bool OptionExists(const std::string &rOption)
void ComputeFineElementsAndWeightsForCoarseQuadPoints(GaussianQuadratureRule< DIM > &rQuadRule, bool safeMode)
Node< SPACE_DIM > * GetNode(unsigned localIndex) const
std::set< unsigned > & rGetLocalBoxes(unsigned boxIndex)
const ChastePoint< SPACE_DIM > & rGetUpperCorner() const
std::vector< ElementAndWeights< DIM > > mFineMeshElementsAndWeights
std::vector< unsigned > mCoarseElementsForFineNodes
bool IsOwned(Node< DIM > *pNode)
void CollectElementsInLocalBoxes(DistributedBoxCollection< DIM > *&rpBoxCollection, unsigned boxIndex, std::set< unsigned > &rElementIndices)
unsigned GetContainingElementIndex(const ChastePoint< SPACE_DIM > &rTestPoint, bool strict=false, std::set< unsigned > testElements=std::set< unsigned >(), bool onlyTryWithTestElements=false)
double GetWidth(unsigned rDimension) const
void CollectElementsInContainingBox(DistributedBoxCollection< DIM > *&rpBoxCollection, unsigned boxIndex, std::set< unsigned > &rElementIndices)
const c_vector< double, SPACE_DIM > & rGetLocation() const
c_vector< double, DIM > & rGet(unsigned elementIndex, unsigned quadIndex)
void SetUpBoxesOnCoarseMesh(double boxWidth=-1)
static CommandLineArguments * Instance()
ChasteCuboid< SPACE_DIM > CalculateBoundingBox(const std::vector< Node< SPACE_DIM > * > &rNodes) const
void SetUpBoxes(AbstractTetrahedralMesh< DIM, DIM > &rMesh, double boxWidth, DistributedBoxCollection< DIM > *&rpBoxCollection)
void DeleteFineBoxCollection()
void SetUpBoxesOnFineMesh(double boxWidth=-1)
unsigned GetNearestElementIndexFromTestElements(const ChastePoint< SPACE_DIM > &rTestPoint, std::set< unsigned > testElements)
std::vector< c_vector< double, DIM+1 > > mNotInMeshNearestElementWeights
void ComputeCoarseElementsForFineNodes(bool safeMode)
Box< DIM > & rGetBox(unsigned boxIndex)
virtual c_vector< double, 2 > CalculateMinMaxEdgeLengths()
c_vector< double, SPACE_DIM > & rGetModifiableLocation()
const AbstractTetrahedralMesh< DIM, DIM > & GetFineMesh() const
DistributedBoxCollection< DIM > * mpCoarseMeshBoxCollection
void SetupAllLocalBoxes()
void ComputeCoarseElementsForFineElementCentroids(bool safeMode)
const ChastePoint< SPACE_DIM > & rGetLowerCorner() const