OpenFCST: The open-source Fuel Cell Simulation Toolbox
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
application_base.h
Go to the documentation of this file.
1 // ------------------------------------------------------------------
2 // $Id: application_base.h 1348 2013-08-16 00:45:07Z secanell $
3 //
4 // Copyright (C) 2006, 2007, 2008, 2009 by Guido Kanschat.
5 // Copyright (C) 2012 by Valentin N. Zingan, University of Alberta.
6 //
7 // This file is subject to QPL and may not be distributed
8 // without copyright and license information. Please refer
9 // to the file deal.II/doc/license.html for the text and
10 // further information on this license.
11 // ------------------------------------------------------------------
12 
13 #ifndef _DEALII_APPFRAME_APPLICATION_BASE_H_
14 #define _DEALII_APPFRAME_APPLICATION_BASE_H_
15 
16 #include <base/parameter_handler.h>
17 
18 #include <boost/shared_ptr.hpp>
19 
20 #include <appframe/fe_vectors.h>
22 #include <appframe/event.h>
23 
24 using namespace dealii;
25 
26 namespace AppFrame
27 {
28 
33 
75 // ------------------------------
76 
77 class ApplicationBase : public Subscriptor
78 {
79 public:
80 
99  ApplicationBase(boost::shared_ptr<ApplicationData> ex_data = boost::shared_ptr<ApplicationData>());
100 
109  ApplicationBase(const ApplicationBase& other);
110 
114  virtual ~ApplicationBase() { }
115 
124  virtual void declare_parameters(ParameterHandler& param) = 0; // No implementation here
125 
137  void print_parameters_to_file(ParameterHandler& param,
138  const std::string& file_name,
139  const ParameterHandler::OutputStyle& style);
140 
158  virtual void initialize(ParameterHandler& param) = 0; // No implementation here
159 
165  virtual void remesh();
166 
171  virtual void init_vector(FEVector& dst) const;
172 
177  virtual void start_vector(FEVector& dst,
178  std::string caller) const;
179 
187  virtual double residual(FEVector& dst,
188  const FEVectors& src,
189  bool apply_boundaries = true);
190 
197  virtual void solve(FEVector& start,
198  const FEVectors& rhs);
199 
206  virtual void Tsolve(FEVector& start,
207  const FEVectors& rhs);
208 
212  virtual double estimate(const FEVectors& src);
213 
218  virtual double evaluate(const FEVectors& src);
219 
224  virtual void grid_out(const std::string& filename) const;
225 
230  virtual void data_out(const std::string& filename,
231  const FEVectors& src);
232 
233  virtual void data_out(const std::string& filename,
234  const FEVectors& src,
235  const std::vector<std::string> );
236 
240  boost::shared_ptr<ApplicationData> get_data() { return data; }
241 
245  const boost::shared_ptr<ApplicationData> get_data() const { return data; }
246 
259  virtual std::string id() const { return std::string( typeid(*this).name() ); }
260 
267  virtual void notify(const Event& reason) { notifications += reason; }
268 
277  virtual void clear() { notifications.all(); }
278 
282  void clear_events() { notifications.clear(); }
283 
284 protected:
285 
289  void print_caller_name(const std::string& caller_name) const;
290 
299  boost::shared_ptr<ApplicationData> data;
300 
310 };
311 
312 // ------------------------------
313 
314 inline
315 ApplicationBase::ApplicationBase(boost::shared_ptr<ApplicationData> ex_data)
316 :
317 Subscriptor(),
318 data(ex_data)
319 {
320  deallog << " Application";
321  notifications.all();
322 
323  if(!data) //if(data == NULL)
324  data = boost::shared_ptr<ApplicationData>(new ApplicationData);
325 }
326 
327 inline
329 :
330 Subscriptor(),
331 data(other.data)
332 {
333  deallog << "Base->";
334  notifications.all();
335 }
336 
337 inline
338 void
340  const std::string& file_name,
341  const ParameterHandler::OutputStyle& style)
342 {
343  std::ofstream file_out;
344  file_out.open(file_name.c_str());
345  deallog << "Printing parameter handler" << std::endl;
346  param.print_parameters(file_out, style);
347  file_out.close();
348 }
349 
350 inline
351 void
353 {
354  print_caller_name(__FUNCTION__);
355 }
356 
357 inline
358 void
360 {
361  print_caller_name(__FUNCTION__);
362 }
363 
364 inline
365 void
367  std::string) const
368 {
369  print_caller_name(__FUNCTION__);
370  init_vector(dst);
371 }
372 
373 inline
374 double
376  const FEVectors&,
377  bool)
378 {
379  print_caller_name(__FUNCTION__);
380  return 0.;
381 }
382 
383 inline
384 void
386  const FEVectors&)
387 {
388  print_caller_name(__FUNCTION__);
389 }
390 
391 inline
392 void
394  const FEVectors&)
395 {
396  print_caller_name(__FUNCTION__);
397 }
398 
399 inline
400 double
402 {
403  print_caller_name(__FUNCTION__);
404  return 0.;
405 }
406 
407 inline
408 double
410 {
411  print_caller_name(__FUNCTION__);
412  return 0.;
413 }
414 
415 inline
416 void
417 ApplicationBase::grid_out(const std::string&) const
418 {
419  print_caller_name(__FUNCTION__);
420 }
421 
422 inline
423 void
424 ApplicationBase::data_out(const std::string&,
425  const FEVectors&)
426 {
427  print_caller_name(__FUNCTION__);
428 }
429 
430 inline
431 void
432 ApplicationBase::data_out(const std::string&,
433  const FEVectors&,
434  const std::vector<std::string> )
435 {
436  print_caller_name(__FUNCTION__);
437 }
438 
439 inline
440 void
441 ApplicationBase::print_caller_name(const std::string& caller_name) const
442 {
443  const std::type_info& info = typeid(*this);
444  deallog << "Pure function " << caller_name << " called in Class " << info.name() << std::endl;
445 }
446 
447 }
448 
449 #endif