Sierra Toolkit  Version of the Day
DiagWriter.cpp
1 /*--------------------------------------------------------------------*/
2 /* Copyright 2000 - 2011 Sandia Corporation. */
3 /* Under the terms of Contract DE-AC04-94AL85000, there is a */
4 /* non-exclusive license for use of this work by or on behalf */
5 /* of the U.S. Government. Export of this program may require */
6 /* a license from the United States Government. */
7 /*--------------------------------------------------------------------*/
8 
9 #ifdef STK_MESH_TRACE_ENABLED
10 
11 #include <stk_util/util/Bootstrap.hpp>
12 
13 #include <stk_mesh/base/DiagWriter.hpp>
14 #include <stk_mesh/base/Entity.hpp>
15 #include <stk_mesh/base/Bucket.hpp>
16 #include <stk_mesh/base/MetaData.hpp>
17 
18 namespace stk_classic {
19 namespace mesh {
20 
21 namespace {
22 
23 static stk_classic::diag::Writer* s_diagWriter = NULL;
24 
25 }
26 
27 void initDiagWriter(std::ostream& stream)
28 {
29  s_diagWriter = new stk_classic::diag::Writer(stream.rdbuf(),
30  theDiagWriterParser().parse(std::getenv("MESHLOG")));
31 }
32 
33 stk_classic::diag::Writer & theDiagWriter()
34 {
35  ThrowRequireMsg(s_diagWriter != NULL, "Please call initDiagWwriter before theDiagWriter");
36  return *s_diagWriter;
37 }
38 
39 DiagWriterParser & theDiagWriterParser()
40 {
41  static DiagWriterParser parser;
42 
43  return parser;
44 }
45 
46 DiagWriterParser::DiagWriterParser()
47  : stk_classic::diag::WriterParser()
48 {
49  mask("entity", (unsigned long) (LOG_ENTITY), "Display entity diagnostic information");
50  mask("bucket", (unsigned long) (LOG_BUCKET), "Display bucket diagnostic information");
51  mask("part", (unsigned long) (LOG_PART), "Display bucket diagnostic information");
52  mask("field", (unsigned long) (LOG_FIELD), "Display bucket diagnostic information");
53 }
54 
55 namespace {
56 
57 void bootstrap()
58 {
59 // diag::registerWriter("meshlog", meshlog, theDiagWriterParser());
60 }
61 
62 std::string log_to_str(EntityModificationLog log)
63 {
64  if (log == 0) {
65  return "Not changed";
66  }
67  else if (log == 1) {
68  return "Created";
69  }
70  else if (log == 2) {
71  return "Modified";
72  }
73  else if (log == 3) {
74  return "Marked deleted";
75  }
76  else {
77  ThrowRequireMsg(false, "Unknown log " << log);
78  }
79  return "";
80 }
81 
82 stk_classic::Bootstrap x(&bootstrap);
83 
84 } // namespace <unnamed>
85 
87 {
88  return writer << "Part[" << part.name() << ", " << part.mesh_meta_data_ordinal() << "]";
89 }
90 
92 {
93  // Get bucket of entity
94  Bucket* bucket = NULL;
95  try {
96  bucket = &(entity.bucket());
97  }
98  catch (...) {} // leave bucket as NULL if it's not found
99 
100  std::string ownership_info = "unregistered";
101  std::string entity_key_str;
102  EntityKey key = entity.key();
103  if (bucket) {
104  MetaData& meta_data = MetaData::get(*bucket);
105  Part & owned = meta_data.locally_owned_part();
106  Part & shared = meta_data.globally_shared_part();
107  if (bucket->member(owned)) {
108  ownership_info = "owned";
109  }
110  else if (bucket->member(shared)) {
111  ownership_info = "shared";
112  }
113  else if (bucket->size() == 0) {
114  ownership_info = "marked deleted";
115  }
116  else {
117  ownership_info = "ghosted";
118  }
119  entity_key_str = print_entity_key(meta_data, key);
120  }
121  else {
122  std::ostringstream out;
123  out << "(rank:" << key.rank() << ",id:" << key.id() << ")";
124  entity_key_str = out.str();
125  }
126 
127  writer << "Entity[key:" << entity_key_str <<
128  ", ownership:" << ownership_info <<
129  ", log:" << log_to_str(entity.log_query()) <<
130  ", owner:" << entity.owner_rank();
131 
132  // print comm info
133  writer << ", COMM: ";
134  PairIterEntityComm comm_itr = entity.comm();
135  for ( ; !comm_itr.empty(); ++comm_itr ) {
136  writer << "(ghost:" << comm_itr->ghost_id << ", proc:" << comm_itr->proc << ") ";
137  }
138  return writer << "]";
139 }
140 
141 stk_classic::diag::Writer& operator<<(stk_classic::diag::Writer& writer, const EntityKey& key)
142 {
143  return writer << "Entity[rank:" << key.rank() << ", id:" << key.id() << "]";
144 }
145 
147 {
148  return writer << "EntityProc[entity:" << *entity_proc.first << ", proc: " << entity_proc.second << "]";
149 }
150 
151 } // namespace mesh
152 } // namespace stk_classic
153 
154 #else
155 int dummy_DiagWriter()
156 {
157  // This function is present just to put a symbol in the object
158  // file and eliminate a "empty object file" warning on the mac...
159  return 1;
160 }
161 #endif // STK_MESH_TRACE_ENABLED
std::ostream & out()
Normal output stream.
Definition: OutputLog.cpp:658
std::pair< Entity *, unsigned > EntityProc
Pairing of an entity with a processor rank.
Definition: Types.hpp:111
std::ostream & operator<<(std::ostream &s, const Bucket &k)
Print the part names for which this bucket is a subset.
Definition: Bucket.cpp:239
Sierra Toolkit.
Class Writer implements a runtime selectable diagnostic output writer to aid in the development and d...
Definition: Writer.hpp:49
Class Bootstrap serves as a bootstrapping mechanism for products in the sierra toolkit and elsewhere...
Definition: Bootstrap.hpp:35
PairIter< std::vector< EntityCommInfo >::const_iterator > PairIterEntityComm
Span of ( communication-subset-ordinal , process-rank ) pairs for the communication of an entity...
Definition: Types.hpp:128