Reference documentation for deal.II version 8.4.2
data_out_dof_data.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 1999 - 2015 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__data_out_dof_data_h
17 #define dealii__data_out_dof_data_h
18 
19 
20 
21 #include <deal.II/base/config.h>
22 #include <deal.II/base/smartpointer.h>
23 #include <deal.II/base/data_out_base.h>
24 #include <deal.II/dofs/dof_handler.h>
25 #include <deal.II/grid/tria.h>
26 #include <deal.II/fe/mapping.h>
27 #include <deal.II/hp/q_collection.h>
28 #include <deal.II/hp/fe_collection.h>
29 #include <deal.II/hp/mapping_collection.h>
30 #include <deal.II/hp/fe_values.h>
31 #include <deal.II/numerics/data_postprocessor.h>
32 #include <deal.II/numerics/data_component_interpretation.h>
33 
34 #include <deal.II/base/std_cxx11/shared_ptr.h>
35 
36 DEAL_II_NAMESPACE_OPEN
37 
38 template <int, int> class FEValuesBase;
39 
40 
41 namespace Exceptions
42 {
47  namespace DataOut
48  {
52  DeclException1 (ExcInvalidNumberOfSubdivisions,
53  int,
54  << "The number of subdivisions per patch, " << arg1
55  << ", is not valid. It needs to be greater or equal to "
56  "one, or zero if you want it to be determined "
57  "automatically.");
58 
62  DeclExceptionMsg (ExcNoTriangulationSelected,
63  "For the operation you are attempting, you first need to "
64  "tell the DataOut or related object which DoFHandler or "
65  "triangulation you would like to work on.");
66 
70  DeclExceptionMsg (ExcNoDoFHandlerSelected,
71  "For the operation you are attempting, you first need to "
72  "tell the DataOut or related object which DoFHandler "
73  "you would like to work on.");
74 
78  DeclException3 (ExcInvalidVectorSize,
79  int, int, int,
80  << "The vector has size " << arg1
81  << " but the DoFHandler object says that there are " << arg2
82  << " degrees of freedom and there are " << arg3
83  << " active cells. The size of your vector needs to be"
84  << " either equal to the number of degrees of freedom, or"
85  << " equal to the number of active cells.");
89  DeclException2 (ExcInvalidCharacter,
90  std::string, size_t,
91  << "Please use only the characters [a-zA-Z0-9_<>()] for" << std::endl
92  << "description strings since some graphics formats will only accept these."
93  << std::endl
94  << "The string you gave was <" << arg1
95  << ">, within which the invalid character is <" << arg1[arg2]
96  << ">." << std::endl);
100  DeclExceptionMsg (ExcOldDataStillPresent,
101  "When attaching a triangulation or DoFHandler object, it is "
102  "not allowed if old data vectors are still referenced. If "
103  "you want to reuse an object of the current type, you first "
104  "need to call the 'clear_data_vector()' function.");
108  DeclException2 (ExcInvalidNumberOfNames,
109  int, int,
110  << "You have to give one name per component in your "
111  << "data vector. The number you gave was " << arg1
112  << ", but the number of components is " << arg2
113  << ".");
117  DeclExceptionMsg (ExcIncompatibleDatasetNames,
118  "While merging sets of patches, the two sets to be merged "
119  "need to refer to data that agrees on the names of the "
120  "various variables represented. In other words, you "
121  "cannot merge sets of patches that originate from "
122  "entirely unrelated simulations.");
126  DeclExceptionMsg (ExcIncompatiblePatchLists,
127  "While merging sets of patches, the two sets to be merged "
128  "need to refer to data that agrees on the number of "
129  "subdivisions and other properties. In other words, you "
130  "cannot merge sets of patches that originate from "
131  "entirely unrelated simulations.");
132 
133  DeclException2 (ExcInvalidVectorDeclaration,
134  int, std::string,
135  << "When declaring that a number of components in a data "
136  << "set to be output logically form a vector instead of "
137  << "simply a set of scalar fields, you need to specify "
138  << "this for all relevant components. Furthermore, "
139  << "vectors must always consist of exactly <dim> "
140  << "components. However, the vector component at "
141  << "position " << arg1 << " with name <" << arg2
142  << "> does not satisfy these conditions.");
143  }
144 }
145 
146 
147 namespace internal
148 {
149  namespace DataOut
150  {
164  template <typename DoFHandlerType>
166  {
167  public:
173  DataEntryBase (const DoFHandlerType *dofs,
174  const std::vector<std::string> &names,
175  const std::vector<DataComponentInterpretation::DataComponentInterpretation> &data_component_interpretation);
176 
182  DataEntryBase (const DoFHandlerType *dofs,
183  const DataPostprocessor<DoFHandlerType::space_dimension> *data_postprocessor);
184 
188  virtual ~DataEntryBase ();
189 
194  virtual
195  double
196  get_cell_data_value (const unsigned int cell_number) const = 0;
197 
202  virtual
203  void
204  get_function_values
206  std::vector<double> &patch_values) const = 0;
207 
213  virtual
214  void
215  get_function_values
217  std::vector<::Vector<double> > &patch_values_system) const = 0;
218 
223  virtual
224  void
225  get_function_gradients
227  std::vector<Tensor<1,DoFHandlerType::space_dimension> > &patch_gradients) const = 0;
228 
234  virtual
235  void
236  get_function_gradients
238  std::vector<std::vector<Tensor<1,DoFHandlerType::space_dimension> > > &patch_gradients_system) const = 0;
239 
244  virtual
245  void
246  get_function_hessians
248  std::vector<Tensor<2,DoFHandlerType::space_dimension> > &patch_hessians) const = 0;
249 
255  virtual
256  void
257  get_function_hessians
259  std::vector<std::vector< Tensor<2,DoFHandlerType::space_dimension> > > &patch_hessians_system) const = 0;
260 
264  virtual void clear () = 0;
265 
270  virtual std::size_t memory_consumption () const = 0;
271 
276 
280  const std::vector<std::string> names;
281 
287  const std::vector<DataComponentInterpretation::DataComponentInterpretation>
289 
295 
302  unsigned int n_output_variables;
303  };
304 
305 
322  template <int dim, int spacedim>
324  {
325  ParallelDataBase (const unsigned int n_datasets,
326  const unsigned int n_subdivisions,
327  const std::vector<unsigned int> &n_postprocessor_outputs,
328  const Mapping<dim,spacedim> &mapping,
329  const std::vector<std_cxx11::shared_ptr<::hp::FECollection<dim,spacedim> > > &finite_elements,
330  const UpdateFlags update_flags,
331  const bool use_face_values);
332 
333  ParallelDataBase (const ParallelDataBase &data);
334 
335  template <typename DoFHandlerType>
336  void reinit_all_fe_values(std::vector<std_cxx11::shared_ptr<DataEntryBase<DoFHandlerType> > > &dof_data,
337  const typename ::Triangulation<dim,spacedim>::cell_iterator &cell,
338  const unsigned int face = numbers::invalid_unsigned_int);
339 
341  get_present_fe_values(const unsigned int dataset) const;
342 
343  void resize_system_vectors(const unsigned int n_components);
344 
345  const unsigned int n_datasets;
346  const unsigned int n_subdivisions;
347 
348  std::vector<double> patch_values;
349  std::vector<::Vector<double> > patch_values_system;
350  std::vector<Tensor<1,spacedim> > patch_gradients;
351  std::vector<std::vector<Tensor<1,spacedim> > > patch_gradients_system;
352  std::vector<Tensor<2,spacedim> > patch_hessians;
353  std::vector<std::vector<Tensor<2,spacedim> > > patch_hessians_system;
354  std::vector<std::vector<::Vector<double> > > postprocessed_values;
355 
356  const ::hp::MappingCollection<dim,spacedim> mapping_collection;
357  const std::vector<std_cxx11::shared_ptr<::hp::FECollection<dim,spacedim> > > finite_elements;
358  const UpdateFlags update_flags;
359 
360  std::vector<std_cxx11::shared_ptr<::hp::FEValues<dim,spacedim> > > x_fe_values;
361  std::vector<std_cxx11::shared_ptr<::hp::FEFaceValues<dim,spacedim> > > x_fe_face_values;
362  };
363  }
364 }
365 
366 
367 //TODO: Most of the documentation of DataOut_DoFData applies to DataOut.
368 
510 template <typename DoFHandlerType, int patch_dim, int patch_space_dim=patch_dim>
511 class DataOut_DoFData : public DataOutInterface<patch_dim,patch_space_dim>
512 {
513 public:
514 
521 
522 public:
523 
533  {
538 
543 
547  type_automatic
548  };
549 
553  DataOut_DoFData ();
554 
558  virtual ~DataOut_DoFData ();
559 
568  void attach_dof_handler (const DoFHandlerType &);
569 
579  void attach_triangulation (const Triangulation<DoFHandlerType::dimension,
580  DoFHandlerType::space_dimension> &);
581 
647  template <class VectorType>
648  void add_data_vector (const VectorType &data,
649  const std::vector<std::string> &names,
650  const DataVectorType type = type_automatic,
651  const std::vector<DataComponentInterpretation::DataComponentInterpretation> &data_component_interpretation
652  = std::vector<DataComponentInterpretation::DataComponentInterpretation>());
653 
670  template <class VectorType>
671  void add_data_vector (const VectorType &data,
672  const std::string &name,
673  const DataVectorType type = type_automatic,
674  const std::vector<DataComponentInterpretation::DataComponentInterpretation> &data_component_interpretation
675  = std::vector<DataComponentInterpretation::DataComponentInterpretation>());
676 
691  template <class VectorType>
692  void add_data_vector (const DoFHandlerType &dof_handler,
693  const VectorType &data,
694  const std::vector<std::string> &names,
695  const std::vector<DataComponentInterpretation::DataComponentInterpretation> &data_component_interpretation
696  = std::vector<DataComponentInterpretation::DataComponentInterpretation>());
697 
698 
703  template <class VectorType>
704  void add_data_vector (const DoFHandlerType &dof_handler,
705  const VectorType &data,
706  const std::string &name,
707  const std::vector<DataComponentInterpretation::DataComponentInterpretation> &data_component_interpretation
708  = std::vector<DataComponentInterpretation::DataComponentInterpretation>());
709 
738  template <class VectorType>
739  void add_data_vector (const VectorType &data,
740  const DataPostprocessor<DoFHandlerType::space_dimension> &data_postprocessor);
741 
748  template <class VectorType>
749  void add_data_vector (const DoFHandlerType &dof_handler,
750  const VectorType &data,
751  const DataPostprocessor<DoFHandlerType::space_dimension> &data_postprocessor);
752 
759  void clear_data_vectors ();
760 
771  void clear_input_data_references ();
772 
796  template <typename DoFHandlerType2>
797  void merge_patches (const DataOut_DoFData<DoFHandlerType2,patch_dim,patch_space_dim> &source,
799 
806  virtual void clear ();
807 
812  std::size_t memory_consumption () const;
813 
814 protected:
818  typedef ::DataOutBase::Patch<patch_dim,patch_space_dim> Patch;
819 
824 
829 
833  std::vector<std_cxx11::shared_ptr<internal::DataOut::DataEntryBase<DoFHandlerType> > > dof_data;
834 
838  std::vector<std_cxx11::shared_ptr<internal::DataOut::DataEntryBase<DoFHandlerType> > > cell_data;
839 
845  std::vector<Patch> patches;
846 
851  virtual
852  const std::vector<Patch> &get_patches () const;
853 
858  virtual
859  std::vector<std::string> get_dataset_names () const;
860 
865  std::vector<std_cxx11::shared_ptr<::hp::FECollection<DoFHandlerType::dimension,DoFHandlerType::space_dimension> > >
866  get_finite_elements() const;
867 
872  virtual
873  std::vector<std_cxx11::tuple<unsigned int, unsigned int, std::string> >
874  get_vector_data_ranges () const;
875 
880  template <class, int, int>
881  friend class DataOut_DoFData;
882 };
883 
884 
885 
886 // -------------------- template and inline functions ------------------------
887 
888 
889 template <typename DoFHandlerType, int patch_dim, int patch_space_dim>
890 template <typename DoFHandlerType2>
891 void
894  const Point<patch_space_dim> &shift)
895 {
896  const std::vector<Patch> source_patches = source.get_patches ();
897  Assert ((patches.size () != 0) &&
898  (source_patches.size () != 0),
899  ExcMessage ("When calling this function, both the current "
900  "object and the one being merged need to have a "
901  "nonzero number of patches associated with it. "
902  "Either you called this function on objects that "
903  "are empty, or you may have forgotten to call "
904  "the 'build_patches()' function."));
905  // check equality of component
906  // names
908  Exceptions::DataOut::ExcIncompatibleDatasetNames());
909  // make sure patches are compatible. we'll
910  // assume that if the first respective
911  // patches are ok that all the other ones
912  // are ok as well
913  Assert (patches[0].n_subdivisions == source_patches[0].n_subdivisions,
914  Exceptions::DataOut::ExcIncompatiblePatchLists());
915  Assert (patches[0].data.n_rows() == source_patches[0].data.n_rows(),
916  Exceptions::DataOut::ExcIncompatiblePatchLists());
917  Assert (patches[0].data.n_cols() == source_patches[0].data.n_cols(),
918  Exceptions::DataOut::ExcIncompatiblePatchLists());
919 
920  // check equality of the vector data
921  // specifications
922  Assert (get_vector_data_ranges().size() ==
923  source.get_vector_data_ranges().size(),
924  ExcMessage ("Both sources need to declare the same components "
925  "as vectors."));
926  for (unsigned int i=0; i<get_vector_data_ranges().size(); ++i)
927  {
928  Assert (std_cxx11::get<0>(get_vector_data_ranges()[i]) ==
929  std_cxx11::get<0>(source.get_vector_data_ranges()[i]),
930  ExcMessage ("Both sources need to declare the same components "
931  "as vectors."));
932  Assert (std_cxx11::get<1>(get_vector_data_ranges()[i]) ==
933  std_cxx11::get<1>(source.get_vector_data_ranges()[i]),
934  ExcMessage ("Both sources need to declare the same components "
935  "as vectors."));
936  Assert (std_cxx11::get<2>(get_vector_data_ranges()[i]) ==
937  std_cxx11::get<2>(source.get_vector_data_ranges()[i]),
938  ExcMessage ("Both sources need to declare the same components "
939  "as vectors."));
940  }
941 
942  // merge patches. store old number
943  // of elements, since we need to
944  // adjust patch numbers, etc
945  // afterwards
946  const unsigned int old_n_patches = patches.size();
947  patches.insert (patches.end(),
948  source_patches.begin(),
949  source_patches.end());
950 
951  // perform shift, if so desired
952  if (shift != Point<patch_space_dim>())
953  for (unsigned int i=old_n_patches; i<patches.size(); ++i)
954  for (unsigned int v=0; v<GeometryInfo<patch_dim>::vertices_per_cell; ++v)
955  patches[i].vertices[v] += shift;
956 
957  // adjust patch numbers
958  for (unsigned int i=old_n_patches; i<patches.size(); ++i)
959  patches[i].patch_index += old_n_patches;
960 
961  // adjust patch neighbors
962  for (unsigned int i=old_n_patches; i<patches.size(); ++i)
963  for (unsigned int n=0; n<GeometryInfo<patch_dim>::faces_per_cell; ++n)
964  if (patches[i].neighbors[n] != Patch::no_neighbor)
965  patches[i].neighbors[n] += old_n_patches;
966 }
967 
968 
969 DEAL_II_NAMESPACE_CLOSE
970 
971 #endif
std::vector< std_cxx11::shared_ptr< internal::DataOut::DataEntryBase< DoFHandlerType > > > cell_data
void merge_patches(const DataOut_DoFData< DoFHandlerType2, patch_dim, patch_space_dim > &source, const Point< patch_space_dim > &shift=Point< patch_space_dim >())
static const unsigned int invalid_unsigned_int
Definition: types.h:164
::DataOutBase::Patch< patch_dim, patch_space_dim > Patch
DeclException1(ExcInvalidNumberOfSubdivisions, int,<< "The number of subdivisions per patch, "<< arg1<< ", is not valid. It needs to be greater or equal to " "one, or zero if you want it to be determined " "automatically.")
const std::vector< DataComponentInterpretation::DataComponentInterpretation > data_component_interpretation
::ExceptionBase & ExcMessage(std::string arg1)
Triangulation< DoFHandlerType::dimension, DoFHandlerType::space_dimension >::cell_iterator cell_iterator
virtual std::vector< std_cxx11::tuple< unsigned int, unsigned int, std::string > > get_vector_data_ranges() const
Definition: point.h:89
DeclExceptionMsg(ExcNoTriangulationSelected, "For the operation you are attempting, you first need to " "tell the DataOut or related object which DoFHandler or " "triangulation you would like to work on.")
#define Assert(cond, exc)
Definition: exceptions.h:294
UpdateFlags
Abstract base class for mapping classes.
Definition: dof_tools.h:52
SmartPointer< const DoFHandlerType > dof_handler
std::vector< Patch > patches
SmartPointer< const ::DataPostprocessor< DoFHandlerType::space_dimension > > postprocessor
virtual std::vector< std::string > get_dataset_names() const
static const unsigned int no_neighbor
Definition: mpi.h:48
SmartPointer< const Triangulation< DoFHandlerType::dimension, DoFHandlerType::space_dimension > > triangulation
DeclException3(ExcInvalidVectorSize, int, int, int,<< "The vector has size "<< arg1<< " but the DoFHandler object says that there are "<< arg2<< " degrees of freedom and there are "<< arg3<< " active cells. The size of your vector needs to be"<< " either equal to the number of degrees of freedom, or"<< " equal to the number of active cells.")
std::vector< std_cxx11::shared_ptr< internal::DataOut::DataEntryBase< DoFHandlerType > > > dof_data
SmartPointer< const DoFHandlerType > dofs
const std::vector< std::string > names
DeclException2(ExcInvalidCharacter, std::string, size_t,<< "Please use only the characters [a-zA-Z0-9_<>()] for"<< std::endl<< "description strings since some graphics formats will only accept these."<< std::endl<< "The string you gave was <"<< arg1<< ">, within which the invalid character is <"<< arg1[arg2]<< ">."<< std::endl)
virtual const std::vector< Patch > & get_patches() const