Sierra Toolkit Version of the Day
DiagWriter.cpp
00001 /*--------------------------------------------------------------------*/
00002 /*    Copyright 2000 - 2011 Sandia Corporation.                       */
00003 /*    Under the terms of Contract DE-AC04-94AL85000, there is a       */
00004 /*    non-exclusive license for use of this work by or on behalf      */
00005 /*    of the U.S. Government.  Export of this program may require     */
00006 /*    a license from the United States Government.                    */
00007 /*--------------------------------------------------------------------*/
00008 
00009 #ifdef STK_MESH_TRACE_ENABLED
00010 
00011 #include <stk_util/util/Bootstrap.hpp>
00012 
00013 #include <stk_mesh/base/DiagWriter.hpp>
00014 #include <stk_mesh/base/Entity.hpp>
00015 #include <stk_mesh/base/Bucket.hpp>
00016 #include <stk_mesh/base/MetaData.hpp>
00017 
00018 namespace stk {
00019 namespace mesh {
00020 
00021 namespace {
00022 
00023 static stk::diag::Writer* s_diagWriter = NULL;
00024 
00025 }
00026 
00027 void initDiagWriter(std::ostream& stream)
00028 {
00029   s_diagWriter = new stk::diag::Writer(stream.rdbuf(),
00030                                        theDiagWriterParser().parse(std::getenv("MESHLOG")));
00031 }
00032 
00033 stk::diag::Writer & theDiagWriter()
00034 {
00035   ThrowRequireMsg(s_diagWriter != NULL, "Please call initDiagWwriter before theDiagWriter");
00036   return *s_diagWriter;
00037 }
00038 
00039 DiagWriterParser & theDiagWriterParser()
00040 {
00041   static DiagWriterParser parser;
00042 
00043   return parser;
00044 }
00045 
00046 DiagWriterParser::DiagWriterParser()
00047   : stk::diag::WriterParser()
00048 {
00049   mask("entity", (unsigned long) (LOG_ENTITY), "Display entity diagnostic information");
00050   mask("bucket", (unsigned long) (LOG_BUCKET), "Display bucket diagnostic information");
00051   mask("part",   (unsigned long) (LOG_PART),   "Display bucket diagnostic information");
00052   mask("field",  (unsigned long) (LOG_FIELD),  "Display bucket diagnostic information");
00053 }
00054 
00055 namespace {
00056 
00057 void bootstrap()
00058 {
00059 //  diag::registerWriter("meshlog", meshlog, theDiagWriterParser());
00060 }
00061 
00062 std::string log_to_str(EntityModificationLog log)
00063 {
00064   if (log == 0) {
00065     return "Not changed";
00066   }
00067   else if (log == 1) {
00068     return "Created";
00069   }
00070   else if (log == 2) {
00071     return "Modified";
00072   }
00073   else if (log == 3) {
00074     return "Marked deleted";
00075   }
00076   else {
00077     ThrowRequireMsg(false, "Unknown log " << log);
00078   }
00079   return "";
00080 }
00081 
00082 stk::Bootstrap x(&bootstrap);
00083 
00084 } // namespace <unnamed>
00085 
00086 stk::diag::Writer& operator<<(stk::diag::Writer& writer, const Part& part)
00087 {
00088   return writer << "Part[" << part.name() << ", " << part.mesh_meta_data_ordinal() << "]";
00089 }
00090 
00091 stk::diag::Writer& operator<<(stk::diag::Writer& writer, const Entity& entity)
00092 {
00093   // Get bucket of entity
00094   Bucket* bucket = NULL;
00095   try {
00096     bucket = &(entity.bucket());
00097   }
00098   catch (...) {} // leave bucket as NULL if it's not found
00099 
00100   std::string ownership_info = "unregistered";
00101   std::string entity_key_str;
00102   EntityKey key = entity.key();
00103   if (bucket) {
00104     MetaData& meta_data = MetaData::get(*bucket);
00105     Part &   owned  = meta_data.locally_owned_part();
00106     Part &   shared = meta_data.globally_shared_part();
00107     if (bucket->member(owned)) {
00108       ownership_info = "owned";
00109     }
00110     else if (bucket->member(shared)) {
00111       ownership_info = "shared";
00112     }
00113     else if (bucket->size() == 0) {
00114       ownership_info = "marked deleted";
00115     }
00116     else {
00117       ownership_info = "ghosted";
00118     }
00119     entity_key_str = print_entity_key(meta_data, key);
00120   }
00121   else {
00122     std::ostringstream out;
00123     out << "(rank:" << key.rank() << ",id:" << key.id() << ")";
00124     entity_key_str = out.str();
00125   }
00126 
00127   writer << "Entity[key:" << entity_key_str <<
00128                  ", ownership:" << ownership_info <<
00129                  ", log:" << log_to_str(entity.log_query()) <<
00130                  ", owner:" << entity.owner_rank();
00131 
00132   // print comm info
00133   writer << ", COMM: ";
00134   PairIterEntityComm comm_itr = entity.comm();
00135   for ( ; !comm_itr.empty(); ++comm_itr ) {
00136     writer << "(ghost:" << comm_itr->ghost_id << ", proc:" << comm_itr->proc << ") ";
00137   }
00138   return writer << "]";
00139 }
00140 
00141 stk::diag::Writer& operator<<(stk::diag::Writer& writer, const EntityKey& key)
00142 {
00143   return writer << "Entity[rank:" << key.rank() << ", id:" << key.id() << "]";
00144 }
00145 
00146 stk::diag::Writer& operator<<(stk::diag::Writer& writer, const EntityProc& entity_proc)
00147 {
00148   return writer << "EntityProc[entity:" << *entity_proc.first << ", proc: " << entity_proc.second << "]";
00149 }
00150 
00151 } // namespace mesh
00152 } // namespace stk
00153 
00154 #endif // STK_MESH_TRACE_ENABLED
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends