ASPECT
interface.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_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  template <int dim> class Simulator;
42  template <int dim> class SimulatorAccess;
43 
44 
51  namespace Postprocess
52  {
53 
68  template <int dim>
70  {
71  public:
89  virtual
90  std::pair<std::string,std::string>
91  execute (TableHandler &statistics) = 0;
92 
115  virtual
116  std::list<std::string>
118 
140  virtual
141  void save (std::map<std::string, std::string> &status_strings) const;
142 
154  virtual
155  void load (const std::map<std::string, std::string> &status_strings);
156  };
157 
158 
159 
160 
161 
162 
172  template <int dim>
173  class Manager : public Plugins::ManagerBase<Interface<dim>>, public SimulatorAccess<dim>
174  {
175  public:
184  std::list<std::pair<std::string,std::string>>
185  execute (TableHandler &statistics);
186 
201  template <typename PostprocessorType,
202  typename = typename std::enable_if_t<std::is_base_of<Interface<dim>,PostprocessorType>::value>>
203  DEAL_II_DEPRECATED
204  bool
205  has_matching_postprocessor () const;
206 
223  template <typename PostprocessorType,
224  typename = typename std::enable_if_t<std::is_base_of<Interface<dim>,PostprocessorType>::value>>
225  DEAL_II_DEPRECATED
226  const PostprocessorType &
227  get_matching_postprocessor () const;
228 
233  static
234  void
235  declare_parameters (ParameterHandler &prm);
236 
242  void
243  parse_parameters (ParameterHandler &prm) override;
244 
249  template <class Archive>
250  void save (Archive &ar,
251  const unsigned int version) const;
252 
257  template <class Archive>
258  void load (Archive &ar,
259  const unsigned int version);
260 
261  BOOST_SERIALIZATION_SPLIT_MEMBER()
262 
263 
264 
281  static
282  void
283  register_postprocessor (const std::string &name,
284  const std::string &description,
285  void (*declare_parameters_function) (ParameterHandler &),
286  std::unique_ptr<Interface<dim>> (*factory_function) ());
287 
297  static
298  void
299  write_plugin_graph (std::ostream &output_stream);
300 
304  DeclException1 (ExcPostprocessorNameNotFound,
305  std::string,
306  << "Could not find entry <"
307  << arg1
308  << "> among the names of registered postprocessors.");
309  };
310 
311 
312  /* -------------------------- inline and template functions ---------------------- */
313 
314  template <int dim>
315  template <class Archive>
316  void Manager<dim>::save (Archive &ar,
317  const unsigned int) const
318  {
319  // let all the postprocessors save their data in a map and then
320  // serialize that
321  std::map<std::string,std::string> saved_text;
322  for (const auto &p : this->plugin_objects)
323  p->save (saved_text);
324 
325  ar &saved_text;
326  }
327 
328 
329  template <int dim>
330  template <class Archive>
331  void Manager<dim>::load (Archive &ar,
332  const unsigned int)
333  {
334  // get the map back out of the stream; then let the postprocessors
335  // that we currently have get their data from there. note that this
336  // may not be the same set of postprocessors we had when we saved
337  // their data
338  std::map<std::string,std::string> saved_text;
339  ar &saved_text;
340 
341  for (auto &p : this->plugin_objects)
342  p->load (saved_text);
343  }
344 
345 
346 
347  template <int dim>
348  template <typename PostprocessorType, typename>
349  inline
350  bool
352  {
353  return this->template has_matching_active_plugin<PostprocessorType>();
354  }
355 
356 
357 
358  template <int dim>
359  template <typename PostprocessorType, typename>
360  inline
361  const PostprocessorType &
363  {
364  return this->template get_matching_active_plugin<PostprocessorType>();
365  }
366 
367 
375 #define ASPECT_REGISTER_POSTPROCESSOR(classname,name,description) \
376  template class classname<2>; \
377  template class classname<3>; \
378  namespace ASPECT_REGISTER_POSTPROCESSOR_ ## classname \
379  { \
380  aspect::internal::Plugins::RegisterHelper<aspect::Postprocess::Interface<2>,classname<2>> \
381  dummy_ ## classname ## _2d (&aspect::Postprocess::Manager<2>::register_postprocessor, \
382  name, description); \
383  aspect::internal::Plugins::RegisterHelper<aspect::Postprocess::Interface<3>,classname<3>> \
384  dummy_ ## classname ## _3d (&aspect::Postprocess::Manager<3>::register_postprocessor, \
385  name, description); \
386  }
387  }
388 }
389 
390 
391 #endif
virtual void save(std::map< std::string, std::string > &status_strings) const
virtual void parse_parameters(ParameterHandler &prm)
void write_plugin_graph(std::ostream &output_stream)
DEAL_II_DEPRECATED const PostprocessorType & get_matching_postprocessor() const
virtual std::pair< std::string, std::string > execute(TableHandler &statistics)=0
void load(Archive &ar, const unsigned int version)
Definition: interface.h:331
Definition: compat.h:59
void save(Archive &ar, const unsigned int version) const
Definition: interface.h:316
DEAL_II_DEPRECATED bool has_matching_postprocessor() const
virtual std::list< std::string > required_other_postprocessors() const
static void declare_parameters(ParameterHandler &prm)
virtual void load(const std::map< std::string, std::string > &status_strings)
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.")