SheafSystem  0.0.0.0
array_field_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 array_field_dof_map
19 
20 #include "SheafSystem/array_field_dof_map.h"
21 #include "SheafSystem/assert_contract.h"
22 
23 #include "SheafSystem/dof_map_factory.h"
24 #include "SheafSystem/discretization_iterator.h"
25 #include "SheafSystem/sec_rep_space.h"
26 
27 using namespace fiber_bundle; // Workaround for MS C++ bug.
28 
29 // PUBLIC MEMBER FUNCTIONS
30 
32 const std::string&
34 class_name() const
35 {
36  // Preconditions:
37 
38  // Body:
39 
40  const string& result = static_class_name();
41 
42  // Postconditions:
43 
44  ensure(!result.empty());
45 
46  // Exit:
47 
48  return result;
49 }
50 
52 const std::string&
55 {
56  // Preconditions:
57 
58  // Body:
59 
60  static const string result("array_field_dof_map");
61 
62  // Postconditions:
63 
64  ensure(!result.empty());
65  ensure(result == "array_field_dof_map");
66 
67  // Exit:
68 
69  return result;
70 }
71 
72 // ===========================================================
73 // CANONICAL FACET
74 // ===========================================================
75 
79  : field_dof_map()
80 {
81 
82  // Preconditions:
83 
84 
85  // Body:
86 
88 
89  _disc_ct = 0;
90  _fiber_ct = 0;
91  _local_ct = 0;
92  _fiber_tuple_size = 0;
93  _dofs = 0;
94  _this_owns_dofs = false;
95 
96  // Postconditions:
97 
98  ensure(invariant());
99 
100  // Exit
101 
102  return;
103 }
104 
108 clone() const
109 {
110  array_field_dof_map* result;
111 
112  // Preconditions:
113 
114 
115  // Body:
116 
117  result = new array_field_dof_map();
118 
119  // Postconditions:
120 
121  ensure(result != 0);
122  ensure(result->is_same_type(this));
123  ensure(postcondition_of(array_field_dof_map()));
124 
125  // Exit:
126 
127  return result;
128 }
129 
130 
131 
135  : field_dof_map(xother)
136 {
137 
138  // Preconditions:
139 
140 
141  // Body:
142 
143  _disc_ct = 0;
144  _fiber_ct = 0;
145  _local_ct = 0;
146  _fiber_tuple_size = 0;
147  _dofs = 0;
148  _this_owns_dofs = false;
149 
150  *this = xother;
151 
152  // Postconditions:
153 
154  ensure(invariant());
155 
156  // Exit
157 
158  return;
159 }
160 
164 copy() const
165 {
166  array_field_dof_map* result;
167 
168  // Preconditions:
169 
170 
171  // Body:
172 
173  result = new array_field_dof_map(*this);
174 
175  // Postconditions:
176 
177  ensure(result != 0);
178  ensure(result->is_same_type(this));
179  ensure(postcondition_of(array_field_dof_map(*this)));
180 
181  // Exit:
182 
183  return result;
184 }
185 
190 {
191 
192  // Preconditions:
193 
194  require(xother.is_initialized());
195 
196  // Body:
197 
198  field_dof_map::operator=(xother);
199 
200  if(_dofs != 0)
201  delete[] _dofs;
202 
203  if(xother._dofs != 0)
204  {
205  // Use same cts and offsets as xother
206 
207  _disc_ct = xother._disc_ct;
208  _fiber_ct = xother._fiber_ct;
209  _local_ct = xother._local_ct;
210  _fiber_tuple_size = xother._fiber_tuple_size;
211 
212  // Allocate and copy the dof storage
213 
214  _this_owns_dofs = xother._this_owns_dofs;
215 
216  if(_this_owns_dofs)
217  {
219  _dofs = new double[dof_tuple_ub()];
220  memcpy(_dofs, xother._dofs, dof_tuple_ub());
221  }
222  else
223  {
224  _dofs = xother._dofs;
225  }
226  }
227  else
228  {
229  _disc_ct = 0;
230  _fiber_ct = 0;
231  _local_ct = 0;
232  _fiber_tuple_size = 0;
233  _dofs = 0;
234  _this_owns_dofs = false;
235  }
236 
237  // Postconditions:
238 
239  ensure(invariant());
240 
241  // Exit
242 
243  return *this;
244 }
245 
246 
250 {
251 
252  // Preconditions:
253 
254 
255  // Body:
256 
257  if(_this_owns_dofs)
258  delete[] _dofs;
259 
260 
261  // Postconditions:
262 
263 }
264 
265 
267 bool
269 invariant() const
270 {
271  bool result = true;
272 
273  // Preconditions:
274 
275  // Body:
276 
277  result = result && (_fiber_tuple_size == _fiber_ct*_local_ct);
278 
280 
281  // Postconditions:
282 
283  // Exit
284 
285  return result;
286 }
287 
288 
289 // ===========================================================
290 // MAP FACET
291 // ===========================================================
292 
295 array_field_dof_map(const sec_rep_space* xhost, void* xdofs, size_t xdofs_ub)
296  : field_dof_map(xhost)
297 {
298 
299  // Preconditions:
300 
301  require(xhost != 0);
302  require(xhost->state_is_read_accessible());
303  require(xdofs != 0 ? xdofs_ub >= xhost->schema().row_dof_tuple_ub(): true);
304  require(unexecutable("if xdofs != 0 it points to buffer of length xdofs_ub"));
305 
306  // Body:
307 
308  // Initialize counts
309 
310 
311  _disc_ct = xhost->discretization().member_ct();
312  _fiber_ct = xhost->df();
313  _local_ct = xhost->multiplicity();
314  _fiber_tuple_size = _fiber_ct*_local_ct;
315 
316 
317  // Initialize dof storage
318 
319  _dofs = static_cast<double*>(xdofs);
320 
321  if(_dofs == 0)
322  {
324  _dofs = new double[dof_tuple_ub()];
325  _this_owns_dofs = true;
326  }
327  else
328  {
329  _this_owns_dofs = false;
330  }
331 
332  // Postconditions:
333 
334  ensure(invariant());
335  ensure(_disc_ct > 0);
336  ensure(_fiber_ct > 0);
337  ensure(_local_ct > 0);
338  ensure(dof_ct() == _disc_ct*_fiber_ct*_local_ct);
339  ensure(dof_tuple_ub() <= xhost->schema().row_dof_tuple_ub());
340  ensure(_dofs != 0);
341  ensure(xdofs != 0 ? _dofs == xdofs : true);
342 
343 }
344 
345 
346 
347 // ===========================================================
348 // NEW DOF ACCESS FACET
349 // ===========================================================
350 
352 void
354 get_dof(pod_index_type xdof_id, void* xdof, size_type xdof_size) const
355 {
356  // Preconditions:
357 
358  require(schema().state_is_read_accessible());
359  require(schema().dof_id_space().contains_range_id(xdof_id));
360  require(unexecutable("xdof points to buffer of size xdof_size"));
361  require(xdof_size >= schema().size(xdof_id));
362 
363  // Body:
364 
365  *reinterpret_cast<sec_vd_dof_type*>(xdof) = *dof_ptr(xdof_id);
366 
367  // Postconditions:
368 
369  // Exit
370 
371  return;
372 }
373 
374 
376 void
378 put_dof(pod_index_type xdof_id, bool xis_poset_id, const void* xdof, size_type xdof_size)
379 {
380  // Preconditions:
381 
382  require(schema().state_is_read_accessible());
383  require(schema().dof_id_space().contains_range_id(xdof_id));
384  require(unexecutable("xdof points to buffer of size xdof_size"));
385  require(xdof_size >= schema().size(xdof_id));
386 
387  // Body:
388 
389  *dof_ptr(xdof_id) = *reinterpret_cast<sec_vd_dof_type*>(xdof);
390 
391  // Postconditions:
392 
393  ensure(unexecutable(internal storage holds dof referred to by xdof_id and xis_poset_id));
394 
395  // Exit
396 
397  return;
398 }
399 
400 
401 void
403 get_dof(pod_index_type xdisc_id, pod_index_type xfiber_dof_id, void* xdof, size_type xdof_size) const
404 {
405  // Preconditions:
406 
407  require(schema().state_is_read_accessible());
408  require(schema().discretization_id_space().contains_range_id(xdisc_id));
409  require(schema().fiber_id_space().contains_range_id(xfiber_dof_id));
410  require(unexecutable("xdof points to buffer of size xdof_size"));
411  require(xdof_size >= schema().size(xdisc_id, xfiber_dof_id));
412 
413 
414  // Body:
415 
416  memcpy(xdof, dof_ptr(xdisc_id, xfiber_dof_id), sizeof(sec_vd_dof_type));
417 
418 
419  // Postconditions:
420 
421 
422  // Exit:
423 
424  return;
425 }
426 
427 void
429 put_dof(pod_index_type xdisc_id, pod_index_type xfiber_dof_id, const void* xdof, size_type xdof_size)
430 {
431  // Preconditions:
432 
433  require(schema().state_is_read_accessible());
434  require(schema().discretization_id_space().contains_range_id(xdisc_id));
435  require(schema().fiber_id_space().contains_range_id(xfiber_dof_id));
436  require(unexecutable("xdof points to buffer of size xdof_size"));
437  require(xdof_size >= schema().size(xdisc_id, xfiber_dof_id));
438 
439 
440  // Body:
441 
442  memcpy(dof_ptr(xdisc_id, xfiber_dof_id), xdof, sizeof(sec_vd_dof_type));
443 
444 
445  // Postconditions:
446 
447 
448  // Exit:
449 
450  return;
451 }
452 
453 void
455 get_fiber(pod_index_type xdisc_id, void* xfiber, size_type xfiber_size) const
456 {
457  // Preconditions:
458 
459  require(schema().state_is_read_accessible());
460  require(schema().discretization_id_space().contains_range_id(xdisc_id));
461  require(unexecutable("xfiber points to buffer of size xfiber_size"));
462  require(xfiber_size >= schema().fiber_size());
463 
464 
465  // Body:
466 
467  memcpy(xfiber, dof_ptr(xdisc_id, 0), schema().fiber_size());
468 
469  // Postconditions:
470 
471 
472  // Exit:
473 
474  return;
475 }
476 
477 void
479 put_fiber(pod_index_type xdisc_id, const void* xfiber, size_type xfiber_size)
480 {
481  // Preconditions:
482 
483  require(schema().state_is_read_accessible());
484  require(schema().discretization_id_space().contains_range_id(xdisc_id));
485  require(unexecutable("xfiber points to buffer of size xfiber_size"));
486  require(xfiber_size >= schema().fiber_size());
487 
488 
489  // Body:
490 
491  memcpy(dof_ptr(xdisc_id, 0), xfiber, schema().fiber_size());
492 
493  // Postconditions:
494 
495 
496  // Exit:
497 
498  return;
499 }
500 
501 void
503 get_component(pod_index_type xfiber_dof_id, void* xcomponent, size_type xcomponent_size) const
504 {
505  // Preconditions:
506 
507  require(schema().state_is_read_accessible());
508  require(schema().fiber_id_space().contains_range_id(xfiber_dof_id));
509  require(unexecutable("xcomponent points to buffer of size xcomponent_size"));
510  require(xcomponent_size >= schema().component_size(xfiber_dof_id));
511 
512 
513  // Body:
514 
515  char* lcomponent = reinterpret_cast<char*>(xcomponent);
516  char* ldof = dof_ptr(0, xfiber_dof_id);
517  size_type ldof_size = schema().size(0, xfiber_dof_id);
518  size_type lfiber_size = schema().fiber_size();
519 
520  for(pod_index_type i=0; i<_discretization_ct; ++i)
521  {
522  memcpy(lcomponent, ldof, ldof_size);
523  lcomponent += ldof_size;
524  ldof += lfiber_size;
525  }
526 
527 
528  // Postconditions:
529 
530 
531  // Exit:
532 
533  return;
534 }
535 
536 void
538 put_component(pod_index_type xfiber_dof_id, const void* xcomponent, size_type xcomponent_size)
539 {
540  // Preconditions:
541 
542  require(schema().state_is_read_accessible());
543  require(schema().fiber_id_space().contains_range_id(xfiber_dof_id));
544  require(unexecutable("xcomponent points to buffer of size xcomponent_size"));
545  require(xcomponent_size >= schema().component_size(xfiber_dof_id));
546 
547 
548  // Body:
549 
550  char* lcomponent = reinterpret_cast<char*>(xcomponent);
551  char* ldof = dof_ptr(0, xfiber_dof_id);
552  size_type ldof_size = schema().size(0, xfiber_dof_id);
553  size_type lfiber_size = schema().fiber_size();
554 
555  for(pod_index_type i=0; i<_discretization_ct; ++i)
556  {
557  memcpy(ldof, lcomponent, ldof_size);
558  lcomponent += ldof_size;
559  ldof += lfiber_size;
560  }
561 
562  // Postconditions:
563 
564 
565  // Exit:
566 
567  return;
568 }
569 
570 // ===========================================================
571 // END NEW DOF ACCESS FACET
572 // ===========================================================
573 
574 
576 void
578 get_dof(const scoped_index& xid, bool xis_poset_id, void* xbuf, size_t xbuf_len) const
579 {
580  // Preconditions:
581 
582  require(xis_poset_id ? schema().contains_row_dof(xid) : true);
583  require(xbuf != 0);
584  require(unexecutable("xbuf_len is large enough to contain the requested dof"));
585  require(unexecutable("xbuf is properly aligned for the type of dof"));
586 
587  // Body:
588 
589  array_field_dof_map* cthis = const_cast<array_field_dof_map*>(this);
590  cthis->copy_dof(xid, xis_poset_id, xbuf, xbuf_len, true);
591 
592  // Postconditions:
593 
594  // Exit
595 
596  return;
597 }
598 
599 
601 void
603 put_dof(const scoped_index& xid, bool xis_poset_id, const void* xbuf, size_t xbuf_len)
604 {
605  // Preconditions:
606 
607  require(xis_poset_id ? schema().contains_row_dof(xid) : true);
608 
609  require(xbuf != 0);
610  require(unexecutable("xbuf_len is large enough to contain the requested dof"));
611  require(unexecutable("xbuf is properly aligned for the type of dof"));
612 
614  require(unexecutable("xbuf must be aligned for the given data type"));
615 
616  // Body:
617 
618  copy_dof(xid, xis_poset_id, const_cast<void*>(xbuf), xbuf_len, false);
619 
620  // Postconditions:
621 
622  ensure(unexecutable(internal storage holds dof referred to by xid and xis_poset_id));
623 
624  // Exit
625 
626  return;
627 }
628 
629 
630 
632 void
634 get_dofs(const client_index* xclient_ids, int xclient_id_ct, void* xbuf, size_t xbuf_len) const
635 {
636  // Preconditions:
637 
638  require(xclient_ids != 0);
639  require(xclient_id_ct > 0);
640  require(unexecutable(xclient_ids points to buffer of length xclient_id_ct));
641  require(unexecutable(xclient_ids are valid client ids));
642  require(xbuf != 0);
643  require(unexecutable(xbuf points to buffer of length xbuf_len));
644  require(unexecutable(xbuf_len is large enough to hold the dofs referred to by xclient_ids));
646  require(unexecutable("xbuf must be aligned for all data types"));
647 
648  // Body:
649 
650  not_implemented();
651 
652  // Postconditions:
653 
654  ensure(unexecutable(xbuf holds dofs referred to by xclient_ids));
655 
656  // Exit
657 
658  return;
659 }
660 
661 
663 void
665 put_dofs(const client_index* xclient_ids, int xclient_id_ct, const void* xbuf, size_t xbuf_len)
666 {
667  // Preconditions:
668 
669  require(xclient_ids != 0);
670  require(xclient_id_ct > 0);
671  require(unexecutable(xclient_ids points to buffer of length xclient_id_ct));
672  require(unexecutable(xclient_ids are valid client ids));
673  require(xbuf != 0);
674  require(unexecutable(xbuf points to buffer of length xbuf_len));
675  require(unexecutable(xbuf_len is large enough to hold the dofs referred to by xclient_ids));
677  require(unexecutable("xbuf must be aligned for all data types"));
678 
679  // Body:
680 
681  not_implemented();
682 
683  // Postconditions:
684 
685  ensure(unexecutable(internal storage holds dofs referred to by xclient_ids));
686 
687  // Exit
688 
689  return;
690 }
691 
692 
693 
695 void
697 get_dof(const scoped_index& xbase_id,
698  const scoped_index& xfiber_id,
699  const scoped_index& xmult_id,
700  bool xis_poset_id, void* xbuf, size_t xbuf_len) const
701 {
702  // Preconditions:
703 
704  require(unexecutable(xbase_id is a valid client id));
705  require(unexecutable(xfiber_id is a valid client id));
706  require(unexecutable(0 <= xmult_id && xmult_id < multiplicity));
707  require(xbuf != 0);
708  require(unexecutable(xbuf points to buffer of length xbuf_len));
709  require(unexecutable(xbuf_len is large enough to hold the dofs referred to by client ids));
710 
711  // Body:
712 
713  array_field_dof_map* cthis = const_cast<array_field_dof_map*>(this);
714  cthis->copy_dof(xbase_id, xfiber_id, xmult_id, xis_poset_id, xbuf, xbuf_len, true);
715 
716  // Postconditions:
717 
718  ensure(unexecutable(xbuf holds dof referred to by xids));
719 
720  // Exit
721 
722  return;
723 }
724 
725 
727 void
729 put_dof(const scoped_index& xbase_id,
730  const scoped_index& xfiber_id,
731  const scoped_index& xmult_id,
732  bool xis_poset_id, const void* xbuf, size_t xbuf_len)
733 {
734  // Preconditions:
735 
736  require(unexecutable(xbase_id is a valid client id));
737  require(unexecutable(xfiber_id is a valid client id));
738  require(unexecutable(0 <= xmult_id && xmult_id < multiplicity));
739  require(xbuf != 0);
740  require(unexecutable(xbuf points to buffer of length xbuf_len));
741  require(unexecutable(xbuf_len is large enough to hold the dofs referred to by client ids));
742 
743  // Body:
744 
745  copy_dof(xbase_id, xfiber_id, xmult_id, xis_poset_id, const_cast<void*>(xbuf), xbuf_len, false);
746 
747  // Postconditions:
748 
749  ensure(unexecutable(internal storage holds dof referred to by xids));
750 
751  // Exit
752 
753  return;
754 }
755 
757 void
759 get_dofs(const client_index* xclient_base_ids, int xclient_base_id_ct,
760  const client_index* xclient_fiber_ids, int xclient_fiber_id_ct,
761  void* xbuf, size_t xbuf_len) const
762 {
763  // Preconditions:
764 
765  require(xclient_base_ids != 0);
766  require(xclient_base_id_ct > 0);
767  require(unexecutable(xclient_base_ids points to buffer of length xclient_base_id_ct));
768  require(unexecutable(xclient_base_ids are valid client ids));
769  require(xclient_fiber_ids != 0);
770  require(xclient_fiber_id_ct > 0);
771  require(unexecutable(xclient_fiber_ids points to buffer of length xclient_fiber_id_ct));
772  require(unexecutable(xclient_fiber_ids are valid client ids));
773  require(xbuf != 0);
774  require(unexecutable(xbuf points to buffer of length xbuf_len));
775  require(unexecutable(xbuf_len is large enough to hold the dofs referred to by client ids));
776 
777  // Body:
778 
779  array_field_dof_map* cthis = const_cast<array_field_dof_map*>(this);
780  cthis->copy_dofs(xclient_base_ids, xclient_base_id_ct, xclient_fiber_ids,
781  xclient_fiber_id_ct, xbuf, xbuf_len, true);
782 
783  // Postconditions:
784 
785  ensure(invariant());
786  ensure(unexecutable(xbuf holds dofs referred to by xclient_ids));
787 
788  // Exit
789 
790  return;
791 }
792 
793 
795 void
797 put_dofs(const client_index* xclient_base_ids, int xclient_base_id_ct,
798  const client_index* xclient_fiber_ids, int xclient_fiber_id_ct,
799  const void* xbuf, size_t xbuf_len)
800 {
801  // Preconditions:
802 
803  require(xclient_base_ids != 0);
804  require(xclient_base_id_ct > 0);
805  require(unexecutable(xclient_base_ids points to buffer of length xclient_base_id_ct));
806  require(unexecutable(xclient_base_ids are valid client ids));
807  require(xclient_fiber_ids != 0);
808  require(xclient_fiber_id_ct > 0);
809  require(unexecutable(xclient_fiber_ids points to buffer of length xclient_fiber_id_ct));
810  require(unexecutable(xclient_fiber_ids are valid client ids));
811  require(xbuf != 0);
812  require(unexecutable(xbuf points to buffer of length xbuf_len));
813  require(unexecutable(xbuf_len is large enough to hold the dofs referred to by xclient_ids));
814 
815  // Body:
816 
817  copy_dofs(xclient_base_ids, xclient_base_id_ct, xclient_fiber_ids,
818  xclient_fiber_id_ct, const_cast<void*>(xbuf), xbuf_len, false);
819 
820  // Postconditions:
821 
822  ensure(invariant());
823  ensure(unexecutable(internal storage holds dofs referred to by xclient_ids));
824 
825  // Exit
826 
827  return;
828 }
829 
831 void
834  bool xis_poset_id,
835  void* xbuf,
836  size_t xbuf_len) const
837 {
838  // Preconditions:
839 
840  require(xbuf != 0);
841  require(unexecutable(xbuf points to buffer of length xbuf_len));
842  require(xbuf_len >= schema().fiber_schema().row_dof_tuple_ub());
843  require(xis_poset_id ? xdisc_id.in_scope() : true);
844 
845  // Body:
846 
847  scoped_index::pod_type ldisc_id;
848  if(xis_poset_id)
849  {
850  ldisc_id = schema().disc_seq_id_map().client_id(xdisc_id.hub_pod());
851  }
852  else
853  {
854  ldisc_id = xdisc_id;
855  }
856 
857 
858  size_t ltuple_size = schema().fiber_schema().row_dof_tuple_ub();
859 
860  char* ldof_base = reinterpret_cast<char*>(_dofs) + ldisc_id*ltuple_size;
861 
862  memcpy(xbuf, ldof_base, ltuple_size);
863 
864  // Postconditions:
865 
866  // Exit
867 
868  return;
869 }
870 
872 void
875  bool xis_poset_id,
876  const void* xbuf,
877  size_t xbuf_len)
878 {
879  // Preconditions:
880 
881  require(xbuf != 0);
882  require(unexecutable(xbuf points to buffer of length xbuf_len));
883  require(xbuf_len >= schema().fiber_schema().row_dof_tuple_ub());
884  require(xis_poset_id ? xdisc_id.in_scope() : true);
885 
886  // Body:
887 
888  scoped_index::pod_type ldisc_id;
889  if(xis_poset_id)
890  {
891  ldisc_id = schema().disc_seq_id_map().client_id(xdisc_id.hub_pod());
892  }
893  else
894  {
895  ldisc_id = xdisc_id;
896  }
897 
898  size_t lfiber_dof_ct = schema().fiber_schema().row_dof_ct();
899  size_t ltuple_size = sizeof(double)*lfiber_dof_ct;
900 
901  size_t lindex = ldisc_id*lfiber_dof_ct;
902 
903  reserve(lindex);
904 
905  char* ldof_base = reinterpret_cast<char*>(_dofs) + lindex*sizeof(double);
906 
907  memcpy(ldof_base, xbuf, ltuple_size);
908 
909  // Postconditions:
910 
911  // Exit
912 
913  return;
914 }
915 
917 void
920  size_t xbuf_len,
921  const scoped_index& xcomp_id,
922  const scoped_index* xdisc_ids,
923  size_type xdisc_ids_ct) const
924 {
925  // Preconditions:
926 
927  require(is_initialized());
928  require(xbuf != 0);
929  require(unexecutable(xbuf points to buffer of length xbuf_len));
930  require(unexecutable("xbuf_len is large enough for the requested dofs"));
931  require(schema().fiber_schema().contains_row_dof(xcomp_id));
932  require(xdisc_ids == 0 ? xdisc_ids_ct == 0 : true);
933  require_for_all(i, 0, xdisc_ids_ct, schema().discretization().contains_member(xdisc_ids[i]));
934 
935  // Body:
936 
937  copy_component_dofs(xbuf,
938  xbuf_len,
939  xcomp_id,
940  xdisc_ids,
941  xdisc_ids_ct,
942  true);
943 
944  // Postconditions:
945 
946  // Exit
947 
948  return;
949 }
950 
951 
953 void
955 put_component_dofs(const void* xbuf,
956  size_t xbuf_len,
957  const scoped_index& xcomp_id,
958  const scoped_index* xdisc_ids,
959  size_type xdisc_ids_ct)
960 {
961  // Preconditions:
962 
963  require(is_initialized());
964  require(xbuf != 0);
965  require(unexecutable(xbuf points to buffer of length xbuf_len));
966  require(unexecutable("xbuf_len is large enough for the requested dofs"));
967  require(schema().fiber_schema().contains_row_dof(xcomp_id));
968  require(xdisc_ids == 0 ? xdisc_ids_ct == 0 : true);
969  require_for_all(i, 0, xdisc_ids_ct, schema().discretization().contains_member(xdisc_ids[i]));
970 
971  // Body:
972 
973  copy_component_dofs(const_cast<void*>(xbuf),
974  xbuf_len,
975  xcomp_id,
976  xdisc_ids,
977  xdisc_ids_ct,
978  false);
979 
980  // Postconditions:
981 
982  // Exit
983 
984  return;
985 }
986 
988 void
991  size_t xbuf_len,
992  const client_index& xcomp_id,
993  const id_map* xcomp_client_id_map,
994  const client_index* xdisc_ids,
995  size_type xdisc_ids_ct,
996  const id_map* xdisc_client_id_map) const
997 {
998  // Preconditions:
999 
1000  require(is_initialized());
1001  require(xbuf != 0);
1002  require(unexecutable(xbuf points to buffer of length xbuf_len));
1003  require(unexecutable("xbuf_len is large enough for the requested dofs"));
1004  require(xcomp_client_id_map != 0);
1005  require(schema().fiber_schema().contains_row_dof(scoped_index(xcomp_id, xcomp_client_id_map)));
1006  require(xdisc_ids == 0 ? xdisc_ids_ct == 0 : true);
1007  require(xdisc_ids_ct != 0 ? xdisc_client_id_map != 0 : true);
1008  require_for_all(i, 0, xdisc_ids_ct, schema().discretization().contains_member(scoped_index(xdisc_ids[i], xdisc_client_id_map)));
1009 
1010 
1011  // Body:
1012 
1013  copy_component_dofs(xbuf,
1014  xbuf_len,
1015  xcomp_id,
1016  xcomp_client_id_map,
1017  xdisc_ids,
1018  xdisc_ids_ct,
1019  xdisc_client_id_map,
1020  true);
1021 
1022  // Postconditions:
1023 
1024  // Exit
1025 
1026  return;
1027 }
1028 
1030 void
1032 put_component_dofs(const void* xbuf,
1033  size_t xbuf_len,
1034  const client_index& xcomp_id,
1035  const id_map* xcomp_client_id_map,
1036  const client_index* xdisc_ids,
1037  size_type xdisc_ids_ct,
1038  const id_map* xdisc_client_id_map)
1039 {
1040  // Preconditions:
1041 
1042  require(is_initialized());
1043  require(xbuf != 0);
1044  require(unexecutable(xbuf points to buffer of length xbuf_len));
1045  require(unexecutable("xbuf_len is large enough for the requested dofs"));
1046  require(xcomp_client_id_map != 0);
1047  require(schema().fiber_schema().contains_row_dof(scoped_index(xcomp_id, xcomp_client_id_map)));
1048  require(xdisc_ids == 0 ? xdisc_ids_ct == 0 : true);
1049  require(xdisc_ids_ct != 0 ? xdisc_client_id_map != 0 : true);
1050  require_for_all(i, 0, xdisc_ids_ct, schema().discretization().contains_member(scoped_index(xdisc_ids[i], xdisc_client_id_map)));
1051 
1052 
1053  // Body:
1054 
1055  copy_component_dofs(const_cast<void*>(xbuf),
1056  xbuf_len,
1057  xcomp_id,
1058  xcomp_client_id_map,
1059  xdisc_ids,
1060  xdisc_ids_ct,
1061  xdisc_client_id_map,
1062  false);
1063 
1064  // Postconditions:
1065 
1066  // Exit
1067 
1068  return;
1069 }
1070 
1072 void*
1075 {
1076  void* result;
1077 
1078  // Preconditions:
1079 
1080  // Body:
1081 
1082  result = _dofs;
1083 
1084  // Postconditions:
1085 
1086  ensure(invariant());
1087 
1088  // Exit
1089 
1090  return result;
1091 }
1092 
1094 const void*
1096 dof_tuple() const
1097 {
1098  const void* result;
1099 
1100  // Preconditions:
1101 
1102  // Body:
1103 
1104  result = _dofs;
1105 
1106  // Postconditions:
1107 
1108  ensure(invariant());
1109 
1110  // Exit
1111 
1112  return result;
1113 }
1114 
1116 void
1118 get_dof_tuple(void* xbuf, size_t xbuflen) const
1119 {
1120  // Preconditions:
1121 
1122  require(xbuf != 0);
1123  require(dof_tuple_ub() <= xbuflen);
1124 
1125  // Body:
1126 
1127  memcpy(xbuf, static_cast<void*>(_dofs), dof_tuple_ub());
1128 
1129  // Postconditions:
1130 
1131  ensure(invariant());
1132  ensure(unexecutable(dof tuple copied to xbuf));
1133 
1134  // Exit
1135 
1136  return;
1137 }
1138 
1139 
1141 void
1143 put_dof_tuple(const void* xbuf, size_t xbuflen)
1144 {
1145  // Preconditions:
1146 
1147  require(xbuf != 0);
1148  require(dof_tuple_ub() <= xbuflen);
1149 
1150  // Body:
1151 
1152  memcpy(static_cast<void*>(_dofs), xbuf, dof_tuple_ub());
1153 
1154  // Postconditions:
1155 
1156  ensure(invariant());
1157  ensure(unexecutable(xbuf copied to dof tuple));
1158 
1159  // Exit
1160 
1161  return ;
1162 }
1163 
1164 
1165 // PROTECTED MEMBER FUNCTIONS
1166 
1167 void
1170 {
1171 
1172  // Preconditions:
1173 
1174  // Body:
1175 
1176  _local_ct = host()->multiplicity();
1177 
1178  // Initialize dof storage
1180 
1181  _dofs = new double[_dof_tuple_ub];
1182  _this_owns_dofs = true;
1183 
1184 
1185  // Postconditions:
1186 
1187  // Exit:
1188 
1189  return;
1190 }
1191 
1192 bool
1193 fiber_bundle::array_field_dof_map::
1194 _has_prototype = make_prototype();
1195 
1197 bool
1198 fiber_bundle::array_field_dof_map::
1199 make_prototype()
1200 {
1201  bool result = false;
1202 
1203  // Preconditions:
1204 
1205 
1206  // Body:
1207 
1208  dof_tuple_type ltype = ARRAY_FIELD_DOF_TUPLE_ID;
1209 
1210  poset_dof_map* lproto = new array_field_dof_map;
1211 
1212  factory().insert_prototype(lproto);
1213  factory().insert_prototype(ltype, lproto);
1214 
1215  // Postconditions:
1216 
1217 
1218  // Exit:
1219 
1220  return result;
1221 }
1222 
1224 void
1225 fiber_bundle::array_field_dof_map::
1226 reserve(int xindex)
1227 {
1228 
1229  // Preconditions:
1230 
1231  require(xindex >= 0);
1232  require(_dofs != 0);
1233  require(_this_owns_dofs);
1234 
1235  // Body:
1236 
1237  define_old_variable(int old_dof_tuple_ub = _dof_tuple_ub);
1238 
1239  if(xindex >= _dof_tuple_ub)
1240  {
1241  size_t new_ub = _dof_tuple_ub*2;
1242  if(new_ub <= xindex)
1243  new_ub = xindex + 1;
1244 
1245  // Allocate a new dofs array
1246 
1247  double* new_dofs = new double[new_ub];
1248 
1249  // Copy the old contents to the new array
1250  // and delete the old array.
1251 
1252  memcpy(new_dofs, _dofs, sizeof(double)*_dof_tuple_ub);
1253  delete [] _dofs;
1254 
1255  // Update base and bound.
1256 
1257  _dofs = new_dofs;
1258  _dof_tuple_ub = new_ub;
1259  }
1260 
1261  // Postconditions:
1262 
1263  ensure(invariant());
1264  ensure(_dof_tuple_ub >= old_dof_tuple_ub);
1265  ensure(_dof_tuple_ub > xindex);
1266 
1267  // Exit:
1268 
1269  return;
1270 }
array_field_dof_map & operator=(const array_field_dof_map &xother)
Assignment operator.
virtual array_field_dof_map * clone() const
Virtual default constructor.
virtual void put_dof_tuple(const void *xbuf, size_t xbuflen)
Copies the entire dof tuple from xbuf into internal storage.
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.
void length(const S &x0, SR &xresult, bool xauto_access)
Definition: sec_ed.impl.h:181
bool in_scope() const
True if and only if scope() contains an entry for pod().
Definition: scoped_index.h:584
virtual void get_discretization_dofs(const scoped_index &xdisc_id, bool xis_poset_id, void *xbuf, size_t xbuf_len) const
Copys the dofs associated with the discretization member identified by xdisc_id into the buffer of le...
virtual ~array_field_dof_map()
Destructor.
schema_poset_member & fiber_schema()
The fiber schema component of this (mutable version).
virtual const std::string & class_name() const
The name of the actual (possibly derived) class of this instance.
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 size_t size() const =0
The number of bytes in this dof.
OBSOLETE: Use array_sec_vd_dof_map or sparse_section_dof_map. The abstract map from section_space_sch...
Definition: field_dof_map.h:48
primitive_value dof(pod_index_type xdof_id) const
The dof referred to by xdof_id.
virtual void put_dofs(const client_index *xclient_ids, int xclient_id_ct, const void *xbuf, size_t xbuf_len)
Copies the values of the dofs referred to by the xclient_id_ct client ids in xclient_ids from the buf...
virtual section_space_schema_member & schema()
The schema on which this is allocated (mutable version).
virtual void allocate_dofs()
Allocates dof storage.
virtual void put_dof(pod_index_type xdof_id, bool xis_poset_id, const void *xdof, size_type xdof_size)
Sets the dof referred to by xdof_id to the value at xdof.
bool is_initialized() const
True if this has been initialized, that is, if the schema has been set and the dof map storage alloca...
int df() const
The dimension of the fiber space.
The general, abstract map from dof ids to dof values.
Definition: poset_dof_map.h:59
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.
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.
size_t _dof_tuple_ub
The size of the dof tuple.
virtual section_space_schema_member & schema()
The schema for this poset (mutable version)
static dof_map_factory & factory()
The dof map factory.
virtual void get_dofs(const client_index *xclient_ids, int xclient_id_ct, void *xbuf, size_t xbuf_len) const
Copies the values of the dofs referred to by the xclient_id_ct client ids in xclient_ids into the buf...
virtual void put_discretization_dofs(const scoped_index &xdisc_id, bool xis_poset_id, const void *xbuf, size_t xbuf_len)
Copys the dofs associated with the discretization member identified by xdisc_id from the buffer of le...
subposet & discretization()
The subposet on which the degrees of freedom are defined (mutable version).
A contiguous tuple, contiguous fiber representation of the abstract map from section_space_schema_mem...
size_t dof_tuple_ub() const
The size of the dof tuple in bytes.
An index within the external ("client") scope of a given id space.
Definition: scoped_index.h:116
virtual void get_component_dofs(void *xbuf, size_t xbuf_len, const scoped_index &xcomp_id, const scoped_index *xdisc_ids=0, size_type xdisc_ids_ct=0) const
Copys the dofs associated with the fiber component identified by xcomp_id from internal storage into ...
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
dof_tuple_type
Identifiers for dof tuple types.
static const std::string & static_class_name()
The name of this class.
static int row_dof_ct(const namespace_poset &xns, const poset_path &xpath, bool xauto_access=true)
The number of row dofs defined by the schema specified by xns and xpath. Synonym for dof_ct(xns...
A member of a Cartesian product space; a tuple of attributes (persistent version).
Definition: tuple.h:191
int member_ct() const
The number of members of this subposet.
Definition: subposet.cc:887
virtual void put_component_dofs(const void *xbuf, size_t xbuf_len, const scoped_index &xcomp_id, const scoped_index *xdisc_ids=0, size_type xdisc_ids_ct=0)
Copys the dofs associated with the fiber component identified by xcomp_id from buffer xbuf of length ...
int dof_ct() const
The number of dofs in this map.
int multiplicity() const
The number of degrees of freedom associated with each member of the discretization.
size_type fiber_size() const
The number of bytes in the fiber.
size_t row_dof_tuple_ub() const
The size in bytes of the row dof tuple defined by this schema. Synonym for dof_tuple_ub(false).
pod_index_type pod_type
The "plain old data" storage type for this.
Definition: scoped_index.h:128
virtual array_field_dof_map * copy() const
Virtual copy constructor.
virtual void get_dof_tuple(void *xbuf, size_t xbuflen) const
Copies the entire dof tuple from internal storage into xbuf.
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
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.
array_field_dof_map()
Default constructor.
field_dof_map & operator=(const field_dof_map &xother)
Assignment operator.
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 get_dof(pod_index_type xdof_id, void *xdof, size_type xdof_size) const
Copies the dof referred to by xdof_id into xdof.
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 void * dof_tuple()
The dof tuple (mutable version).
virtual bool invariant() const
The class invariant.
virtual sec_rep_space * host() const
The poset which hosts member()
pod_type hub_pod() const
The pod value of this mapped to the unglued hub id space.
Definition: scoped_index.h:710
A handle for a poset whose members are numerical representations of sections of a fiber bundle...
Definition: sec_rep_space.h:61