ASPECT
visualization.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2011 - 2024 by the authors of the ASPECT code.
3 
4  This file is part of ASPECT.
5 
6  ASPECT is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2, or (at your option)
9  any later version.
10 
11  ASPECT is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with ASPECT; see the file LICENSE. If not see
18  <http://www.gnu.org/licenses/>.
19 */
20 
21 
22 #ifndef _aspect_postprocess_visualization_h
23 #define _aspect_postprocess_visualization_h
24 
27 #include <aspect/plugins.h>
28 
29 #include <deal.II/base/thread_management.h>
30 #include <deal.II/numerics/data_postprocessor.h>
31 #include <deal.II/base/data_out_base.h>
32 #include <deal.II/numerics/data_out.h>
33 
34 #include <thread>
35 
36 namespace aspect
37 {
38  namespace Postprocess
39  {
40  namespace VisualizationPostprocessors
41  {
45  inline void average_quantities(std::vector<Vector<double>> &quantities)
46  {
47  const unsigned int N = quantities.size();
48  const unsigned int M = quantities[0].size();
49  for (unsigned int m=0; m<M; ++m)
50  {
51  double sum = 0;
52  for (unsigned int q=0; q<N; ++q)
53  sum += quantities[q](m);
54 
55  const double average = sum/N;
56  for (unsigned int q=0; q<N; ++q)
57  quantities[q](m) = average;
58  }
59  }
60 
123  template <int dim>
125  {
126  public:
146  explicit Interface (const std::string &physical_units = "");
147 
159  virtual
160  std::string
161  get_physical_units () const;
162 
177  virtual
178  std::list<std::string>
180 
181  private:
185  const std::string physical_units;
186  };
187 
188 
189 
202  template <int dim>
203  class CellDataVectorCreator : public Interface<dim>
204  {
205  public:
211  explicit CellDataVectorCreator (const std::string &physical_units = "");
212 
216  ~CellDataVectorCreator () override = default;
217 
236  virtual
237  std::pair<std::string, std::unique_ptr<Vector<float>>>
238  execute () const = 0;
239  };
240 
241 
248  template <int dim>
250  {
251  public:
257  virtual
258  ~SurfaceOnlyVisualization () = default;
259  };
260  }
261 
262 
278  template <int dim>
279  class Visualization : public Interface<dim>, public ::aspect::SimulatorAccess<dim>
280  {
281  public:
285  Visualization ();
286 
290  std::pair<std::string,std::string>
291  execute (TableHandler &statistics) override;
292 
296  void
297  update () override;
298 
317  static
318  void
319  register_visualization_postprocessor (const std::string &name,
320  const std::string &description,
321  void (*declare_parameters_function) (ParameterHandler &),
322  std::unique_ptr<VisualizationPostprocessors::Interface<dim>>(*factory_function) ());
323 
331  std::list<std::string>
332  required_other_postprocessors () const override;
333 
337  static
338  void
339  declare_parameters (ParameterHandler &prm);
340 
344  void
345  parse_parameters (ParameterHandler &prm) override;
346 
350  void save (std::map<std::string, std::string> &status_strings) const override;
351 
355  void load (const std::map<std::string, std::string> &status_strings) override;
356 
361  template <class Archive>
362  void serialize (Archive &ar, const unsigned int version);
363 
373  static
374  void
375  write_plugin_graph (std::ostream &output_stream);
376 
381  bool output_pointwise_stress_and_strain() const;
382 
386  DeclException1 (ExcPostprocessorNameNotFound,
387  std::string,
388  << "Could not find entry <"
389  << arg1
390  << "> among the names of registered postprocessors.");
391 
392  private:
399 
405 
413 
418  unsigned int last_output_timestep;
419 
424  unsigned int output_file_number;
425 
429  std::string output_format;
430 
437  unsigned int group_files;
438 
447 
459 
468 
475 
488 
496 
505 
513 
521 
529 
538  void set_last_output_time (const double current_time);
539 
544  void mesh_changed_signal ();
545 
552  static
553  void writer (const std::string &filename,
554  const std::string &temporary_filename,
555  const std::string &file_contents);
556 
561  std::list<std::unique_ptr<VisualizationPostprocessors::Interface<dim>>> postprocessors;
562 
570  {
574  OutputHistory ();
575 
581  ~OutputHistory ();
582 
587  template <class Archive>
588  void serialize (Archive &ar, const unsigned int version);
589 
595 
600  std::string last_mesh_file_name;
601 
610  std::vector<std::pair<double,std::string>> times_and_pvtu_names;
611 
617  std::vector<std::vector<std::string>> output_file_names_by_timestep;
618 
625  std::vector<XDMFEntry> xdmf_entries;
626 
632  std::thread background_thread;
633  };
634 
640 
646 
664  template <typename DataOutType>
665  void write_description_files (const DataOutType &data_out,
666  const std::string &solution_file_prefix,
667  const std::vector<std::string> &filenames,
668  OutputHistory &output_history) const;
669 
670 
680  template <typename DataOutType>
681  std::string write_data_out_data(DataOutType &data_out,
682  OutputHistory &output_history,
683  const std::map<std::string,std::string> &visualization_field_names_and_units) const;
684  };
685  }
686 
687 
694 #define ASPECT_REGISTER_VISUALIZATION_POSTPROCESSOR(classname,name,description) \
695  template class classname<2>; \
696  template class classname<3>; \
697  namespace ASPECT_REGISTER_VISUALIZATION_POSTPROCESSOR_ ## classname \
698  { \
699  aspect::internal::Plugins::RegisterHelper<aspect::Postprocess::VisualizationPostprocessors::Interface<2>,classname<2>> \
700  dummy_ ## classname ## _2d (&aspect::Postprocess::Visualization<2>::register_visualization_postprocessor, \
701  name, description); \
702  aspect::internal::Plugins::RegisterHelper<aspect::Postprocess::VisualizationPostprocessors::Interface<3>,classname<3>> \
703  dummy_ ## classname ## _3d (&aspect::Postprocess::Visualization<3>::register_visualization_postprocessor, \
704  name, description); \
705  }
706 }
707 
708 
709 #endif
virtual void parse_parameters(ParameterHandler &prm)
void write_plugin_graph(std::ostream &output_stream)
std::vector< std::pair< double, std::string > > times_and_pvtu_names
virtual std::list< std::string > required_other_postprocessors() const
virtual void load(const std::map< std::string, std::string > &status_strings)
std::list< std::unique_ptr< VisualizationPostprocessors::Interface< dim > > > postprocessors
Interface(const std::string &physical_units="")
void average_quantities(std::vector< Vector< double >> &quantities)
Definition: visualization.h:45
std::vector< std::vector< std::string > > output_file_names_by_timestep
virtual void save(std::map< std::string, std::string > &status_strings) const
void average(const AveragingOperation operation, const typename DoFHandler< dim >::active_cell_iterator &cell, const Quadrature< dim > &quadrature_formula, const Mapping< dim > &mapping, const MaterialProperties::Property &requested_properties, MaterialModelOutputs< dim > &values_out)
static void declare_parameters(ParameterHandler &prm)
DeclException1(ProbabilityFunctionNegative, Point< dim >,<< "Your probability density function in the particle generator " "returned a negative probability density for the following position: "<< arg1<< ". Please check your function expression.")