SheafSystem  0.0.0.0
base_space_factory.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 
18 // Template specializations for class base_space_factory.
19 
20 #include "SheafSystem/base_space_factory.impl.h"
21 
22 //#include "SheafSystem/base_space_member_prototype.h"
23 #include "SheafSystem/hex_connectivity.h"
24 #include "SheafSystem/line_connectivity.h"
25 #include "SheafSystem/point_block_1d.h"
26 #include "SheafSystem/point_block_2d.h"
27 #include "SheafSystem/point_block_3d.h"
28 #include "SheafSystem/quad_connectivity.h"
29 #include "SheafSystem/structured_block_1d.h"
30 #include "SheafSystem/structured_block_2d.h"
31 #include "SheafSystem/structured_block_3d.h"
32 #include "SheafSystem/tetra_connectivity.h"
33 #include "SheafSystem/triangle_connectivity.h"
34 #include "SheafSystem/unstructured_block.h"
35 #include "SheafSystem/zone_nodes_block.h"
36 
37 using namespace std;
38 
39 //==============================================================================
40 // SPECIALIZATION FOR STRUCTURED_BLOCK_1D
41 //==============================================================================
42 
47 template <>
48 SHEAF_DLL_SPEC
51 new_base(fiber_bundles_namespace& xns, const std::string& xbase_name)
52 {
53  // Preconditions:
54 
55  require(xns.state_is_read_write_accessible());
56  require(poset_path::is_valid_name(path.poset_name()));
57  require(poset_path::is_valid_name(xbase_name));
58  require(xns.contains_poset_member(poset_path(path.poset_name(), xbase_name)) ||
59  index_ubs.ct() >= 1);
60 
61  // Body:
62 
64 
65  poset_path lbase_path(path.poset_name(), xbase_name);
66 
67  if(xns.contains_poset_member(lbase_path, true))
68  {
69  result->attach_to_state(&xns, lbase_path);
70  }
71  else
72  {
73  base_space_poset* lhost = new_space(xns);
74  result->new_state(lhost, index_ubs[0], true);
75  result->put_name(xbase_name, true, true);
76  }
77 
78  // Postconditions:
79 
80  ensure(result->name(true) == xbase_name);
81 
82  // Exit:
83 
84  return result;
85 }
86 
87 
88 //==============================================================================
89 // SPECIALIZATION FOR STRUCTURED_BLOCK_2D
90 //==============================================================================
91 
92 
93 template <>
94 SHEAF_DLL_SPEC
97 new_base(fiber_bundles_namespace& xns, const std::string& xbase_name)
98 {
99  // Preconditions:
100 
101  require(xns.state_is_read_write_accessible());
102  require(poset_path::is_valid_name(path.poset_name()));
103  require(poset_path::is_valid_name(xbase_name));
104  require(xns.contains_poset_member(poset_path(path.poset_name(), xbase_name)) ||
105  index_ubs.ct() >= 2);
106 
107  // Body:
108 
110  poset_path lbase_path(path.poset_name(), xbase_name);
111 
112  if(xns.contains_poset_member(lbase_path, true))
113  {
114  result->attach_to_state(&xns, lbase_path);
115  }
116  else
117  {
118  base_space_poset* lhost = new_space(xns);
119  result->new_state(lhost, index_ubs[0], index_ubs[1], true);
120  result->put_name(xbase_name, true, true);
121  }
122 
123  // Postconditions:
124 
125  ensure(result->name(true) == xbase_name);
126 
127  // Exit:
128 
129  return result;
130 }
131 
132 
133 //==============================================================================
134 // SPECIALIZATION FOR STRUCTURED_BLOCK_3D
135 //==============================================================================
136 
137 
142 template <>
143 SHEAF_DLL_SPEC
146 new_base(fiber_bundles_namespace& xns, const std::string& xbase_name)
147 {
148  // Preconditions:
149 
150  require(xns.state_is_read_write_accessible());
151  require(poset_path::is_valid_name(path.poset_name()));
152  require(poset_path::is_valid_name(xbase_name));
153  require(xns.contains_poset_member(poset_path(path.poset_name(), xbase_name)) ||
154  index_ubs.ct() >= 3);
155 
156  // Body:
157 
159 
160  poset_path lbase_path(path.poset_name(), xbase_name);
161  if(xns.contains_poset_member(lbase_path, true))
162  {
163  result->attach_to_state(&xns, lbase_path);
164  }
165  else
166  {
167  base_space_poset* lhost = new_space(xns);
168  result->new_state(lhost,
169  index_ubs[0],
170  index_ubs[1],
171  index_ubs[2],
172  true);
173  result->put_name(xbase_name, true, true);
174  }
175 
176  // Postconditions:
177 
178  ensure(result->name(true) == xbase_name);
179 
180  // Exit:
181 
182  return result;
183 }
184 
185 
186 //==============================================================================
187 // SPECIALIZATION FOR POINT_BLOCK_1D
188 //==============================================================================
189 
190 
191 template <>
192 SHEAF_DLL_SPEC
195 new_base(fiber_bundles_namespace& xns, const std::string& xbase_name)
196 {
197  // Preconditions:
198 
199  require(xns.state_is_read_write_accessible());
200  require(poset_path::is_valid_name(path.poset_name()));
201  require(poset_path::is_valid_name(xbase_name));
202  require(xns.contains_poset_member(poset_path(path.poset_name(), xbase_name)) || index_ubs.ct() >= 1);
203 
204  // Body:
205 
206  point_block_1d* result = new point_block_1d();
207  poset_path lbase_path(path.poset_name(), xbase_name);
208 
209  if(xns.contains_poset_member(lbase_path, true))
210  {
211  result->attach_to_state(&xns, lbase_path);
212  }
213  else
214  {
215  base_space_poset* lhost = new_space(xns);
216  result->new_state(lhost, index_ubs[0], true);
217  result->put_name(xbase_name, true, true);
218  }
219 
220  // Postconditions:
221 
222  ensure(result->name(true) == xbase_name);
223 
224  // Exit:
225 
226  return result;
227 }
228 
229 
230 //==============================================================================
231 // SPECIALIZATION FOR POINT_BLOCK_2D
232 //==============================================================================
233 
234 
235 template <>
236 SHEAF_DLL_SPEC
239 new_base(fiber_bundles_namespace& xns, const std::string& xbase_name)
240 {
241  // Preconditions:
242 
243  require(xns.state_is_read_write_accessible());
244  require(poset_path::is_valid_name(path.poset_name()));
245  require(poset_path::is_valid_name(xbase_name));
246  require(xns.contains_poset_member(poset_path(path.poset_name(), xbase_name)) || index_ubs.ct() >= 2);
247 
248  // Body:
249 
250  point_block_2d* result = new point_block_2d();
251  poset_path lbase_path(path.poset_name(), xbase_name);
252 
253  if(xns.contains_poset_member(lbase_path, true))
254  {
255  result->attach_to_state(&xns, lbase_path);
256  }
257  else
258  {
259  base_space_poset* lhost = new_space(xns);
260  result->new_state(lhost, index_ubs[0], index_ubs[1], true);
261  result->put_name(xbase_name, true, true);
262  }
263 
264  // Postconditions:
265 
266  ensure(result->name(true) == xbase_name);
267 
268  // Exit:
269 
270  return result;
271 }
272 
273 
274 //==============================================================================
275 // SPECIALIZATION FOR POINT_BLOCK_3D
276 //==============================================================================
277 
278 
279 template <>
280 SHEAF_DLL_SPEC
283 new_base(fiber_bundles_namespace& xns, const std::string& xbase_name)
284 {
285  // Preconditions:
286 
287  require(xns.state_is_read_write_accessible());
288  require(poset_path::is_valid_name(path.poset_name()));
289  require(poset_path::is_valid_name(xbase_name));
290  require(xns.contains_poset_member(poset_path(path.poset_name(), xbase_name)) || index_ubs.ct() >= 3);
291 
292  // Body:
293 
294  point_block_3d* result = new point_block_3d();
295  poset_path lbase_path(path.poset_name(), xbase_name);
296 
297  if(xns.contains_poset_member(lbase_path, true))
298  {
299  result->attach_to_state(&xns, lbase_path);
300  }
301  else
302  {
303  base_space_poset* lhost = new_space(xns);
304  result->new_state(lhost,
305  index_ubs[0],
306  index_ubs[1],
307  index_ubs[2],
308  true);
309  result->put_name(xbase_name, true, true);
310  }
311 
312  // Postconditions:
313 
314  ensure(result->name(true) == xbase_name);
315 
316  // Exit:
317 
318  return result;
319 }
320 
321 
322 //==============================================================================
323 // SPECIALIZATION FOR ZONE_NODES_BLOCK
324 //==============================================================================
325 
326 
327 template <>
328 SHEAF_DLL_SPEC
332 {
333  // Preconditions:
334 
335  require(xns.state_is_read_accessible());
336  require(!path.empty());
337  require(poset_path::is_valid_name(path.poset_name()));
338  require(xns.contains_poset(path.poset_name()) ||
339  ((1 <= index_ubs.ct()) && (index_ubs.ct() <= 3)));
340 
341  // Body:
342 
343  base_space_poset* result;
344 
345  int ldb = index_ubs.ct();
346 
347  if(xns.contains_poset(path, true))
348  {
349  result = dynamic_cast<base_space_poset*>(&xns.member_poset(path, false));
350  }
351  else
352  {
353  result = &zone_nodes_block::standard_host(xns, path.poset_name(), ldb, false);
354  }
355 
356  // Get
357 
358  // Postconditions:
359 
360  ensure(xns.contains_poset(path, true));
361 
362  // Exit:
363 
364  return result;
365 }
366 
367 template <>
368 SHEAF_DLL_SPEC
371 new_base(fiber_bundles_namespace& xns, const std::string& xbase_name)
372 {
373  // Preconditions:
374 
375  require(xns.state_is_read_write_accessible());
376  require(poset_path::is_valid_name(path.poset_name()));
377  require(poset_path::is_valid_name(xbase_name));
378  require(xns.contains_poset_member(poset_path(path.poset_name(), xbase_name)) ||
379  ((1 <= index_ubs.ct()) && (index_ubs.ct() <= 3)));
380 
381  // Body:
382 
383  zone_nodes_block* result = new zone_nodes_block();
384  poset_path lbase_path(path.poset_name(), xbase_name);
385 
386  poset_path llocal_cell_prototype_path(local_cell_prototype_path);
387 
388  if(xns.contains_poset_member(lbase_path))
389  {
390  result->attach_to_state(&xns, lbase_path);
391  }
392  else
393  {
394 
395  base_space_poset* lhost = new_space(xns);
396 
397  int ldb = index_ubs.ct();
398  switch(ldb)
399  {
400  case 1:
401  { // scope suppresses compiler warnings
402  line_connectivity lconn(index_ubs[0]);
403  result->new_state(*lhost, lconn, true);
404  }
405  break;
406  case 2:
407  if(llocal_cell_prototype_path.member_name() == "triangles_nodes")
408  {
409  triangle_connectivity lconn(index_ubs[0], index_ubs[1]);
410  result->new_state(*lhost, lconn, true);
411  }
412  else
413  {
414  quad_connectivity lconn(index_ubs[0], index_ubs[1]);
415  result->new_state(*lhost, lconn, true);
416  }
417  break;
418  case 3:
419  if(llocal_cell_prototype_path.member_name() == "tetra_nodes")
420  {
421  tetra_connectivity lconn(index_ubs[0], index_ubs[1], index_ubs[2]);
422  result->new_state(*lhost, lconn, true);
423  }
424  else
425  {
426  hex_connectivity lconn(index_ubs[0], index_ubs[1], index_ubs[2]);
427  result->new_state(*lhost, lconn, true);
428  }
429  break;
430  default:
431  post_fatal_error_message("Unsupported base dimension");
432  break;
433  }
434 
435  result->put_name(xbase_name, true, true);
436  }
437 
438  // Postconditions:
439 
440  ensure(result->name(true) == xbase_name);
441 
442  // Exit:
443 
444  return result;
445 }
446 
447 
448 //================================================================================================
449 // SPECIALIZATION FOR UNSTRUCTURED_BLOCK
450 //================================================================================================
451 
452 
453 template <>
454 SHEAF_DLL_SPEC
458 {
459  // Preconditions:
460 
461  require(xns.state_is_read_accessible());
462  require(!path.empty());
463  require(poset_path::is_valid_name(path.poset_name()));
464 
465  // Body:
466 
467  base_space_poset* result;
468 
469  int ldb = index_ubs.ct();
470 
471 
472  if(xns.contains_poset(path, true))
473  {
474  result = dynamic_cast<base_space_poset*>(&xns.member_poset(path, false));
475  }
476  else
477  {
478  zone_nodes_block::standard_host(xns, path.poset_name(), ldb, false);
479  result = &xns.member_poset<base_space_poset>(path.poset_name());
480  }
481 
482  // Get
483 
484  // Postconditions:
485 
486  ensure(xns.contains_poset(path, true));
487 
488  // Exit:
489 
490  return result;
491 }
492 
493 template <>
494 SHEAF_DLL_SPEC
497 new_base(fiber_bundles_namespace& xns, const std::string& xbase_name)
498 {
499  // Preconditions:
500 
501  require(xns.state_is_read_write_accessible());
502  require(poset_path::is_valid_name(path.poset_name()));
503  require(poset_path::is_valid_name(xbase_name));
504  require(xns.contains_poset_member(poset_path(path.poset_name(), xbase_name)) ||
505  ((1 <= index_ubs.ct()) && (index_ubs.ct() <= 3)));
506 
507  // Body:
508 
509  unstructured_block* result = new unstructured_block();
510  poset_path lbase_path(path.poset_name(), xbase_name);
511 
512  poset_path llocal_cell_prototype_path(local_cell_prototype_path);
513 
514  if(xns.contains_poset_member(lbase_path))
515  {
516  result->attach_to_state(&xns, lbase_path);
517  }
518  else
519  {
520 
521  base_space_poset* lhost = new_space(xns);
522 
523  string lposet_name(base_space_member::prototypes_poset_name());
524 
525  int ldb = index_ubs.ct();
526  switch(ldb)
527  {
528  case 1:
529  if(llocal_cell_prototype_path.empty())
530  {
531  llocal_cell_prototype_path.put_poset_name(lposet_name);
532  llocal_cell_prototype_path.put_member_name("segment_complex");
533  }
534 
535  result->new_state(lhost,
536  llocal_cell_prototype_path,
537  index_ubs[0],
538  true);
539  break;
540  case 2:
541  if(llocal_cell_prototype_path.empty())
542  {
543  llocal_cell_prototype_path.put_poset_name(lposet_name);
544  llocal_cell_prototype_path.put_member_name("quad_nodes");
545  }
546  result->new_state(lhost,
547  llocal_cell_prototype_path,
548  index_ubs[0],
549  index_ubs[1],
550  true);
551  break;
552  case 3:
553  if(llocal_cell_prototype_path.empty())
554  {
555  llocal_cell_prototype_path.put_poset_name(lposet_name);
556  llocal_cell_prototype_path.put_member_name("hex_nodes");
557  }
558  result->new_state(lhost,
559  llocal_cell_prototype_path,
560  index_ubs[0],
561  index_ubs[1],
562  index_ubs[2],
563  true);
564  break;
565  default:
566  post_fatal_error_message("Unsupported base dimension");
567  break;
568  }
569 
570  result->put_name(xbase_name, true, true);
571  }
572 
573  // Postconditions:
574 
575  ensure(result->name(true) == xbase_name);
576 
577  // Exit:
578 
579  return result;
580 }
581 
582 
A homogeneous collection of connected quads arranged in an i_size() x j_size() array.
bool state_is_read_accessible() const
True if this is attached and if the state is accessible for read or access control is disabled...
The standard fiber bundles name space; extends the standard sheaves namespace by defining base space...
bool contains_poset_member(pod_index_type xposet_hub_id, pod_index_type xmember_hub_id, bool xauto_access=true) const
True if this contains a poset with hub id xposet_hub_id which contains a member with hub id xmember_h...
A path defined by a poset name and a member name separated by a forward slash (&#39;/&#39;). For example: "cell_definitions/triangle".
Definition: poset_path.h:48
STL namespace.
A homogeneous collection of zones with nodal connectivity.
base_space_poset * new_space(fiber_bundles_namespace &xns)
Finds or creates the base space poset specified by path in namespace xns.
poset_state_handle & member_poset(pod_index_type xhub_id, bool xauto_access=true) const
The poset_state_handle object referred to by hub id xhub_id.
OBSOLETE: use zone_nodes_block or point_block_*d. A client handle for a base space member which repre...
Nodal connectivity for a block containing zones of type tetra.
A homogeneous collection of connected segments arranged in an i_size() array.
Nodal connectivity for a block containing zones of type triangle.
The lattice of closed cells of a cellular space; a lattice representation of a computational mesh...
bool state_is_read_write_accessible() const
True if this is attached and if the state is accessible for read and write or access control is disab...
A homogeneous collection of i_size() * j_size() disconnected points similar to a structured_block_2d...
Nodal connectivity for a block containing zones of type hex.
bool contains_poset(pod_index_type xhub_id, bool xauto_access=true) const
True if this contains a poset with hub id xhub_id..
A homogeneous collection of connected hexahedra arranged in an i_size() x j_size() x k_size() array...
Nodal connectivity for a block containing zones of type segment.
Nodal connectivity for a block containing zones of type quad.
A homogeneous collection of i_size() disconnected points; similar to a structured_block_1d, but without the segments.
A homogeneous collection of i_size()*j_size()*k_size() disconnected points similar to a structured_bl...
base_type * new_base(fiber_bundles_namespace &xns, const poset_path &xbase_path)
Finds or creates the base space specified by xbase_path in namespace xns.