Reference documentation for deal.II version 8.1.0
data_out_dof_data.h
1 // ---------------------------------------------------------------------
2 // @f$Id: data_out_dof_data.h 30425 2013-08-22 16:26:52Z kronbichler @f$
3 //
4 // Copyright (C) 1999 - 2013 by the deal.II authors
5 //
6 // This file is part of the deal.II library.
7 //
8 // The deal.II library is free software; you can use it, redistribute
9 // it, and/or modify it under the terms of the GNU Lesser General
10 // Public License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
12 // The full text of the license can be found in the file LICENSE at
13 // the top level of the deal.II distribution.
14 //
15 // ---------------------------------------------------------------------
16 
17 #ifndef __deal2__data_out_dof_data_h
18 #define __deal2__data_out_dof_data_h
19 
20 
21 
22 #include <deal.II/base/config.h>
23 #include <deal.II/base/smartpointer.h>
24 #include <deal.II/base/data_out_base.h>
25 #include <deal.II/dofs/dof_handler.h>
26 #include <deal.II/grid/tria.h>
27 #include <deal.II/fe/mapping.h>
28 #include <deal.II/hp/q_collection.h>
29 #include <deal.II/hp/fe_collection.h>
30 #include <deal.II/hp/mapping_collection.h>
31 #include <deal.II/hp/fe_values.h>
32 #include <deal.II/numerics/data_postprocessor.h>
33 #include <deal.II/numerics/data_component_interpretation.h>
34 
35 #include <deal.II/base/std_cxx1x/shared_ptr.h>
36 
38 
39 template <int, int> class FEValuesBase;
40 
41 namespace internal
42 {
43  namespace DataOut
44  {
58  template <class DH>
60  {
61  public:
67  DataEntryBase (const DH *dofs,
68  const std::vector<std::string> &names,
69  const std::vector<DataComponentInterpretation::DataComponentInterpretation> &data_component_interpretation);
70 
76  DataEntryBase (const DH *dofs,
77  const DataPostprocessor<DH::space_dimension> *data_postprocessor);
78 
82  virtual ~DataEntryBase ();
83 
88  virtual
89  double
90  get_cell_data_value (const unsigned int cell_number) const = 0;
91 
96  virtual
97  void
99  std::vector<double> &patch_values) const = 0;
100 
106  virtual
107  void
109  std::vector<::Vector<double> > &patch_values_system) const = 0;
110 
115  virtual
116  void
118  std::vector<Tensor<1,DH::space_dimension> > &patch_gradients) const = 0;
119 
125  virtual
126  void
128  std::vector<std::vector<Tensor<1,DH::space_dimension> > > &patch_gradients_system) const = 0;
129 
134  virtual
135  void
137  std::vector<Tensor<2,DH::space_dimension> > &patch_hessians) const = 0;
138 
144  virtual
145  void
147  std::vector<std::vector< Tensor<2,DH::space_dimension> > > &patch_hessians_system) const = 0;
148 
152  virtual void clear () = 0;
153 
158  virtual std::size_t memory_consumption () const = 0;
159 
164 
168  const std::vector<std::string> names;
169 
175  const std::vector<DataComponentInterpretation::DataComponentInterpretation>
177 
183 
190  unsigned int n_output_variables;
191  };
192 
193 
210  template <int dim, int spacedim>
212  {
213  ParallelDataBase (const unsigned int n_datasets,
214  const unsigned int n_subdivisions,
215  const std::vector<unsigned int> &n_postprocessor_outputs,
216  const Mapping<dim,spacedim> &mapping,
217  const std::vector<std_cxx1x::shared_ptr<::hp::FECollection<dim,spacedim> > > &finite_elements,
218  const UpdateFlags update_flags,
219  const bool use_face_values);
220 
221  ParallelDataBase (const ParallelDataBase &data);
222 
223  template <typename DH>
224  void reinit_all_fe_values(std::vector<std_cxx1x::shared_ptr<DataEntryBase<DH> > > &dof_data,
225  const typename ::Triangulation<dim,spacedim>::cell_iterator &cell,
226  const unsigned int face = numbers::invalid_unsigned_int);
227 
229  get_present_fe_values(const unsigned int dataset) const;
230 
231  void resize_system_vectors(const unsigned int n_components);
232 
233  const unsigned int n_datasets;
234  const unsigned int n_subdivisions;
235 
236  std::vector<double> patch_values;
237  std::vector<::Vector<double> > patch_values_system;
238  std::vector<Tensor<1,spacedim> > patch_gradients;
239  std::vector<std::vector<Tensor<1,spacedim> > > patch_gradients_system;
240  std::vector<Tensor<2,spacedim> > patch_hessians;
241  std::vector<std::vector<Tensor<2,spacedim> > > patch_hessians_system;
242  std::vector<std::vector<::Vector<double> > > postprocessed_values;
243 
244  const ::hp::MappingCollection<dim,spacedim> mapping_collection;
245  const std::vector<std_cxx1x::shared_ptr<::hp::FECollection<dim,spacedim> > > finite_elements;
246  const UpdateFlags update_flags;
247 
248  std::vector<std_cxx1x::shared_ptr<::hp::FEValues<dim,spacedim> > > x_fe_values;
249  std::vector<std_cxx1x::shared_ptr<::hp::FEFaceValues<dim,spacedim> > > x_fe_face_values;
250  };
251  }
252 }
253 
254 
255 //TODO: Most of the documentation of DataOut_DoFData applies to DataOut.
256 
403 template <class DH, int patch_dim, int patch_space_dim=patch_dim>
404 class DataOut_DoFData : public DataOutInterface<patch_dim,patch_space_dim>
405 {
406 public:
407 
414 
415 public:
416 
426  {
431 
436 
441  };
442 
446  DataOut_DoFData ();
447 
451  virtual ~DataOut_DoFData ();
452 
461  void attach_dof_handler (const DH &);
462 
472  void attach_triangulation (const Triangulation<DH::dimension,
473  DH::space_dimension> &);
474 
541  template <class VECTOR>
542  void add_data_vector (const VECTOR &data,
543  const std::vector<std::string> &names,
544  const DataVectorType type = type_automatic,
545  const std::vector<DataComponentInterpretation::DataComponentInterpretation> &data_component_interpretation
546  = std::vector<DataComponentInterpretation::DataComponentInterpretation>());
547 
564  template <class VECTOR>
565  void add_data_vector (const VECTOR &data,
566  const std::string &name,
567  const DataVectorType type = type_automatic,
568  const std::vector<DataComponentInterpretation::DataComponentInterpretation> &data_component_interpretation
569  = std::vector<DataComponentInterpretation::DataComponentInterpretation>());
570 
585  template <class VECTOR>
586  void add_data_vector (const DH &dof_handler,
587  const VECTOR &data,
588  const std::vector<std::string> &names,
589  const std::vector<DataComponentInterpretation::DataComponentInterpretation> &data_component_interpretation
590  = std::vector<DataComponentInterpretation::DataComponentInterpretation>());
591 
592 
597  template <class VECTOR>
598  void add_data_vector (const DH &dof_handler,
599  const VECTOR &data,
600  const std::string &name,
601  const std::vector<DataComponentInterpretation::DataComponentInterpretation> &data_component_interpretation
602  = std::vector<DataComponentInterpretation::DataComponentInterpretation>());
603 
622  template <class VECTOR>
623  void add_data_vector (const VECTOR &data,
624  const DataPostprocessor<DH::space_dimension> &data_postprocessor);
625 
632  template <class VECTOR>
633  void add_data_vector (const DH &dof_handler,
634  const VECTOR &data,
635  const DataPostprocessor<DH::space_dimension> &data_postprocessor);
636 
643  void clear_data_vectors ();
644 
656 
680  template <class DH2>
683 
690  virtual void clear ();
691 
696  std::size_t memory_consumption () const;
697 
701  DeclException0 (ExcNoTriangulationSelected);
702 
706  DeclException0 (ExcNoDoFHandlerSelected);
707 
711  DeclException0 (ExcDataPostprocessingIsNotPossibleForCellData);
712 
716  DeclException3 (ExcInvalidVectorSize,
717  int, int, int,
718  << "The vector has size " << arg1
719  << " but the DoFHandler objects says there are " << arg2
720  << " degrees of freedom and there are " << arg3
721  << " active cells.");
725  DeclException2 (ExcInvalidCharacter,
726  std::string, size_t,
727  << "Please use only the characters [a-zA-Z0-9_<>()] for" << std::endl
728  << "description strings since some graphics formats will only accept these."
729  << std::endl
730  << "The string you gave was <" << arg1
731  << ">, the invalid character is <" << arg1[arg2]
732  << ">." << std::endl);
736  DeclException0 (ExcOldDataStillPresent);
740  DeclException2 (ExcInvalidNumberOfNames,
741  int, int,
742  << "You have to give one name per component in your "
743  << "data vector. The number you gave was " << arg1
744  << ", but the number of components is " << arg2);
748  DeclException0 (ExcNoPatches);
752  DeclException0 (ExcIncompatibleDatasetNames);
756  DeclException0 (ExcIncompatiblePatchLists);
757 
758  DeclException2 (ExcInvalidVectorDeclaration,
759  int, std::string,
760  << "When declaring that a number of components in a data\n"
761  << "set to be output logically form a vector instead of\n"
762  << "simply a set of scalar fields, you need to specify\n"
763  << "this for all relevant components. Furthermore,\n"
764  << "vectors must always consist of exactly <dim>\n"
765  << "components. However, the vector component at\n"
766  << "position " << arg1 << " with name <" << arg2
767  << "> does not satisfy these conditions.");
768 
769 protected:
773  typedef ::DataOutBase::Patch<patch_dim,patch_space_dim> Patch;
774 
779 
784 
788  std::vector<std_cxx1x::shared_ptr<internal::DataOut::DataEntryBase<DH> > > dof_data;
789 
793  std::vector<std_cxx1x::shared_ptr<internal::DataOut::DataEntryBase<DH> > > cell_data;
794 
800  std::vector<Patch> patches;
801 
806  virtual
807  const std::vector<Patch> &get_patches () const;
808 
813  virtual
814  std::vector<std::string> get_dataset_names () const;
815 
820  std::vector<std_cxx1x::shared_ptr<::hp::FECollection<DH::dimension,DH::space_dimension> > >
821  get_finite_elements() const;
822 
827  virtual
828  std::vector<std_cxx1x::tuple<unsigned int, unsigned int, std::string> >
829  get_vector_data_ranges () const;
830 
835  template <class, int, int>
836  friend class DataOut_DoFData;
837 };
838 
839 
840 
841 // -------------------- template and inline functions ------------------------
842 
843 
844 template <class DH, int patch_dim, int patch_space_dim>
845 template <class DH2>
846 void
849  const Point<patch_space_dim> &shift)
850 {
851  const std::vector<Patch> source_patches = source.get_patches ();
852  Assert (patches.size () != 0, ExcNoPatches ());
853  Assert (source_patches.size () != 0, ExcNoPatches ());
854  // check equality of component
855  // names
857  ExcIncompatibleDatasetNames());
858  // make sure patches are compatible. we'll
859  // assume that if the first respective
860  // patches are ok that all the other ones
861  // are ok as well
862  Assert (patches[0].n_subdivisions == source_patches[0].n_subdivisions,
863  ExcIncompatiblePatchLists());
864  Assert (patches[0].data.n_rows() == source_patches[0].data.n_rows(),
865  ExcIncompatiblePatchLists());
866  Assert (patches[0].data.n_cols() == source_patches[0].data.n_cols(),
867  ExcIncompatiblePatchLists());
868 
869  // check equality of the vector data
870  // specifications
871  Assert (get_vector_data_ranges().size() ==
872  source.get_vector_data_ranges().size(),
873  ExcMessage ("Both sources need to declare the same components "
874  "as vectors."));
875  for (unsigned int i=0; i<get_vector_data_ranges().size(); ++i)
876  {
877  Assert (std_cxx1x::get<0>(get_vector_data_ranges()[i]) ==
878  std_cxx1x::get<0>(source.get_vector_data_ranges()[i]),
879  ExcMessage ("Both sources need to declare the same components "
880  "as vectors."));
881  Assert (std_cxx1x::get<1>(get_vector_data_ranges()[i]) ==
882  std_cxx1x::get<1>(source.get_vector_data_ranges()[i]),
883  ExcMessage ("Both sources need to declare the same components "
884  "as vectors."));
885  Assert (std_cxx1x::get<2>(get_vector_data_ranges()[i]) ==
886  std_cxx1x::get<2>(source.get_vector_data_ranges()[i]),
887  ExcMessage ("Both sources need to declare the same components "
888  "as vectors."));
889  }
890 
891  // merge patches. store old number
892  // of elements, since we need to
893  // adjust patch numbers, etc
894  // afterwards
895  const unsigned int old_n_patches = patches.size();
896  patches.insert (patches.end(),
897  source_patches.begin(),
898  source_patches.end());
899 
900  // perform shift, if so desired
901  if (shift != Point<patch_space_dim>())
902  for (unsigned int i=old_n_patches; i<patches.size(); ++i)
903  for (unsigned int v=0; v<GeometryInfo<patch_dim>::vertices_per_cell; ++v)
904  patches[i].vertices[v] += shift;
905 
906  // adjust patch numbers
907  for (unsigned int i=old_n_patches; i<patches.size(); ++i)
908  patches[i].patch_index += old_n_patches;
909 
910  // adjust patch neighbors
911  for (unsigned int i=old_n_patches; i<patches.size(); ++i)
912  for (unsigned int n=0; n<GeometryInfo<patch_dim>::faces_per_cell; ++n)
913  if (patches[i].neighbors[n] != Patch::no_neighbor)
914  patches[i].neighbors[n] += old_n_patches;
915 }
916 
917 
918 DEAL_II_NAMESPACE_CLOSE
919 
920 #endif
virtual std::size_t memory_consumption() const =0
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<< ">, the invalid character is <"<< arg1[arg2]<< ">."<< std::endl)
static const unsigned int invalid_unsigned_int
Definition: types.h:191
virtual ~DataOut_DoFData()
const std::vector< DataComponentInterpretation::DataComponentInterpretation > data_component_interpretation
virtual const std::vector< Patch > & get_patches() const
SmartPointer< const DH > dofs
::ExceptionBase & ExcMessage(std::string arg1)
virtual void get_function_gradients(const FEValuesBase< DH::dimension, DH::space_dimension > &fe_patch_values, std::vector< Tensor< 1, DH::space_dimension > > &patch_gradients) const =0
DataEntryBase(const DH *dofs, const std::vector< std::string > &names, const std::vector< DataComponentInterpretation::DataComponentInterpretation > &data_component_interpretation)
void clear_data_vectors()
SmartPointer< const DH > dof_handler
virtual void get_function_values(const FEValuesBase< DH::dimension, DH::space_dimension > &fe_patch_values, std::vector< double > &patch_values) const =0
DeclException0(ExcNoTriangulationSelected)
#define Assert(cond, exc)
Definition: exceptions.h:299
UpdateFlags
virtual void clear()
std::vector< Patch > patches
void add_data_vector(const VECTOR &data, const std::vector< std::string > &names, const DataVectorType type=type_automatic, const std::vector< DataComponentInterpretation::DataComponentInterpretation > &data_component_interpretation=std::vector< DataComponentInterpretation::DataComponentInterpretation >())
::DataOutBase::Patch< patch_dim, patch_space_dim > Patch
virtual void get_function_hessians(const FEValuesBase< DH::dimension, DH::space_dimension > &fe_patch_values, std::vector< Tensor< 2, DH::space_dimension > > &patch_hessians) const =0
SmartPointer< const Triangulation< DH::dimension, DH::space_dimension > > triangulation
std::vector< std_cxx1x::shared_ptr<::hp::FECollection< DH::dimension, DH::space_dimension > > > get_finite_elements() const
static const unsigned int no_neighbor
std::vector< std_cxx1x::shared_ptr< internal::DataOut::DataEntryBase< DH > > > cell_data
virtual std::vector< std::string > get_dataset_names() const
const std::vector< std::string > names
void clear_input_data_references()
std::vector< std_cxx1x::shared_ptr< internal::DataOut::DataEntryBase< DH > > > dof_data
std::size_t memory_consumption() const
Triangulation< DH::dimension, DH::space_dimension >::cell_iterator cell_iterator
DeclException3(ExcInvalidVectorSize, int, int, int,<< "The vector has size "<< arg1<< " but the DoFHandler objects says there are "<< arg2<< " degrees of freedom and there are "<< arg3<< " active cells.")
virtual std::vector< std_cxx1x::tuple< unsigned int, unsigned int, std::string > > get_vector_data_ranges() const
virtual double get_cell_data_value(const unsigned int cell_number) const =0
void merge_patches(const DataOut_DoFData< DH2, patch_dim, patch_space_dim > &source, const Point< patch_space_dim > &shift=Point< patch_space_dim >())
void attach_triangulation(const Triangulation< DH::dimension, DH::space_dimension > &)
SmartPointer< const ::DataPostprocessor< DH::space_dimension > > postprocessor
void attach_dof_handler(const DH &)