SheafSystem  0.0.0.0
sparse_section_dof_map.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 // Implementation for class sparse_section_dof_map
19 
20 #include "SheafSystem/sparse_section_dof_map.h"
21 
22 #include "SheafSystem/assert_contract.h"
23 #include "SheafSystem/dof_map_factory.h"
24 #include "SheafSystem/ij_product_structure.h"
25 #include "SheafSystem/index_space_iterator.h"
26 #include "SheafSystem/primitive_type.h"
27 #include "SheafSystem/sec_rep_space.h"
28 #include "SheafSystem/sec_vd.h"
29 
30 using namespace std;
31 using namespace fiber_bundle; // Workaround for MS C++ bug.
32 
33 // PUBLIC MEMBER FUNCTIONS
34 
36 const std::string&
38 class_name() const
39 {
40  // Preconditions:
41 
42  // Body:
43 
44  const string& result = static_class_name();
45 
46  // Postconditions:
47 
48  ensure(!result.empty());
49 
50  // Exit:
51 
52  return result;
53 }
54 
56 const std::string&
59 {
60  // Preconditions:
61 
62  // Body:
63 
64  static const string result("sparse_section_dof_map");
65 
66  // Postconditions:
67 
68  ensure(!result.empty());
69  ensure(result == "sparse_section_dof_map");
70 
71  // Exit:
72 
73  return result;
74 }
75 
76 // CANONICAL MEMBERS
77 
81  : section_dof_map()
82 {
83 
84  // Preconditions:
85 
86 
87  // Body:
88 
89  _def_val = 0.0;
90 
91  // Postconditions:
92 
93  ensure(invariant());
94  ensure(!is_initialized());
95 
96 
97  // Exit
98 
99  return;
100 }
101 
105  : section_dof_map(xother)
106 {
107 
108  // Preconditions:
109 
110 
111  // Body:
112 
113  *this = xother;
114 
115  // Postconditions:
116 
117  ensure(invariant());
118 
119  // Exit
120 
121  return;
122 }
123 
126  : section_dof_map(xhost, xhost->base().index().pod(), xhost->version())
127 {
128 
129  // Preconditions:
130 
131  require(xhost != 0);
132  require(xhost->state_is_read_accessible());
133 
134  // Body:
135 
136  _def_val = xdefault_value;
137 
138  // Postconditions:
139 
140  ensure(default_value() == xdefault_value);
141 
142 }
143 
147 clone() const
148 {
149  sparse_section_dof_map* result;
150 
151  // Preconditions:
152 
153 
154  // Body:
155 
156  result = new sparse_section_dof_map();
157 
158  // Postconditions:
159 
160  ensure(result != 0);
161  ensure(result->is_same_type(this));
162  ensure(postcondition_of(sparse_section_dof_map()));
163 
164  // Exit:
165 
166  return result;
167 }
168 
169 
173 copy() const
174 {
175  sparse_section_dof_map* result;
176 
177  // Preconditions:
178 
179 
180  // Body:
181 
182  result = new sparse_section_dof_map(*this);
183 
184  // Postconditions:
185 
186  ensure(result != 0);
187  ensure(result->is_same_type(this));
188  ensure(postcondition_of(sparse_section_dof_map(*this)));
189 
190  // Exit:
191 
192  return result;
193 }
194 
195 
200 {
201 
202  // Preconditions:
203 
204  require(xother.is_initialized());
205 
206  // Body:
207 
209 
210  _val_map.clear();
211  _val_map = xother._val_map;
212 
213  _def_val = xother._def_val;
214 
215 
216  // Postconditions:
217 
218  ensure(invariant());
219 
220  // Exit
221 
222  return *this;
223 }
224 
225 
229 {
230  // Preconditions:
231 
232 
233  // Body:
234 
235  // Nothing to do.
236 
237  // Postconditions:
238 
239  // Exit:
240 
241  return;
242 }
243 
244 
246 bool
248 invariant() const
249 {
250  bool result = true;
251 
252  // Preconditions:
253 
254  // Body:
255 
257 
258  // Postconditions:
259 
260  // Exit
261 
262  return result;
263 }
264 
265 
266 // ===========================================================
267 // MAP FACET
268 // ===========================================================
269 
270 
271 // ===========================================================
272 // NEW DOF ACCESS FACET
273 // ===========================================================
274 
276 void
278 get_dof(pod_index_type xdof_id, void* xdof, size_type xdof_size) const
279 {
280  // Preconditions:
281 
282  require(schema().state_is_read_accessible());
283  require(schema().dof_id_space(is_table_dof_map()).contains(xdof_id));
284  require(unexecutable("xdof points to buffer of size xdof_size"));
285  require(xdof_size >= schema().size(xdof_id, is_table_dof_map()));
286 
287  // Body:
288 
289  sec_vd_dof_type& ldof = *reinterpret_cast<sec_vd_dof_type*>(xdof);
290 
291  val_map_type::const_iterator itr = _val_map.find(xdof_id);
292 
293  if(itr != _val_map.end())
294  {
295  ldof = itr->second;
296  }
297  else
298  {
299  ldof = _def_val;
300  }
301 
302  // Postconditions:
303 
304  // Exit
305 
306  return;
307 }
308 
310 void
312 put_dof(pod_index_type xdof_id, const void* xdof, size_type xdof_size)
313 {
314  // Preconditions:
315 
316  require(schema().state_is_read_accessible());
317  require(schema().dof_id_space(is_table_dof_map()).contains(xdof_id));
318  require(unexecutable("xdof points to buffer of size xdof_size"));
319  require(xdof_size >= schema().size(xdof_id, is_table_dof_map()));
320 
321  // Body:
322 
323  const sec_vd_dof_type& ldof =
324  *reinterpret_cast<const sec_vd_dof_type*>(xdof);
325 
326  if(ldof != _def_val)
327  {
328  // Insert the value in the map;
329  // updates entry if one already exists.
330 
331  _val_map[xdof_id] = ldof;
332  }
333  else
334  {
335  // Value is default,
336  // make sure it's not in the map
337 
338  _val_map.erase(xdof_id);
339  }
340 
341  // Postconditions:
342 
343 
344  // Exit
345 
346  return;
347 }
348 
349 
350 void
352 get_dof(pod_index_type xdisc_id, pod_index_type xfiber_dof_id, void* xdof, size_type xdof_size) const
353 {
354  // Preconditions:
355 
356  require(schema().state_is_read_accessible());
357  require(schema().discretization_id_space().contains(xdisc_id));
358  require(schema().fiber_schema_id_space(false).contains(xfiber_dof_id));
359  require(unexecutable("xdof points to buffer of size xdof_size"));
360  require(xdof_size >= schema().size(xdisc_id, xfiber_dof_id, false));
361 
362  // Body:
363 
364  pod_index_type ldof_id;
366  ordinal(xdisc_id, xfiber_dof_id, ldof_id);
367 
368  get_dof(ldof_id, xdof, xdof_size);
369 
370  // Postconditions:
371 
372 
373  // Exit:
374 
375  return;
376 }
377 
378 void
380 put_dof(pod_index_type xdisc_id, pod_index_type xfiber_dof_id, const void* xdof, size_type xdof_size)
381 {
382  // Preconditions:
383 
384  require(schema().state_is_read_accessible());
385  require(schema().discretization_id_space().contains(xdisc_id));
386  require(schema().fiber_schema_id_space(false).contains(xfiber_dof_id));
387  require(unexecutable("xdof points to buffer of size xdof_size"));
388  require(xdof_size >= schema().size(xdisc_id, xfiber_dof_id, false));
389 
390 
391  // Body:
392 
393  pod_index_type ldof_id;
395  ordinal(xdisc_id, xfiber_dof_id, ldof_id);
396 
397  put_dof(ldof_id, xdof, xdof_size);
398 
399 
400  // Postconditions:
401 
402 
403  // Exit:
404 
405  return;
406 }
407 
408 void
410 get_fiber(pod_index_type xdisc_id, void* xfiber, size_type xfiber_size) const
411 {
412  // Preconditions:
413 
414  require(schema().state_is_read_accessible());
415  require(schema().discretization_id_space().contains(xdisc_id));
416  require(unexecutable("xfiber points to buffer of size xfiber_size"));
417  require(xfiber_size >= schema().fiber_size());
418 
419 
420  // Body:
421 
422  sec_vd_dof_type* lfiber = reinterpret_cast<sec_vd_dof_type*>(xfiber);
423 
424  const ij_product_structure& lproduct =
426 
427  pod_index_type ldof_id;
429 
430  for(pod_index_type i=0; i<lub; ++i, ++lfiber)
431  {
432  lproduct.ordinal(xdisc_id, i, ldof_id);
433  get_dof(ldof_id, lfiber, sizeof(sec_vd_dof_type));
434  }
435 
436 
437  // Postconditions:
438 
439 
440  // Exit:
441 
442  return;
443 }
444 
445 void
447 put_fiber(pod_index_type xdisc_id, const void* xfiber, size_type xfiber_size)
448 {
449  // Preconditions:
450 
451  require(schema().state_is_read_accessible());
452  require(schema().discretization_id_space().contains(xdisc_id));
453  require(unexecutable("xfiber points to buffer of size xfiber_size"));
454  require(xfiber_size >= schema().fiber_size());
455 
456 
457  // Body:
458 
459  const sec_vd_dof_type* lfiber =
460  reinterpret_cast<const sec_vd_dof_type*>(xfiber);
461 
462  const ij_product_structure& lproduct =
464 
465  pod_index_type ldof_id;
467 
468  for(pod_index_type i=0; i<lub; ++i, ++lfiber)
469  {
470  lproduct.ordinal(xdisc_id, i, ldof_id);
471  put_dof(ldof_id, lfiber, sizeof(sec_vd_dof_type));
472  }
473 
474  // Postconditions:
475 
476 
477  // Exit:
478 
479  return;
480 }
481 
482 void
484 get_component(pod_index_type xfiber_dof_id, void* xcomponent, size_type xcomponent_size) const
485 {
486  // Preconditions:
487 
488  require(schema().state_is_read_accessible());
489  require(schema().fiber_schema_id_space(false).contains(xfiber_dof_id));
490  require(unexecutable("xcomponent points to buffer of size xcomponent_size"));
491  require(xcomponent_size >= schema().component_size(xfiber_dof_id));
492 
493 
494  // Body:
495 
496  sec_vd_dof_type* lcomponent = reinterpret_cast<sec_vd_dof_type*>(xcomponent);
497 
498  const ij_product_structure& lproduct =
500 
501  pod_index_type ldof_id;
502  size_type ldisc_ct = schema().discretization_ct();
503 
504  for(pod_index_type i=0; i<ldisc_ct; ++i, ++lcomponent)
505  {
506  lproduct.ordinal(i, xfiber_dof_id, ldof_id);
507  get_dof(ldof_id, lcomponent, sizeof(sec_vd_dof_type));
508  }
509 
510  // Postconditions:
511 
512 
513  // Exit:
514 
515  return;
516 }
517 
518 void
520 put_component(pod_index_type xfiber_dof_id, const void* xcomponent, size_type xcomponent_size)
521 {
522  // Preconditions:
523 
524  require(schema().state_is_read_accessible());
525  require(schema().fiber_schema_id_space(false).contains(xfiber_dof_id));
526  require(unexecutable("xcomponent points to buffer of size xcomponent_size"));
527  require(xcomponent_size >= schema().component_size(xfiber_dof_id));
528 
529 
530  // Body:
531 
532  const sec_vd_dof_type* lcomponent =
533  reinterpret_cast<const sec_vd_dof_type*>(xcomponent);
534 
535  const ij_product_structure& lproduct =
537 
538  pod_index_type ldof_id;
539  size_type ldisc_ct = schema().discretization_ct();
540 
541  for(pod_index_type i=0; i<ldisc_ct; ++i, ++lcomponent)
542  {
543  lproduct.ordinal(i, xfiber_dof_id, ldof_id);
544  put_dof(ldof_id, lcomponent, sizeof(sec_vd_dof_type));
545  }
546 
547 
548  // Postconditions:
549 
550 
551  // Exit:
552 
553  return;
554 }
555 
556 
557 
558 // ===========================================================
559 // END NEW DOF ACCESS FACET
560 // ===========================================================
561 
563 void*
566 {
567  void* result = 0;
568 
569  // Preconditions:
570 
571  // Body:
572 
573  not_implemented();
574 
575  // Postconditions:
576 
577  ensure(invariant());
578 
579  // Exit
580 
581  return result;
582 }
583 
585 const void*
587 dof_tuple() const
588 {
589  void* result = 0;
590 
591  // Preconditions:
592 
593  // Body:
594 
595  not_implemented();
596 
597  // Postconditions:
598 
599  ensure(invariant());
600 
601  // Exit
602 
603  return result;
604 }
605 
607 void
609 get_dof_tuple(void* xbuf, size_t xbuf_len) const
610 {
611  // Preconditions:
612 
613  require(xbuf != 0);
614  require(dof_tuple_ub() <= xbuf_len);
615 
616  // Body:
617 
618  double* lbuf = reinterpret_cast<double*>(xbuf);
619  size_t lbuf_len = xbuf_len/sizeof(double);
620 
622  while(!itr.is_done())
623  {
624  get_dof(itr.pod(), lbuf++, lbuf_len--);
625 
626  itr.next();
627  }
629 
630 
631  // Postconditions:
632 
633  ensure(invariant());
634  ensure(unexecutable(dof tuple copied to xbuf));
635 
636  // Exit
637 
638  return;
639 }
640 
641 
643 void
645 put_dof_tuple(const void* xbuf, size_t xbuf_len)
646 {
647  // Preconditions:
648 
649  require(xbuf != 0);
650  require(dof_tuple_ub() <= xbuf_len);
651 
652  // Body:
653 
655 
656  double* lbuf = reinterpret_cast<double*>(const_cast<void*>(xbuf));
657  size_t lbuf_len = xbuf_len/sizeof(double);
658 
660  while(!itr.is_done())
661  {
662  put_dof(itr.pod(), lbuf++, lbuf_len--);
663 
664  itr.next();
665  }
667 
668  // Postconditions:
669 
670  ensure(invariant());
671  ensure(unexecutable(xbuf copied to dof tuple));
672 
673  // Exit
674 
675  return ;
676 }
677 
679 bool
682 {
684  return false;
685 }
686 
687 // PROTECTED MEMBER FUNCTIONS
688 
689 
690 
691 // void
692 // fiber_bundle::sparse_section_dof_map::
693 // copy_dofs(client_index* xclient_base_ids,
694 // int xclient_base_id_ct,
695 // client_index* xclient_fiber_ids,
696 // int xclient_fiber_id_ct,
697 // void* xbuf,
698 // size_t xbuf_len,
699 // bool to_client)
700 // {
701 // // Preconditions:
702 
703 // // Body:
704 
705 // double* lbuf = static_cast<double*>(xbuf);
706 // size_t lbuf_len = xbuf_len/sizeof(double);
707 
708 // scoped_index lbid, lfid, l_id; // Unscoped.
709 
710 // for(int b=0; b<xclient_base_id_ct; b++)
711 // {
712 // lbid = schema().discretization().client_id_map()->range_id(xclient_base_ids[b]);
713 
714 // for(int f=0; f<xclient_fiber_id_ct; f++)
715 // {
716 // lfid = schema().fiber_schema().row_dof_client_id_map().range_id(xclient_fiber_ids[f]);
717 
718 // l_id = schema().host()->get_index_from_components(lbid, lfid);
719 
720 // if(to_client)
721 // {
722 // get_dof(l_id, true, lbuf++, lbuf_len--);
723 // }
724 // else
725 // {
726 // put_dof(l_id, true, lbuf++, lbuf_len--);
727 // }
728 // }
729 // }
730 
731 // // Postconditions:
732 
733 // ensure(invariant());
734 
735 // // Exit
736 
737 // return;
738 // }
739 
741 void
744 {
745  // Preconditions:
746 
747 
748  // Body:
749 
750  // Nothing to do.
751 
752  // Postconditions:
753 
754 
755  // Exit:
756 
757  return;
758 }
759 
760 bool
761 fiber_bundle::sparse_section_dof_map::
762 make_prototype()
763 {
764  bool result = false;
765 
766  // Preconditions:
767 
768 
769  // Body:
770 
771  // $$SCRIBBLE: need to define SPARSE_SECTION_DOF_TUPLE_ID
772 
773  dof_tuple_type ltype = SPARSE_SECTION_DOF_TUPLE_ID;
774 
776 
777  factory().insert_prototype(lproto);
778  factory().insert_prototype(ltype, lproto);
779 
780  // Postconditions:
781 
782 
783  // Exit:
784 
785  return result;
786 }
virtual bool supports_xfr_opt() const
True if this dof map type supports dof tuple transfer optimization. /.
bool is_table_dof_map() const
True if this is a table dof map.
virtual void get_component(pod_index_type xfiber_dof_id, void *xcomponent, size_type xcomponent_size) const
Sets xcomponent to the component referred to by fiber id xfiber_dof_id.
virtual const std::string & class_name() const
The name of the actual (possibly derived) class of this instance.
const index_space_handle & row_dof_id_space() const
The row dof id space for the schema defined by this.
virtual const abstract_product_structure & product_structure() const =0
The product structure for this id space (const version).
The abstract map from section dof ids to section dof values of heterogeneous type.
virtual pod_type end() const =0
Ending id of this space.
An abstract iterator over the ids of an id space.
pod_type pod() const
The current id in the iteration.
bool state_is_read_accessible() const
True if this is attached and if the state is accessible for read or access control is disabled...
virtual void get_fiber(pod_index_type xdisc_id, void *xfiber, size_type xfiber_size) const
Sets xfiber to the fiber referred to by discretization id xdisc_id.
primitive_value dof(pod_index_type xdof_id) const
The dof referred to by xdof_id.
int version() const
The version of the host of the schema this is defined on.
pod_index_type ordinal(pod_index_type xi, pod_index_type xj, size_type xj_ub)
2-tuple to ordinal conversion.
virtual void put_dof(pod_index_type xdof_id, const void *xdof, size_type xdof_size)
Sets the dof referred to by xdof_id to the value at xdof.
virtual section_space_schema_member & schema()
The schema on which this is allocated (mutable version).
virtual sparse_section_dof_map * copy() const
Virtual copy constructor.
bool is_initialized() const
True if this has been initialized, that is, if the schema has been set and the dof map storage alloca...
STL namespace.
virtual void next()=0
Makes id() the next id in the iteration.
The general, abstract map from dof ids to dof values.
Definition: poset_dof_map.h:59
static dof_map_factory & factory()
The dof map factory.
bool is_done() const
True if iteration is finished.
virtual void release_iterator(index_space_iterator &xitr) const =0
Returns the id space iterator xitr to the iterator pool.
size_t dof_tuple_ub() const
The size of the dof tuple in bytes.
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
static const std::string & static_class_name()
The name of this class.
int discretization_ct() const
The number of members in the intersection of the discretization subposet and the down set of the base...
virtual void put_component(pod_index_type xfiber_dof_id, const void *xcomponent, size_type xcomponent_size)
Sets the component referred to by fiber id xfiber_dof_id to xcomponent.
dof_tuple_type
Identifiers for dof tuple types.
A member of a Cartesian product space; a tuple of attributes (persistent version).
Definition: tuple.h:191
void ordinal(pod_type xi, pod_type xj, pod_type &xordinal) const
2-tuple to ordinal conversion.
virtual index_space_iterator & get_iterator() const =0
Allocates an id space iterator from the iterator pool.
section_dof_map & operator=(const section_dof_map &xother)
Assignment operator.
const index_space_handle & fiber_schema_id_space(bool xis_table_dofs) const
The id space for the dofs in the down set of the fiber schema of this.
A discontiguous tuple, discontiguous fiber representation of the abstract map from section dof ids to...
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
A 2D implementation of abstract_product_structure.
virtual void get_dof(pod_index_type xdof_id, void *xdof, size_type xdof_size) const
Copies the dof referred to by xdof_id into xdof.
virtual sparse_section_dof_map * clone() const
Virtual default constructor.
sparse_section_dof_map & operator=(const sparse_section_dof_map &xother)
Assignment operator.
virtual void get_dof_tuple(void *xbuf, size_t xbuflen) const
Copies the entire dof tuple from internal storage into xbuf.
void insert_prototype(const poset_dof_map *xprototype)
Sets xprototype as the prototype for its client class.
double sec_vd_dof_type
The type of degree of freedom in the section space.
Definition: fiber_bundle.h:78
virtual void * dof_tuple()
The dof tuple (mutable version).
double default_value()
The default value; the value for dofs that are not stored in _val_map.
virtual void put_dof_tuple(const void *xbuf, size_t xbuflen)
Copies the entire dof tuple from xbuf into internal storage.
Namespace for the fiber_bundles component of the sheaf system.
bool is_same_type(const any *other) const
True if other is the same type as this.
Definition: any.cc:79
virtual bool invariant() const
The class invariant.
virtual void allocate_dofs()
Allocates dof storage.
const scoped_index & index() const
The index of this in host() dof tuple table.
virtual void put_fiber(pod_index_type xdisc_id, const void *xfiber, size_type xfiber_size)
Sets the fiber referred to by discretization id xdisc_id to xfiber.
A handle for a poset whose members are numerical representations of sections of a fiber bundle...
Definition: sec_rep_space.h:61