Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007 #if !defined(LCM_Topology_Utils_h)
00008 #define LCM_Topology_Utils_h
00009
00010 #include "Topology_Types.h"
00011
00012 namespace LCM {
00013
00021 inline
00022 void
00023 display_connectivity(BulkData * bulk_data, EntityRank cell_rank)
00024 {
00025
00026 EntityVector
00027 elements;
00028
00029 stk::mesh::get_entities(*(bulk_data), cell_rank, elements);
00030
00031 typedef EntityVector::size_type size_type;
00032
00033
00034 size_type const
00035 number_of_elements = elements.size();
00036
00037 for (size_type i = 0; i < number_of_elements; ++i) {
00038
00039 PairIterRelation
00040 relations = elements[i]->relations(NODE_RANK);
00041
00042 EntityId const
00043 element_id = elements[i]->identifier();
00044
00045 std::cout << std::setw(16) << element_id << ":";
00046
00047 size_t const
00048 nodes_per_element = relations.size();
00049
00050 for (size_t j = 0; j < nodes_per_element; ++j) {
00051
00052 Entity const &
00053 node = *(relations[j].entity());
00054
00055 EntityId const
00056 node_id = node.identifier();
00057
00058 std::cout << std::setw(16) << node_id;
00059 }
00060
00061 std::cout << '\n';
00062 }
00063
00064 return;
00065 }
00066
00073 inline
00074 void
00075 display_relation(Entity const & entity)
00076 {
00077 std::cout << "Relations for entity (identifier,rank): ";
00078 std::cout << entity.identifier() << "," << entity.entity_rank();
00079 std::cout << '\n';
00080
00081 PairIterRelation
00082 relations = entity.relations();
00083
00084 for (size_t i = 0; i < relations.size(); ++i) {
00085 std::cout << "entity:\t";
00086 std::cout << relations[i].entity()->identifier() << ",";
00087 std::cout << relations[i].entity()->entity_rank();
00088 std::cout << "\tlocal id: ";
00089 std::cout << relations[i].identifier();
00090 std::cout << '\n';
00091 }
00092 return;
00093 }
00094
00101 inline
00102 void
00103 display_relation(Entity const & entity, EntityRank const rank)
00104 {
00105 std::cout << "Relations of rank ";
00106 std::cout << rank;
00107 std::cout << " for entity (identifier,rank): ";
00108 std::cout << entity.identifier() << "," << entity.entity_rank();
00109 std::cout << '\n';
00110
00111 PairIterRelation
00112 relations = entity.relations(rank);
00113
00114 for (size_t i = 0; i < relations.size(); ++i) {
00115 std::cout << "entity:\t";
00116 std::cout << relations[i].entity()->identifier() << ",";
00117 std::cout << relations[i].entity()->entity_rank();
00118 std::cout << "\tlocal id: ";
00119 std::cout << relations[i].identifier();
00120 std::cout << '\n';
00121 }
00122 return;
00123 }
00124
00125 inline
00126 bool
00127 is_one_down(Entity const & entity, Relation const & relation)
00128 {
00129 EntityRank const
00130 entity_rank = entity.entity_rank();
00131
00132 EntityRank const
00133 target_rank = relation.entity_rank();
00134
00135 return entity_rank - target_rank == 1;
00136 }
00137
00138 inline
00139 bool
00140 is_one_up(Entity const & entity, Relation const & relation)
00141 {
00142 EntityRank const
00143 entity_rank = entity.entity_rank();
00144
00145 EntityRank const
00146 target_rank = relation.entity_rank();
00147
00148 return target_rank - entity_rank == 1;
00149 }
00150
00156 inline
00157 bool
00158 is_graph_relation(Entity const & source_entity, Relation const & relation)
00159 {
00160 return is_one_down(source_entity, relation);
00161 }
00162
00168 inline
00169 bool
00170 is_needed_for_stk(
00171 Entity const & source_entity,
00172 Relation const & relation,
00173 EntityRank const cell_rank)
00174 {
00175 EntityRank const
00176 source_rank = source_entity.entity_rank();
00177
00178 EntityRank const
00179 target_rank = relation.entity_rank();
00180
00181 return (source_rank == cell_rank) && (target_rank == NODE_RANK);
00182 }
00183
00184
00185
00186
00187
00188
00189
00193 inline
00194 PairIterRelation
00195 relations_all(Entity const & entity)
00196 {
00197 return entity.relations();
00198 }
00199
00203 inline
00204 PairIterRelation
00205 relations_one_up(Entity const & entity)
00206 {
00207 return entity.relations(entity.entity_rank() + 1);
00208 }
00209
00213 inline
00214 PairIterRelation
00215 relations_one_down(Entity const & entity)
00216 {
00217 return entity.relations(entity.entity_rank() - 1);
00218 }
00219
00224 inline
00225 std::string
00226 parallelize_string(std::string const & string)
00227 {
00228 std::ostringstream
00229 oss;
00230
00231 oss << string;
00232
00233 int const
00234 number_processors = Teuchos::GlobalMPISession::getNProc();
00235
00236 if (number_processors > 1) {
00237
00238 int const
00239 number_digits = static_cast<int>(std::log10(number_processors));
00240
00241 int const
00242 processor_id = Teuchos::GlobalMPISession::getRank();
00243
00244 oss << "-";
00245 oss << std::setfill('0') << std::setw(number_digits) << processor_id;
00246 }
00247
00248 return oss.str();
00249 }
00250
00251 }
00252
00253 #endif // LCM_Topology_Utils_h