ASPECT
interface.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2011 - 2023 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_interface_h
23 #define _aspect_postprocess_interface_h
24 
25 #include <aspect/global.h>
26 #include <aspect/plugins.h>
28 
29 #include <memory>
30 #include <deal.II/base/table_handler.h>
31 #include <deal.II/base/parameter_handler.h>
32 
33 #include <boost/serialization/split_member.hpp>
34 #include <boost/core/demangle.hpp>
35 
36 #include <typeinfo>
37 
38 
39 namespace aspect
40 {
41  using namespace dealii;
42 
43  template <int dim> class Simulator;
44  template <int dim> class SimulatorAccess;
45 
46 
53  namespace Postprocess
54  {
55 
70  template <int dim>
72  {
73  public:
91  virtual
92  std::pair<std::string,std::string>
93  execute (TableHandler &statistics) = 0;
94 
117  virtual
118  std::list<std::string>
119  required_other_postprocessors () const;
120 
142  virtual
143  void save (std::map<std::string, std::string> &status_strings) const;
144 
156  virtual
157  void load (const std::map<std::string, std::string> &status_strings);
158  };
159 
160 
161 
162 
163 
164 
174  template <int dim>
175  class Manager : public Plugins::ManagerBase<Interface<dim>>, public SimulatorAccess<dim>
176  {
177  public:
186  std::list<std::pair<std::string,std::string>>
187  execute (TableHandler &statistics);
188 
203  template <typename PostprocessorType,
204  typename = typename std::enable_if_t<std::is_base_of<Interface<dim>,PostprocessorType>::value>>
206  bool
207  has_matching_postprocessor () const;
208 
225  template <typename PostprocessorType,
226  typename = typename std::enable_if_t<std::is_base_of<Interface<dim>,PostprocessorType>::value>>
228  const PostprocessorType &
229  get_matching_postprocessor () const;
230 
235  static
236  void
237  declare_parameters (ParameterHandler &prm);
238 
244  void
245  parse_parameters (ParameterHandler &prm) override;
246 
251  template <class Archive>
252  void save (Archive &ar,
253  const unsigned int version) const;
254 
259  template <class Archive>
260  void load (Archive &ar,
261  const unsigned int version);
262 
263  BOOST_SERIALIZATION_SPLIT_MEMBER()
264 
265 
266 
283  static
284  void
285  register_postprocessor (const std::string &name,
286  const std::string &description,
287  void (*declare_parameters_function) (ParameterHandler &),
288  std::unique_ptr<Interface<dim>> (*factory_function) ());
289 
299  static
300  void
301  write_plugin_graph (std::ostream &output_stream);
302 
306  DeclException1 (ExcPostprocessorNameNotFound,
307  std::string,
308  << "Could not find entry <"
309  << arg1
310  << "> among the names of registered postprocessors.");
311  };
312 
313 
314  /* -------------------------- inline and template functions ---------------------- */
315 
316  template <int dim>
317  template <class Archive>
318  void Manager<dim>::save (Archive &ar,
319  const unsigned int) const
320  {
321  // let all the postprocessors save their data in a map and then
322  // serialize that
323  std::map<std::string,std::string> saved_text;
324  for (const auto &p : this->plugin_objects)
325  p->save (saved_text);
326 
327  ar &saved_text;
328  }
329 
330 
331  template <int dim>
332  template <class Archive>
333  void Manager<dim>::load (Archive &ar,
334  const unsigned int)
335  {
336  // get the map back out of the stream; then let the postprocessors
337  // that we currently have get their data from there. note that this
338  // may not be the same set of postprocessors we had when we saved
339  // their data
340  std::map<std::string,std::string> saved_text;
341  ar &saved_text;
342 
343  for (auto &p : this->plugin_objects)
344  p->load (saved_text);
345  }
346 
347 
348 
349  template <int dim>
350  template <typename PostprocessorType, typename>
351  inline
352  bool
354  {
355  return this->template has_matching_active_plugin<PostprocessorType>();
356  }
357 
358 
359 
360  template <int dim>
361  template <typename PostprocessorType, typename>
362  inline
363  const PostprocessorType &
365  {
366  return this->template get_matching_active_plugin<PostprocessorType>();
367  }
368 
369 
377 #define ASPECT_REGISTER_POSTPROCESSOR(classname,name,description) \
378  template class classname<2>; \
379  template class classname<3>; \
380  namespace ASPECT_REGISTER_POSTPROCESSOR_ ## classname \
381  { \
382  aspect::internal::Plugins::RegisterHelper<aspect::Postprocess::Interface<2>,classname<2>> \
383  dummy_ ## classname ## _2d (&aspect::Postprocess::Manager<2>::register_postprocessor, \
384  name, description); \
385  aspect::internal::Plugins::RegisterHelper<aspect::Postprocess::Interface<3>,classname<3>> \
386  dummy_ ## classname ## _3d (&aspect::Postprocess::Manager<3>::register_postprocessor, \
387  name, description); \
388  }
389  }
390 }
391 
392 
393 #endif
StructuredDataLookup< dim > DEAL_II_DEPRECATED
void write_plugin_graph(std::ostream &output_stream)
void load(Archive &ar, const unsigned int version)
Definition: interface.h:333
Definition: compat.h:59
void save(Archive &ar, const unsigned int version) const
Definition: interface.h:318
void declare_parameters(ParameterHandler &prm)
Definition: compat.h:42
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.")