Reference documentation for deal.II version 9.0.0
dof_faces.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2006 - 2018 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE at
12 // the top level of the deal.II distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_hp_dof_faces_h
17 #define dealii_hp_dof_faces_h
18 
19 
20 #include <deal.II/base/config.h>
21 #include <deal.II/hp/fe_collection.h>
22 
23 #include <vector>
24 
25 DEAL_II_NAMESPACE_OPEN
26 
27 namespace internal
28 {
29  namespace hp
30  {
93  template <int structdim>
95  {
96  public:
104  std::vector<unsigned int> dof_offsets;
105 
110  std::vector<types::global_dof_index> dofs;
111 
124  template <int dim, int spacedim>
125  void
126  set_dof_index (const ::hp::DoFHandler<dim,spacedim> &dof_handler,
127  const unsigned int obj_index,
128  const unsigned int fe_index,
129  const unsigned int local_index,
130  const types::global_dof_index global_index,
131  const unsigned int obj_level);
132 
144  template <int dim, int spacedim>
146  get_dof_index (const ::hp::DoFHandler<dim,spacedim> &dof_handler,
147  const unsigned int obj_index,
148  const unsigned int fe_index,
149  const unsigned int local_index,
150  const unsigned int obj_level) const;
151 
163  template <int dim, int spacedim>
164  unsigned int
165  n_active_fe_indices (const ::hp::DoFHandler<dim,spacedim> &dof_handler,
166  const unsigned int obj_index) const;
167 
171  template <int dim, int spacedim>
173  nth_active_fe_index (const ::hp::DoFHandler<dim,spacedim> &dof_handler,
174  const unsigned int obj_level,
175  const unsigned int obj_index,
176  const unsigned int n) const;
177 
182  template <int dim, int spacedim>
183  bool
184  fe_index_is_active (const ::hp::DoFHandler<dim,spacedim> &dof_handler,
185  const unsigned int obj_index,
186  const unsigned int fe_index,
187  const unsigned int obj_level) const;
188 
193  std::size_t memory_consumption () const;
194 
199  template <class Archive>
200  void serialize(Archive &ar,
201  const unsigned int version);
202  };
203 
204 
205 
233  template <int dim>
235 
236 
244  template <>
246  {
247  public:
252  std::size_t memory_consumption () const;
253 
258  template <class Archive>
259  void serialize(Archive &ar,
260  const unsigned int version);
261  };
262 
270  template <>
272  {
273  public:
278 
283  std::size_t memory_consumption () const;
284 
289  template <class Archive>
290  void serialize(Archive &ar,
291  const unsigned int version);
292  };
293 
301  template <>
303  {
304  public:
309 
314 
319  std::size_t memory_consumption () const;
320 
325  template <class Archive>
326  void serialize(Archive &ar,
327  const unsigned int version);
328  };
329 
330 
331  // --------------------- inline and template functions ------------------
332  template <class Archive>
334  const unsigned int)
335  {}
336 
337 
338  template <class Archive>
340  const unsigned int)
341  {
342  ar &lines;
343  }
344 
345 
346  template <class Archive>
348  const unsigned int)
349  {
350  ar &lines &quads;
351  }
352 
353  template <int structdim>
354  template <int dim, int spacedim>
355  inline
358  get_dof_index (const ::hp::DoFHandler<dim,spacedim> &dof_handler,
359  const unsigned int obj_index,
360  const unsigned int fe_index,
361  const unsigned int local_index,
362  const unsigned int /*obj_level*/) const
363  {
365  ExcMessage ("You need to specify a FE index when working "
366  "with hp DoFHandlers"));
367  Assert (fe_index < dof_handler.get_fe_collection().size(),
368  ExcIndexRange (fe_index, 0, dof_handler.get_fe_collection().size()));
369  Assert (local_index <
370  dof_handler.get_fe(fe_index).template n_dofs_per_object<structdim>(),
371  ExcIndexRange(local_index, 0,
372  dof_handler.get_fe(fe_index)
373  .template n_dofs_per_object<structdim>()));
374  Assert (obj_index < dof_offsets.size(),
375  ExcIndexRange (obj_index, 0, dof_offsets.size()));
376 
377  // make sure we are on an
378  // object for which DoFs have
379  // been allocated at all
380  Assert (dof_offsets[obj_index] != numbers::invalid_unsigned_int,
381  ExcMessage ("You are trying to access degree of freedom "
382  "information for an object on which no such "
383  "information is available"));
384 
385  Assert (structdim<dim, ExcMessage ("This object can not be used for cells."));
386 
387  // there may be multiple finite elements associated with
388  // this object. hop along the list of index sets until we
389  // find the one with the correct fe_index, and then poke
390  // into that part. trigger an exception if we can't find a
391  // set for this particular fe_index
392  const types::global_dof_index starting_offset = dof_offsets[obj_index];
393  const types::global_dof_index *pointer = &dofs[starting_offset];
394  while (true)
395  {
396  Assert (*pointer != numbers::invalid_dof_index,
397  ExcInternalError());
398  if (*pointer == fe_index)
399  return *(pointer + 1 + local_index);
400  else
401  pointer += static_cast<types::global_dof_index>(
402  dof_handler.get_fe(*pointer)
403  .template n_dofs_per_object<structdim>() + 1);
404  }
405  }
406 
407 
408 
409  template <int structdim>
410  template <int dim, int spacedim>
411  inline
412  void
414  set_dof_index (const ::hp::DoFHandler<dim,spacedim> &dof_handler,
415  const unsigned int obj_index,
416  const unsigned int fe_index,
417  const unsigned int local_index,
418  const types::global_dof_index global_index,
419  const unsigned int /*obj_level*/)
420  {
422  ExcMessage ("You need to specify a FE index when working "
423  "with hp DoFHandlers"));
424  Assert (fe_index < dof_handler.get_fe_collection().size(),
425  ExcIndexRange (fe_index, 0, dof_handler.get_fe_collection().size()));
426  Assert (local_index <
427  dof_handler.get_fe(fe_index).template n_dofs_per_object<structdim>(),
428  ExcIndexRange(local_index, 0,
429  dof_handler.get_fe(fe_index)
430  .template n_dofs_per_object<structdim>()));
431  Assert (obj_index < dof_offsets.size(),
432  ExcIndexRange (obj_index, 0, dof_offsets.size()));
433 
434  // make sure we are on an
435  // object for which DoFs have
436  // been allocated at all
437  Assert (dof_offsets[obj_index] != numbers::invalid_unsigned_int,
438  ExcMessage ("You are trying to access degree of freedom "
439  "information for an object on which no such "
440  "information is available"));
441 
442  Assert (structdim<dim, ExcMessage ("This object can not be used for cells."));
443 
444  // there may be multiple finite elements associated with
445  // this object. hop along the list of index sets until we
446  // find the one with the correct fe_index, and then poke
447  // into that part. trigger an exception if we can't find a
448  // set for this particular fe_index
449  const types::global_dof_index starting_offset = dof_offsets[obj_index];
450  types::global_dof_index *pointer = &dofs[starting_offset];
451  while (true)
452  {
453  Assert (*pointer != numbers::invalid_dof_index,
454  ExcInternalError());
455  if (*pointer == fe_index)
456  {
457  *(pointer + 1 + local_index) = global_index;
458  return;
459  }
460  else
461  pointer += dof_handler.get_fe(*pointer)
462  .template n_dofs_per_object<structdim>() + 1;
463  }
464  }
465 
466 
467 
468  template <int structdim>
469  template <int dim, int spacedim>
470  inline
471  unsigned int
473  n_active_fe_indices (const ::hp::DoFHandler<dim,spacedim> &dof_handler,
474  const unsigned int obj_index) const
475  {
476  Assert (obj_index < dof_offsets.size(),
477  ExcIndexRange (obj_index, 0, dof_offsets.size()));
478 
479  // make sure we are on an
480  // object for which DoFs have
481  // been allocated at all
482  if (dof_offsets[obj_index] == numbers::invalid_unsigned_int)
483  return 0;
484 
485  Assert (structdim<dim, ExcMessage ("This object can not be used for cells."));
486 
487  // there may be multiple finite elements associated with this
488  // object. hop along the list of index sets until we find the
489  // one with the correct fe_index, and then poke into that
490  // part. trigger an exception if we can't find a set for this
491  // particular fe_index
492  const unsigned int starting_offset = dof_offsets[obj_index];
493  const types::global_dof_index *pointer = &dofs[starting_offset];
494  unsigned int counter = 0;
495  while (true)
496  {
497  if (*pointer == numbers::invalid_dof_index)
498  // end of list reached
499  return counter;
500  else
501  {
502  ++counter;
503  pointer += dof_handler.get_fe(*pointer)
504  .template n_dofs_per_object<structdim>() + 1;
505  }
506  }
507  }
508 
509 
510 
511  template <int structdim>
512  template <int dim, int spacedim>
513  inline
516  nth_active_fe_index (const ::hp::DoFHandler<dim,spacedim> &dof_handler,
517  const unsigned int /*obj_level*/,
518  const unsigned int obj_index,
519  const unsigned int n) const
520  {
521  Assert (obj_index < dof_offsets.size(),
522  ExcIndexRange (obj_index, 0, dof_offsets.size()));
523 
524  // make sure we are on an
525  // object for which DoFs have
526  // been allocated at all
527  Assert (dof_offsets[obj_index] != numbers::invalid_unsigned_int,
528  ExcMessage ("You are trying to access degree of freedom "
529  "information for an object on which no such "
530  "information is available"));
531 
532  Assert (structdim<dim, ExcMessage ("This object can not be used for cells."));
533 
534  Assert (n < n_active_fe_indices(dof_handler, obj_index),
535  ExcIndexRange (n, 0,
536  n_active_fe_indices(dof_handler, obj_index)));
537 
538  // there may be multiple finite elements associated with
539  // this object. hop along the list of index sets until we
540  // find the one with the correct fe_index, and then poke
541  // into that part. trigger an exception if we can't find a
542  // set for this particular fe_index
543  const unsigned int starting_offset = dof_offsets[obj_index];
544  const types::global_dof_index *pointer = &dofs[starting_offset];
545  unsigned int counter = 0;
546  while (true)
547  {
548  Assert (*pointer != numbers::invalid_dof_index,
549  ExcInternalError());
550 
551  const unsigned int fe_index = *pointer;
552 
553  Assert (fe_index < dof_handler.get_fe_collection().size(),
554  ExcInternalError());
555 
556  if (counter == n)
557  return fe_index;
558 
559  ++counter;
560  pointer += dof_handler.get_fe(fe_index)
561  .template n_dofs_per_object<structdim>() + 1;
562  }
563  }
564 
565 
566 
567  template <int structdim>
568  template <int dim, int spacedim>
569  inline
570  bool
572  fe_index_is_active (const ::hp::DoFHandler<dim,spacedim> &dof_handler,
573  const unsigned int obj_index,
574  const unsigned int fe_index,
575  const unsigned int /*obj_level*/) const
576  {
577  Assert (obj_index < dof_offsets.size(),
578  ExcIndexRange (obj_index, 0, static_cast<unsigned int>(dof_offsets.size())));
580  ExcMessage ("You need to specify a FE index when working "
581  "with hp DoFHandlers"));
582  Assert (fe_index < dof_handler.get_fe_collection().size(),
583  ExcIndexRange (fe_index, 0, dof_handler.get_fe_collection().size()));
584 
585  // make sure we are on an
586  // object for which DoFs have
587  // been allocated at all
588  Assert (dof_offsets[obj_index] != numbers::invalid_unsigned_int,
589  ExcMessage ("You are trying to access degree of freedom "
590  "information for an object on which no such "
591  "information is available"));
592 
593  Assert (structdim<dim, ExcMessage ("This object can not be used for cells."));
594 
595  // there may be multiple finite elements associated with
596  // this object. hop along the list of index sets until we
597  // find the one with the correct fe_index, and then poke
598  // into that part. trigger an exception if we can't find a
599  // set for this particular fe_index
600  const types::global_dof_index starting_offset = dof_offsets[obj_index];
601  const types::global_dof_index *pointer = &dofs[starting_offset];
602  while (true)
603  {
604  if (*pointer == numbers::invalid_dof_index)
605  // end of list reached
606  return false;
607  else if (*pointer == fe_index)
608  return true;
609  else
610  pointer += static_cast<types::global_dof_index>(
611  dof_handler.get_fe(*pointer)
612  .template n_dofs_per_object<structdim>()+1);
613  }
614  }
615 
616  template <int structdim>
617  template <class Archive>
619  const unsigned int)
620  {
621  ar &dofs;
622  ar &dof_offsets;
623  }
624 
625 
626  } // namespace hp
627 
628 } // namespace internal
629 
630 DEAL_II_NAMESPACE_CLOSE
631 
632 #endif
static const unsigned int invalid_unsigned_int
Definition: types.h:173
void set_dof_index(const ::hp::DoFHandler< dim, spacedim > &dof_handler, const unsigned int obj_index, const unsigned int fe_index, const unsigned int local_index, const types::global_dof_index global_index, const unsigned int obj_level)
Definition: dof_faces.h:414
types::global_dof_index get_dof_index(const ::hp::DoFHandler< dim, spacedim > &dof_handler, const unsigned int obj_index, const unsigned int fe_index, const unsigned int local_index, const unsigned int obj_level) const
Definition: dof_faces.h:358
unsigned int n_active_fe_indices(const ::hp::DoFHandler< dim, spacedim > &dof_handler, const unsigned int obj_index) const
Definition: dof_faces.h:473
internal::hp::DoFIndicesOnFacesOrEdges< 1 > lines
Definition: dof_faces.h:277
static ::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
static ::ExceptionBase & ExcMessage(std::string arg1)
unsigned int global_dof_index
Definition: types.h:88
#define Assert(cond, exc)
Definition: exceptions.h:1142
void serialize(Archive &ar, const unsigned int version)
Definition: dof_faces.h:618
std::size_t memory_consumption() const
Definition: dof_faces.cc:29
std::vector< types::global_dof_index > dofs
Definition: dof_faces.h:110
std::vector< unsigned int > dof_offsets
Definition: dof_faces.h:104
Definition: hp.h:102
internal::hp::DoFIndicesOnFacesOrEdges< 2 > quads
Definition: dof_faces.h:313
bool fe_index_is_active(const ::hp::DoFHandler< dim, spacedim > &dof_handler, const unsigned int obj_index, const unsigned int fe_index, const unsigned int obj_level) const
Definition: dof_faces.h:572
types::global_dof_index nth_active_fe_index(const ::hp::DoFHandler< dim, spacedim > &dof_handler, const unsigned int obj_level, const unsigned int obj_index, const unsigned int n) const
Definition: dof_faces.h:516
const types::global_dof_index invalid_dof_index
Definition: types.h:187
internal::hp::DoFIndicesOnFacesOrEdges< 1 > lines
Definition: dof_faces.h:308
static ::ExceptionBase & ExcInternalError()