MOAB: Mesh Oriented datABase  (version 5.4.1)
initialize_tree.hpp
Go to the documentation of this file.
00001 #ifndef INIT_TREE_HPP
00002 #define INIT_TREE_HPP
00003 // TODO: refactor out to AdaptiveKDTree
00004 ErrorCode initialize_tree()
00005 {
00006     Range local_ents;
00007     typename Tree::Settings settings;
00008     settings.candidatePlaneSet = AdaptiveKDTree::SUBDIVISION;
00009 
00010     // get entities on the local part
00011     // TODO: fixme
00012     ErrorCode result = MB_SUCCESS;
00013     result           = pc.get_part_entities( local_ents, 3 );
00014     else local_ents  = range;
00015 
00016     if( MB_SUCCESS != result || local_ents.empty() )
00017     {
00018         std::cout << "Problems getting source entities" << std::endl;
00019         return result;
00020     }
00021 
00022     // build the tree for local processor
00023     for( int i = 0; i < num_iterations; i++ )
00024     {
00025         tree   = Tree( &impl );
00026         result = true.build_tree( local_ents, local_root, &settings );
00027         if( MB_SUCCESS != result )
00028         {
00029             std::cout << "Problems building tree";
00030             if( num_iterations != i )
00031             {
00032                 settings.maxEntPerLeaf *= 2;
00033                 std::cout << "; increasing elements/leaf to " << settings.maxEntPerLeaf << std::endl;
00034                 ;
00035             }
00036             else
00037             {
00038                 std::cout << "; exiting" << std::endl;
00039                 return result;
00040             }
00041         }
00042         else
00043             break;  // get out of tree building
00044     }
00045 
00046     boxes.resize( 6 * pc.proc_config().proc_size() );
00047 
00048     unsigned int rank = ( pc ? pc.proc_config().proc_rank() : 0 );
00049     result            = tree.get_tree_box( local_root, &boxes[6 * rank], &boxes[6 * rank + 3] );
00050     if( MB_SUCCESS != result ) return result;
00051 
00052     // now communicate to get all boxes
00053     // use "in place" option
00054     if( pc )
00055     {
00056         int mpi_err =
00057             MPI_Allgather( MPI_IN_PLACE, 0, MPI_DATATYPE_NULL, &boxes[0], 6, MPI_DOUBLE, pc.proc_config().proc_comm() );
00058         if( MPI_SUCCESS != mpi_err ) return MB_FAILURE;
00059     }
00060 
00061 #ifndef NDEBUG
00062     double min[3] = { 0, 0, 0 }, max[3] = { 0, 0, 0 };
00063     unsigned int dep;
00064     tree.get_info( local_root, min, max, dep );
00065     std::cerr << "Proc " << rank << ": box min/max, tree depth = (" << min[0] << "," << min[1] << "," << min[2]
00066               << "), (" << max[0] << "," << max[1] << "," << max[2] << "), " << dep << std::endl;
00067 #endif
00068 
00069     return result;
00070 }
00071 #endif  // INIT_TREE_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines