SheafSystem  0.0.0.0
query_mesh.cc
1 
2 //
3 // Copyright (c) 2014 Limit Point Systems, Inc.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 
19 
20 #include "SheafSystem/adjacency_extractor.h"
21 #include "SheafSystem/connectivity_extractor.h"
22 #include "SheafSystem/id_map.h"
23 #include "SheafSystem/namespace_poset.h"
24 #include "SheafSystem/neighborhood_extractor.h"
25 #include "SheafSystem/postorder_member_iterator.h"
26 #include "SheafSystem/std_iostream.h"
27 #include "SheafSystem/stencil_extractor.h"
28 #include "SheafSystem/storage_agent.h"
29 
30 using namespace fiber_bundle;
31 
33 
34 char* sp_names[3] = {const_cast<char *>("__vertices"),
35  const_cast<char *>("__edges"),
36  const_cast<char *>("__elements")};
37 
38 
39 void
40 init_id_array(poset* mesh, const string& sp_name, int* domain_mbrs)
41 {
42  subposet sp(mesh, sp_name);
43 
44  id_map* id_map = sp.id_map();
45  int i=0;
46  postorder_member_iterator itr(mesh->top(), &sp);
47  while(!itr.is_done())
48  {
49  domain_mbrs[i++] = id_map->domain_id(itr.item().index());
50  itr.next();
51  }
52 
53  sp.detach_from_state();
54 }
55 
56 
57 void
58 print_it(int* ids, int* ids_cts, int* domain_mbrs, int domain_mbrs_ct)
59 {
60  int* ids_p = ids;
61 
62  cout << endl;
63  for(int i=0; i<domain_mbrs_ct; i++)
64  {
65  cout << "mbr= " << setw(5) << domain_mbrs[i] << " ids=";
66 
67  for(int j=0; j<ids_cts[i]; j++)
68  {
69  cout << " " << setw(5) << *ids_p;
70  ids_p++;
71  }
72  cout << endl;
73  }
74  cout << endl << endl;
75 }
76 
77 
78 void
79 query_connectivity(poset* mesh, int upper_level, int lower_level, bool use_poset_api)
80 {
81  // Get a handle to the top of the mesh poset
82 
83  abstract_poset_member* mesh_top = &(mesh->top());
84 
85  // Get the subposet names
86 
87  string ll_name(sp_names[lower_level]);
88  string ul_name(sp_names[upper_level]);
89 
90  cout << endl << endl;
91  cout << "connectivity for " << ll_name << " and " << ul_name << endl;
92 
93  // Make a connectivity extractor
94 
95  connectivity_extractor ae(mesh, ll_name, ul_name);
96 
97  // Get the number of entries in the connectivity array
98 
99  ae.count(mesh_top);
100  int domain_mbrs_ct = ae.domain_mbrs_ct();
101  int conn_cts_ct = ae.connectivity_cts_ct();
102  int conn_ct = ae.connectivity_ct();
103 
104  // Allocate the connectivity counts and connectivity arrays
105 
106  int* domain_mbrs = new int[domain_mbrs_ct];
107  int* conn_cts = new int[conn_cts_ct];
108  int* conn = new int[conn_ct];
109 
110  // Extract the connectivity
111 
112  if (use_poset_api)
113  {
114  // Use poset member api
115 
116  ae.extract(mesh_top, domain_mbrs, domain_mbrs_ct, conn_cts, conn_cts_ct, conn, conn_ct);
117  }
118  else
119  {
120  // Use array api
121 
122  // Client will typically have domain of query
123  // represented as array of ids, but native sheaf
124  // code like this doesn't, so we have to make
125  // an array of client ids.
126 
127  init_id_array(mesh, ul_name, domain_mbrs);
128 
129  ae.extract(domain_mbrs, domain_mbrs_ct, conn_cts, conn_cts_ct, conn, conn_ct);
130  }
131 
132  // Print it
133 
134  print_it(conn, conn_cts, domain_mbrs, domain_mbrs_ct);
135 
136 }
137 
138 
139 void
140 query_adjacency(poset* mesh, int upper_level, int lower_level, bool use_poset_api)
141 {
142  // Get a handle to the top of the mesh poset
143 
144  abstract_poset_member* mesh_top = &(mesh->top());
145 
146  // Get the subposet names
147 
148  string ul_name(sp_names[upper_level]);
149  string ll_name(sp_names[lower_level]);
150 
151  cout << endl << endl;
152  cout << "adjacency for " << ll_name << " and " << ul_name << endl;
153 
154  // Make a adjacency extractor
155 
156  adjacency_extractor ae(mesh, ll_name, ul_name);
157 
158  // Get the number of entries in the adjacency array for the bottom
159 
160  ae.count(mesh_top);
161  int domain_mbrs_ct = ae.domain_mbrs_ct();
162  int adj_cts_ct = ae.adjacency_cts_ct();
163  int adj_ct = ae.adjacency_ct();
164 
165  // Allocate the adjacency counts and adjacency arrays
166 
167  int* domain_mbrs = new int[domain_mbrs_ct];
168  int* adj_cts = new int[adj_cts_ct];
169  int* adj = new int[adj_ct];
170 
171  // Extract the adjacency
172 
173  if (use_poset_api)
174  {
175  // Use poset member api
176 
177  ae.extract(mesh_top, domain_mbrs, domain_mbrs_ct, adj_cts, adj_cts_ct, adj, adj_ct);
178  }
179  else
180  {
181  // Use array api
182 
183  // Client will typically have domain of query
184  // represented as array of ids, but native sheaf
185  // code like this doesn't, so we have to make
186  // an array of client ids.
187 
188  init_id_array(mesh, ll_name, domain_mbrs);
189 
190  ae.extract(domain_mbrs, domain_mbrs_ct, adj_cts, adj_cts_ct, adj, adj_ct);
191  }
192 
193 
194  // Print it
195 
196  print_it(adj, adj_cts, domain_mbrs, domain_mbrs_ct);
197 
198 }
199 
200 void
201 query_neighborhood(poset* mesh,
202  int upper_level,
203  int lower_level,
204  bool includes_center,
205  bool use_poset_api)
206 {
207  // Get a handle to the top of the mesh poset
208 
209  abstract_poset_member* mesh_top = &(mesh->top());
210 
211  // Get the subposet names
212 
213  string ll_name(sp_names[lower_level]);
214  string ul_name(sp_names[upper_level]);
215 
216  cout << endl << endl;
217  cout << "neighborhood for " << ll_name << " and " << ul_name << endl;
218 
219  // Make a neighborhood extractor
220 
221  neighborhood_extractor ae(mesh, ll_name, ul_name, includes_center);
222 
223  // Get the number of entries in the neighborhood array
224 
225  ae.count(mesh_top);
226  int domain_mbrs_ct = ae.domain_mbrs_ct();
227  int nbr_cts_ct = ae.neighborhood_cts_ct();
228  int nbr_ct = ae.neighborhood_ct();
229 
230  // Allocate the neighborhood counts and neighborhood arrays
231 
232  int* domain_mbrs = new int[domain_mbrs_ct];
233  int* nbr_cts = new int[nbr_cts_ct];
234  int* nbr = new int[nbr_ct];
235 
236  // Extract the neighborhood
237 
238  if (use_poset_api)
239  {
240  // Use poset member api
241 
242  ae.extract(mesh_top, domain_mbrs, domain_mbrs_ct, nbr_cts, nbr_cts_ct, nbr, nbr_ct);
243  }
244  else
245  {
246  // Use array api
247 
248  // Client will typically have domain of query
249  // represented as array of ids, but native sheaf
250  // code like this doesn't, so we have to make
251  // an array of client ids.
252 
253  init_id_array(mesh, ul_name, domain_mbrs);
254 
255  ae.extract(domain_mbrs, domain_mbrs_ct, nbr_cts, nbr_cts_ct, nbr, nbr_ct);
256  }
257 
258 
259  // Print it
260 
261  print_it(nbr, nbr_cts, domain_mbrs, domain_mbrs_ct);
262 
263 }
264 
265 
266 
267 void
268 query_stencil(poset* mesh,
269  int upper_level,
270  int lower_level,
271  bool includes_center,
272  bool use_poset_api)
273 {
274  // Get a handle to the top of the mesh poset
275 
276  abstract_poset_member* mesh_top = &(mesh->top());
277 
278  // Get the subposet names
279 
280  string ll_name(sp_names[lower_level]);
281  string ul_name(sp_names[upper_level]);
282 
283  cout << endl << endl;
284  cout << "stencil for " << ll_name << " and " << ul_name << endl;
285 
286  // Make a stencil extractor
287 
288  stencil_extractor ae(mesh, ll_name, ul_name, includes_center);
289 
290  // Get the number of entries in the stencil array
291 
292  ae.count(mesh_top);
293  int domain_mbrs_ct = ae.domain_mbrs_ct();
294  int sten_cts_ct = ae.stencil_cts_ct();
295  int sten_ct = ae.stencil_ct();
296 
297  // Allocate the stencil counts and stencil arrays
298 
299  int* domain_mbrs = new int[domain_mbrs_ct];
300  int* sten_cts = new int[sten_cts_ct];
301  int* sten = new int[sten_ct];
302 
303  // Extract the stencil
304 
305  if (use_poset_api)
306  {
307  // Use poset member api
308 
309  ae.extract(mesh_top, domain_mbrs, domain_mbrs_ct, sten_cts, sten_cts_ct, sten, sten_ct);
310  }
311  else
312  {
313  // Use array api
314 
315  // Client will typically have domain of query
316  // represented as array of ids, but native sheaf
317  // code like this doesn't, so we have to make
318  // an array of client ids.
319 
320  init_id_array(mesh, ll_name, domain_mbrs);
321 
322  ae.extract(domain_mbrs, domain_mbrs_ct, sten_cts, sten_cts_ct, sten, sten_ct);
323  }
324 
325 
326  // Print it
327 
328  print_it(sten, sten_cts, domain_mbrs, domain_mbrs_ct);
329 
330 }
331 
332 
333 void
334 query_mesh(namespace_poset* ns,
335  const string& mesh_name,
336  bool use_poset_api)
337 {
338  // Get a handle to the top of the mesh poset
339 
340  poset* mesh = new poset(ns, mesh_name);
341  mesh->get_read_access();
342 
343  // Query element-nodal connectivity
344 
345  query_connectivity(mesh, 2, 0, false);
346  if (use_poset_api)
347  query_connectivity(mesh, 2, 0, true);
348 
349  // Query element-edge connectivity
350 
351  query_connectivity(mesh, 2, 1, false);
352  if (use_poset_api)
353  query_connectivity(mesh, 2, 1, true);
354 
355  // Query edge-nodal connectivity
356 
357  query_connectivity(mesh, 1, 0, false);
358  if (use_poset_api)
359  query_connectivity(mesh, 1, 0, true);
360 
361  // Query element-nodal adjacency,
362 
363  query_adjacency(mesh, 2, 0, false);
364  if (use_poset_api)
365  query_adjacency(mesh, 2, 0, true);
366 
367  // Query element-edge adjacency,
368 
369  query_adjacency(mesh, 2, 1, false);
370  if (use_poset_api)
371  query_adjacency(mesh, 2, 1, true);
372 
373  // Query edge-nodal adjacency,
374 
375  query_adjacency(mesh, 1, 0, false);
376  if (use_poset_api)
377  query_adjacency(mesh, 1, 0, true);
378 
379  // Query element-nodal neighborhood
380 
381  query_neighborhood(mesh, 2, 0, false, false);
382  if (use_poset_api)
383  query_neighborhood(mesh, 2, 0, true, true);
384 
385  // Query element-edge neighborhood
386 
387  query_neighborhood(mesh, 2, 1, false, false);
388  if (use_poset_api)
389  query_neighborhood(mesh, 2, 1, true, true);
390 
391  // Query edge-nodal neighborhood
392 
393  query_neighborhood(mesh, 1, 0, false, false);
394  if (use_poset_api)
395  query_neighborhood(mesh, 1, 0, true, true);
396 
397  // Query element-nodal stencil
398 
399  query_stencil(mesh, 2, 0, false, false);
400  if (use_poset_api)
401  query_stencil(mesh, 2, 0, true, true);
402 
403  // Query element-edge stencil
404 
405  query_stencil(mesh, 2, 1, false, false);
406  if (use_poset_api)
407  query_stencil(mesh, 2, 1, true, true);
408 
409  // Query edge-nodal stencil
410 
411  query_stencil(mesh, 1, 0, false, false);
412  if (use_poset_api)
413  query_stencil(mesh, 1, 0, true, true);
414 
415 }
416 
417 
418 int
419 main(int argc, char** argv)
420 {
421  string filename;
422  string mesh_name;
423 
424  if (argc > 2)
425  {
426  filename = argv[1];
427  mesh_name = argv[2];
428  }
429  else
430  {
431  cerr << "usage: query_mesh sheaf_file mesh_name [use_poset_api]\n";
432  exit(1);
433  }
434 
435  bool use_poset_api = argc > 3;
436 
437  storage_agent sa(filename, sheaf_file::READ_ONLY, false);
438 
439  namespace_poset ns;
440 
441  sa.read_entire(ns);
442 
443  ns.get_read_access();
444 
445  query_mesh(&ns, mesh_name, use_poset_api);
446 
447  return 0;
448 }
A client handle for a subposet.
Definition: subposet.h:86
abstract_poset_member & top()
The top member of the poset (mutable version)
The default name space; a poset which contains other posets as members.
A client handle for a mutable partially ordered set.
Definition: poset.h:40
virtual void get_read_access() const
Get read access to the state associated with this.
virtual void next()
Makes this the next member of the iteration.
virtual void get_read_access() const
Get read access to the state associated with this.
An abstract client handle for a member of a poset.
Namespace for the fiber_bundles component of the sheaf system.
Agent responsible for importing and exporting posets from an external name space which resides on dis...
Definition: storage_agent.h:74