Reference documentation for deal.II version 9.0.0
data_out_dof_data.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 1999 - 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_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 <memory>
35 
36 DEAL_II_NAMESPACE_OPEN
37 
38 namespace Exceptions
39 {
44  namespace DataOutImplementation
45  {
50  int,
51  << "The number of subdivisions per patch, " << arg1
52  << ", is not valid. It needs to be greater or equal to "
53  "one, or zero if you want it to be determined "
54  "automatically.");
55 
60  "For the operation you are attempting, you first need to "
61  "tell the DataOut or related object which DoFHandler or "
62  "triangulation you would like to work on.");
63 
68  "For the operation you are attempting, you first need to "
69  "tell the DataOut or related object which DoFHandler "
70  "you would like to work on.");
71 
76  int, int, int,
77  << "The vector has size " << arg1
78  << " but the DoFHandler object says that there are " << arg2
79  << " degrees of freedom and there are " << arg3
80  << " active cells. The size of your vector needs to be"
81  << " either equal to the number of degrees of freedom, or"
82  << " equal to the number of active cells.");
87  std::string, size_t,
88  << "Please use only the characters [a-zA-Z0-9_<>()] for" << std::endl
89  << "description strings since some graphics formats will only accept these."
90  << std::endl
91  << "The string you gave was <" << arg1
92  << ">, within which the invalid character is <" << arg1[arg2]
93  << ">." << std::endl);
98  "When attaching a triangulation or DoFHandler object, it is "
99  "not allowed if old data vectors are still referenced. If "
100  "you want to reuse an object of the current type, you first "
101  "need to call the 'clear_data_vector()' function.");
106  int, int,
107  << "You have to give one name per component in your "
108  << "data vector. The number you gave was " << arg1
109  << ", but the number of components is " << arg2
110  << ".");
115  "While merging sets of patches, the two sets to be merged "
116  "need to refer to data that agrees on the names of the "
117  "various variables represented. In other words, you "
118  "cannot merge sets of patches that originate from "
119  "entirely unrelated simulations.");
124  "While merging sets of patches, the two sets to be merged "
125  "need to refer to data that agrees on the number of "
126  "subdivisions and other properties. In other words, you "
127  "cannot merge sets of patches that originate from "
128  "entirely unrelated simulations.");
129 
131  int, std::string,
132  << "When declaring that a number of components in a data "
133  << "set to be output logically form a vector instead of "
134  << "simply a set of scalar fields, you need to specify "
135  << "this for all relevant components. Furthermore, "
136  << "vectors must always consist of exactly <dim> "
137  << "components. However, the vector component at "
138  << "position " << arg1 << " with name <" << arg2
139  << "> does not satisfy these conditions.");
140  }
141 }
142 
143 
144 namespace internal
145 {
146  namespace DataOutImplementation
147  {
170  enum class ComponentExtractor
171  {
172  real_part,
173  imaginary_part
174  };
175 
176 
190  template <typename DoFHandlerType>
192  {
193  public:
199  DataEntryBase (const DoFHandlerType *dofs,
200  const std::vector<std::string> &names,
201  const std::vector<DataComponentInterpretation::DataComponentInterpretation> &data_component_interpretation);
202 
208  DataEntryBase (const DoFHandlerType *dofs,
209  const DataPostprocessor<DoFHandlerType::space_dimension> *data_postprocessor);
210 
214  virtual ~DataEntryBase () = default;
215 
220  virtual
221  double
222  get_cell_data_value (const unsigned int cell_number,
223  const ComponentExtractor extract_component) const = 0;
224 
229  virtual
230  void
233  const ComponentExtractor extract_component,
234  std::vector<double> &patch_values) const = 0;
235 
241  virtual
242  void
245  const ComponentExtractor extract_component,
246  std::vector<::Vector<double> > &patch_values_system) const = 0;
247 
252  virtual
253  void
256  const ComponentExtractor extract_component,
257  std::vector<Tensor<1,DoFHandlerType::space_dimension> > &patch_gradients) const = 0;
258 
264  virtual
265  void
268  const ComponentExtractor extract_component,
269  std::vector<std::vector<Tensor<1,DoFHandlerType::space_dimension> > > &patch_gradients_system) const = 0;
270 
275  virtual
276  void
279  const ComponentExtractor extract_component,
280  std::vector<Tensor<2,DoFHandlerType::space_dimension> > &patch_hessians) const = 0;
281 
287  virtual
288  void
291  const ComponentExtractor extract_component,
292  std::vector<std::vector< Tensor<2,DoFHandlerType::space_dimension> > > &patch_hessians_system) const = 0;
293 
298  virtual bool is_complex_valued () const = 0;
299 
303  virtual void clear () = 0;
304 
309  virtual std::size_t memory_consumption () const = 0;
310 
315 
319  const std::vector<std::string> names;
320 
326  const std::vector<DataComponentInterpretation::DataComponentInterpretation>
328 
334 
341  unsigned int n_output_variables;
342  };
343 
344 
361  template <int dim, int spacedim>
363  {
364  ParallelDataBase (const unsigned int n_datasets,
365  const unsigned int n_subdivisions,
366  const std::vector<unsigned int> &n_postprocessor_outputs,
367  const Mapping<dim,spacedim> &mapping,
368  const std::vector<std::shared_ptr<::hp::FECollection<dim,spacedim> > > &finite_elements,
369  const UpdateFlags update_flags,
370  const bool use_face_values);
371 
372  ParallelDataBase (const ParallelDataBase &data);
373 
374  template <typename DoFHandlerType>
375  void reinit_all_fe_values(std::vector<std::shared_ptr<DataEntryBase<DoFHandlerType> > > &dof_data,
376  const typename ::Triangulation<dim,spacedim>::cell_iterator &cell,
377  const unsigned int face = numbers::invalid_unsigned_int);
378 
380  get_present_fe_values(const unsigned int dataset) const;
381 
382  void resize_system_vectors(const unsigned int n_components);
383 
384  const unsigned int n_datasets;
385  const unsigned int n_subdivisions;
386 
387  DataPostprocessorInputs::Scalar<spacedim> patch_values_scalar;
388  DataPostprocessorInputs::Vector<spacedim> patch_values_system;
389  std::vector<std::vector<::Vector<double> > > postprocessed_values;
390 
391  const ::hp::MappingCollection<dim,spacedim> mapping_collection;
392  const std::vector<std::shared_ptr<::hp::FECollection<dim,spacedim> > > finite_elements;
393  const UpdateFlags update_flags;
394 
395  std::vector<std::shared_ptr<::hp::FEValues<dim,spacedim> > > x_fe_values;
396  std::vector<std::shared_ptr<::hp::FEFaceValues<dim,spacedim> > > x_fe_face_values;
397  };
398  }
399 }
400 
401 
402 //TODO: Most of the documentation of DataOut_DoFData applies to DataOut.
403 
545 template <typename DoFHandlerType, int patch_dim, int patch_space_dim=patch_dim>
546 class DataOut_DoFData : public DataOutInterface<patch_dim,patch_space_dim>
547 {
548 public:
549 
556 
557 public:
558 
568  {
573 
578 
583  };
584 
588  DataOut_DoFData ();
589 
593  virtual ~DataOut_DoFData ();
594 
603  void attach_dof_handler (const DoFHandlerType &);
604 
614  void attach_triangulation (const Triangulation<DoFHandlerType::dimension,
615  DoFHandlerType::space_dimension> &);
616 
682  template <class VectorType>
683  void add_data_vector (const VectorType &data,
684  const std::vector<std::string> &names,
685  const DataVectorType type = type_automatic,
686  const std::vector<DataComponentInterpretation::DataComponentInterpretation> &data_component_interpretation
687  = std::vector<DataComponentInterpretation::DataComponentInterpretation>());
688 
705  template <class VectorType>
706  void add_data_vector (const VectorType &data,
707  const std::string &name,
708  const DataVectorType type = type_automatic,
709  const std::vector<DataComponentInterpretation::DataComponentInterpretation> &data_component_interpretation
710  = std::vector<DataComponentInterpretation::DataComponentInterpretation>());
711 
726  template <class VectorType>
727  void add_data_vector (const DoFHandlerType &dof_handler,
728  const VectorType &data,
729  const std::vector<std::string> &names,
730  const std::vector<DataComponentInterpretation::DataComponentInterpretation> &data_component_interpretation
731  = std::vector<DataComponentInterpretation::DataComponentInterpretation>());
732 
733 
738  template <class VectorType>
739  void add_data_vector (const DoFHandlerType &dof_handler,
740  const VectorType &data,
741  const std::string &name,
742  const std::vector<DataComponentInterpretation::DataComponentInterpretation> &data_component_interpretation
743  = std::vector<DataComponentInterpretation::DataComponentInterpretation>());
744 
773  template <class VectorType>
774  void add_data_vector (const VectorType &data,
775  const DataPostprocessor<DoFHandlerType::space_dimension> &data_postprocessor);
776 
783  template <class VectorType>
784  void add_data_vector (const DoFHandlerType &dof_handler,
785  const VectorType &data,
786  const DataPostprocessor<DoFHandlerType::space_dimension> &data_postprocessor);
787 
794  void clear_data_vectors ();
795 
807 
831  template <typename DoFHandlerType2>
834 
841  virtual void clear ();
842 
847  std::size_t memory_consumption () const;
848 
849 protected:
853  typedef ::DataOutBase::Patch<patch_dim,patch_space_dim> Patch;
854 
859 
864 
868  std::vector<std::shared_ptr<internal::DataOutImplementation::DataEntryBase<DoFHandlerType> > > dof_data;
869 
873  std::vector<std::shared_ptr<internal::DataOutImplementation::DataEntryBase<DoFHandlerType> > > cell_data;
874 
880  std::vector<Patch> patches;
881 
886  virtual
887  const std::vector<Patch> &get_patches () const;
888 
893  virtual
894  std::vector<std::string> get_dataset_names () const;
895 
900  std::vector<std::shared_ptr<::hp::FECollection<DoFHandlerType::dimension,DoFHandlerType::space_dimension> > >
901  get_fes() const;
902 
907  virtual
908  std::vector<std::tuple<unsigned int, unsigned int, std::string> >
909  get_vector_data_ranges () const;
910 
915  template <class, int, int>
916  friend class DataOut_DoFData;
917 private:
921  template <class VectorType>
922  void
924  (const DoFHandlerType *dof_handler,
925  const VectorType &data,
926  const std::vector<std::string> &names,
927  const DataVectorType type,
928  const std::vector<DataComponentInterpretation::DataComponentInterpretation> &data_component_interpretation,
929  const bool deduce_output_names);
930 };
931 
932 
933 
934 // -------------------- template and inline functions ------------------------
935 template <typename DoFHandlerType, int patch_dim, int patch_space_dim>
936 template <typename VectorType>
937 void
940 (const VectorType &vec,
941  const std::string &name,
942  const DataVectorType type,
943  const std::vector<DataComponentInterpretation::DataComponentInterpretation> &data_component_interpretation)
944 {
946  std::vector<std::string> names(1, name);
947  add_data_vector_internal (dofs, vec, names, type, data_component_interpretation, true);
948 }
949 
950 
951 
952 template <typename DoFHandlerType, int patch_dim, int patch_space_dim>
953 template <typename VectorType>
954 void
957 (const VectorType &vec,
958  const std::vector<std::string> &names,
959  const DataVectorType type,
960  const std::vector<DataComponentInterpretation::DataComponentInterpretation> &data_component_interpretation)
961 {
963  add_data_vector_internal(dofs, vec, names, type, data_component_interpretation, false);
964 }
965 
966 
967 
968 template <typename DoFHandlerType, int patch_dim, int patch_space_dim>
969 template <typename VectorType>
970 void
973 (const DoFHandlerType &dof_handler,
974  const VectorType &data,
975  const std::string &name,
976  const std::vector<DataComponentInterpretation::DataComponentInterpretation> &data_component_interpretation)
977 {
978  std::vector<std::string> names(1, name);
979  add_data_vector_internal (&dof_handler, data, names, type_dof_data, data_component_interpretation, true);
980 }
981 
982 
983 
984 template <typename DoFHandlerType, int patch_dim, int patch_space_dim>
985 template <typename VectorType>
986 void
989 (const DoFHandlerType &dof_handler,
990  const VectorType &data,
991  const std::vector<std::string> &names,
992  const std::vector<DataComponentInterpretation::DataComponentInterpretation> &data_component_interpretation)
993 {
994  add_data_vector_internal(&dof_handler, data, names, type_dof_data, data_component_interpretation, false);
995 }
996 
997 
998 
999 template <typename DoFHandlerType, int patch_dim, int patch_space_dim>
1000 template <typename VectorType>
1001 void
1003 add_data_vector (const VectorType &vec,
1004  const DataPostprocessor<DoFHandlerType::space_dimension> &data_postprocessor)
1005 {
1007  add_data_vector(*dofs, vec, data_postprocessor);
1008 }
1009 
1010 
1011 
1012 template <typename DoFHandlerType, int patch_dim, int patch_space_dim>
1013 template <typename DoFHandlerType2>
1014 void
1017  const Point<patch_space_dim> &shift)
1018 {
1019  const std::vector<Patch> &source_patches = source.get_patches ();
1020  Assert ((patches.size () != 0) &&
1021  (source_patches.size () != 0),
1022  ExcMessage ("When calling this function, both the current "
1023  "object and the one being merged need to have a "
1024  "nonzero number of patches associated with it. "
1025  "Either you called this function on objects that "
1026  "are empty, or you may have forgotten to call "
1027  "the 'build_patches()' function."));
1028  // check equality of component
1029  // names
1032  // make sure patches are compatible. we'll
1033  // assume that if the first respective
1034  // patches are ok that all the other ones
1035  // are ok as well
1036  Assert (patches[0].n_subdivisions == source_patches[0].n_subdivisions,
1038  Assert (patches[0].data.n_rows() == source_patches[0].data.n_rows(),
1040  Assert (patches[0].data.n_cols() == source_patches[0].data.n_cols(),
1042 
1043  // check equality of the vector data
1044  // specifications
1045  Assert (get_vector_data_ranges().size() ==
1046  source.get_vector_data_ranges().size(),
1047  ExcMessage ("Both sources need to declare the same components "
1048  "as vectors."));
1049  for (unsigned int i=0; i<get_vector_data_ranges().size(); ++i)
1050  {
1051  Assert (std::get<0>(get_vector_data_ranges()[i]) ==
1052  std::get<0>(source.get_vector_data_ranges()[i]),
1053  ExcMessage ("Both sources need to declare the same components "
1054  "as vectors."));
1055  Assert (std::get<1>(get_vector_data_ranges()[i]) ==
1056  std::get<1>(source.get_vector_data_ranges()[i]),
1057  ExcMessage ("Both sources need to declare the same components "
1058  "as vectors."));
1059  Assert (std::get<2>(get_vector_data_ranges()[i]) ==
1060  std::get<2>(source.get_vector_data_ranges()[i]),
1061  ExcMessage ("Both sources need to declare the same components "
1062  "as vectors."));
1063  }
1064 
1065  // merge patches. store old number
1066  // of elements, since we need to
1067  // adjust patch numbers, etc
1068  // afterwards
1069  const unsigned int old_n_patches = patches.size();
1070  patches.insert (patches.end(),
1071  source_patches.begin(),
1072  source_patches.end());
1073 
1074  // perform shift, if so desired
1075  if (shift != Point<patch_space_dim>())
1076  for (unsigned int i=old_n_patches; i<patches.size(); ++i)
1077  for (unsigned int v=0; v<GeometryInfo<patch_dim>::vertices_per_cell; ++v)
1078  patches[i].vertices[v] += shift;
1079 
1080  // adjust patch numbers
1081  for (unsigned int i=old_n_patches; i<patches.size(); ++i)
1082  patches[i].patch_index += old_n_patches;
1083 
1084  // adjust patch neighbors
1085  for (unsigned int i=old_n_patches; i<patches.size(); ++i)
1086  for (unsigned int n=0; n<GeometryInfo<patch_dim>::faces_per_cell; ++n)
1087  if (patches[i].neighbors[n] != Patch::no_neighbor)
1088  patches[i].neighbors[n] += old_n_patches;
1089 }
1090 
1091 
1092 DEAL_II_NAMESPACE_CLOSE
1093 
1094 #endif
void clear_input_data_references()
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:173
static ::ExceptionBase & ExcNoTriangulationSelected()
static ::ExceptionBase & ExcIncompatiblePatchLists()
::DataOutBase::Patch< patch_dim, patch_space_dim > Patch
#define DeclException2(Exception2, type1, type2, outsequence)
Definition: exceptions.h:358
void attach_triangulation(const Triangulation< DoFHandlerType::dimension, DoFHandlerType::space_dimension > &)
std::vector< std::shared_ptr<::hp::FECollection< DoFHandlerType::dimension, DoFHandlerType::space_dimension > > > get_fes() const
static ::ExceptionBase & ExcOldDataStillPresent()
const std::vector< DataComponentInterpretation::DataComponentInterpretation > data_component_interpretation
virtual std::vector< std::tuple< unsigned int, unsigned int, std::string > > get_vector_data_ranges() const
void attach_dof_handler(const DoFHandlerType &)
static ::ExceptionBase & ExcInvalidVectorSize(int arg1, int arg2, int arg3)
SmartPointer< const ::DataPostprocessor< DoFHandlerType::space_dimension > > postprocessor
Triangulation< DoFHandlerType::dimension, DoFHandlerType::space_dimension >::cell_iterator cell_iterator
virtual std::vector< std::string > get_dataset_names() const
static ::ExceptionBase & ExcInvalidNumberOfSubdivisions(int arg1)
Definition: point.h:104
static ::ExceptionBase & ExcIncompatibleDatasetNames()
static ::ExceptionBase & ExcMessage(std::string arg1)
static ::ExceptionBase & ExcNoDoFHandlerSelected()
#define DeclException1(Exception1, type1, outsequence)
Definition: exceptions.h:346
std::vector< std::shared_ptr< internal::DataOutImplementation::DataEntryBase< DoFHandlerType > > > dof_data
DataEntryBase(const DoFHandlerType *dofs, const std::vector< std::string > &names, const std::vector< DataComponentInterpretation::DataComponentInterpretation > &data_component_interpretation)
#define Assert(cond, exc)
Definition: exceptions.h:1142
virtual ~DataOut_DoFData()
UpdateFlags
virtual void get_function_values(const FEValuesBase< DoFHandlerType::dimension, DoFHandlerType::space_dimension > &fe_patch_values, const ComponentExtractor extract_component, std::vector< double > &patch_values) const =0
Abstract base class for mapping classes.
Definition: dof_tools.h:46
static ::ExceptionBase & ExcInvalidNumberOfNames(int arg1, int arg2)
virtual void get_function_gradients(const FEValuesBase< DoFHandlerType::dimension, DoFHandlerType::space_dimension > &fe_patch_values, const ComponentExtractor extract_component, std::vector< Tensor< 1, DoFHandlerType::space_dimension > > &patch_gradients) const =0
std::vector< std::shared_ptr< internal::DataOutImplementation::DataEntryBase< DoFHandlerType > > > cell_data
static ::ExceptionBase & ExcInvalidVectorDeclaration(int arg1, std::string arg2)
#define DeclExceptionMsg(Exception, defaulttext)
Definition: exceptions.h:335
static ::ExceptionBase & ExcInvalidCharacter(std::string arg1, size_t arg2)
std::vector< Patch > patches
virtual const std::vector< Patch > & get_patches() const
void add_data_vector(const VectorType &data, const std::vector< std::string > &names, const DataVectorType type=type_automatic, const std::vector< DataComponentInterpretation::DataComponentInterpretation > &data_component_interpretation=std::vector< DataComponentInterpretation::DataComponentInterpretation >())
std::size_t memory_consumption() const
static const unsigned int no_neighbor
SmartPointer< const DoFHandlerType > dof_handler
Definition: mpi.h:53
virtual void get_function_hessians(const FEValuesBase< DoFHandlerType::dimension, DoFHandlerType::space_dimension > &fe_patch_values, const ComponentExtractor extract_component, std::vector< Tensor< 2, DoFHandlerType::space_dimension > > &patch_hessians) const =0
SmartPointer< const Triangulation< DoFHandlerType::dimension, DoFHandlerType::space_dimension > > triangulation
virtual std::size_t memory_consumption() const =0
void add_data_vector_internal(const DoFHandlerType *dof_handler, const VectorType &data, const std::vector< std::string > &names, const DataVectorType type, const std::vector< DataComponentInterpretation::DataComponentInterpretation > &data_component_interpretation, const bool deduce_output_names)
#define DeclException3(Exception3, type1, type2, type3, outsequence)
Definition: exceptions.h:370
void clear_data_vectors()
SmartPointer< const DoFHandlerType > dofs
virtual double get_cell_data_value(const unsigned int cell_number, const ComponentExtractor extract_component) const =0
virtual void clear()