• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

Topology_Utils.h

Go to the documentation of this file.
00001 //*****************************************************************//
00002 //    Albany 2.0:  Copyright 2012 Sandia Corporation               //
00003 //    This Software is released under the BSD license detailed     //
00004 //    in the file "license.txt" in the top-level Albany directory  //
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   // Create a list of element entities
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   // Loop over the elements
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 // TODO: returning PairIterRelation(*relation_vector) below
00185 // stores tenporary iterators to relation_vector that are
00186 // invalid outside the scope of these functions.
00187 // Perhaps change to returning the vector itself but this will require
00188 // change of interface for functions that return relations.
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 }// namespace LCM
00252 
00253 #endif // LCM_Topology_Utils_h

Generated on Wed Mar 26 2014 18:36:45 for Albany: a Trilinos-based PDE code by  doxygen 1.7.1