Hermes2D  2.0
calculation_continuity.h
1 // This file is part of Hermes2D
2 //
3 // Copyright (c) 2009 hp-FEM group at the University of Nevada, Reno (UNR).
4 // Email: hpfem-group@unr.edu, home page: http://hpfem.org/.
5 //
6 // Hermes2D is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published
8 // by the Free Software Foundation; either version 2 of the License,
9 // or (at your option) any later version.
10 //
11 // Hermes2D 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 Hermes2D; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #include "config.h"
24 #include "compat.h"
25 #include "function/solution.h"
26 
27 namespace Hermes
28 {
29  namespace Hermes2D
30  {
32  class HERMES_API CalculationContinuityException : public Hermes::Exceptions::Exception
33  {
34  public:
35  enum exceptionEntityType
36  {
37  meshes,
38  spaces,
39  solutions,
40  time_steps,
41  error,
42  general
43  };
45  CalculationContinuityException(exceptionEntityType type, const char * msg);
46  void init(exceptionEntityType type, const char * msg);
47  };
48 
51  {
52  public:
53  enum inputOutput
54  {
55  input,
56  output
57  };
58  IOCalculationContinuityException(exceptionEntityType type, inputOutput inputOutput, const char * filename);
59  IOCalculationContinuityException(exceptionEntityType type, inputOutput inputOutput, const char * filename, const char * reason);
60  };
61 
64  template<typename Scalar>
65  class HERMES_API CalculationContinuity
66  {
67  public:
71  {
72  timeAndNumber,
73  onlyTime,
74  onlyNumber
75  };
76 
77  CalculationContinuity(IdentificationMethod identification_method);
78 
80  class HERMES_API Record
81  {
82  public:
84  Record(double time, unsigned int number);
85  Record(double time);
86  Record(unsigned int number);
87 
89  void save_meshes(Hermes::vector<Mesh*> meshes);
91  void save_mesh(Mesh* mesh);
92 
94  void save_spaces(Hermes::vector<Space<Scalar>*> spaces);
96  void save_space(Space<Scalar>* space);
97 
99  void save_solutions(Hermes::vector<Solution<Scalar>*> solutions);
101  void save_solution(Solution<Scalar>* solution);
102 
104  void save_time_step_length(double time_step_length_to_save);
105  void save_time_step_length_n_minus_one(double time_step_length_to_save);
106 
108  void save_error(double error);
109 
111  void load_meshes(Hermes::vector<Mesh*> meshes);
113  void load_mesh(Mesh* mesh);
114 
116  Hermes::vector<Space<Scalar>*> load_spaces(Hermes::vector<Mesh*> meshes, Hermes::vector<EssentialBCs<Scalar>*> essential_bcs, Hermes::vector<Shapeset*> shapeset = Hermes::vector<Shapeset*>());
117 
120  Hermes::vector<Space<Scalar>*> load_spaces(Hermes::vector<Mesh*> meshes, Hermes::vector<Shapeset*> shapeset = Hermes::vector<Shapeset*>());
121 
123  Space<Scalar>* load_space(Mesh* mesh, EssentialBCs<Scalar>* essential_bcs = NULL, Shapeset* shapeset = NULL);
124 
126  void load_solutions(Hermes::vector<Solution<Scalar>*> solutions, Hermes::vector<Space<Scalar>*> spaces);
128  void load_solution(Solution<Scalar>* solution, Space<Scalar>* space);
129 
131  void load_time_step_length(double & time_step_length);
132  void load_time_step_length_n_minus_one(double & time_step_length);
133 
135  void load_error(double & error);
136 
138  double get_time();
139 
141  unsigned int get_number();
142 
143  private:
145  Hermes::vector<std::string> meshFiles;
147  Hermes::vector<std::string> spaceFiles;
149  Hermes::vector<std::string> solutionFiles;
150 
152  double time;
153  unsigned int number;
154  };
155 
158  void add_record(double time, unsigned int number, Mesh* mesh, Space<Scalar>* space = NULL, Solution<Scalar>* sln = NULL, double time_step = 0.0, double time_step_n_minus_one = 0.0, double error = 0.0);
159  void add_record(double time, unsigned int number, Hermes::vector<Mesh*> meshes, Hermes::vector<Space<Scalar>*> spaces = Hermes::vector<Space<Scalar>*>(), Hermes::vector<Solution<Scalar>*> slns = Hermes::vector<Solution<Scalar>*>(), double time_step = 0.0, double time_step_n_minus_one = 0.0, double error = 0.0);
160 
163  void add_record(double time, Mesh* mesh, Space<Scalar>* space = NULL, Solution<Scalar>* sln = NULL, double time_step = 0.0, double time_step_n_minus_one = 0.0, double error = 0.0);
164  void add_record(double time, Hermes::vector<Mesh*> meshes, Hermes::vector<Space<Scalar>*> spaces = Hermes::vector<Space<Scalar>*>(), Hermes::vector<Solution<Scalar>*> slns = Hermes::vector<Solution<Scalar>*>(), double time_step = 0.0, double time_step_n_minus_one = 0.0, double error = 0.0);
165 
168  void add_record(unsigned int number, Mesh* mesh, Space<Scalar>* space = NULL, Solution<Scalar>* sln = NULL, double time_step = 0.0, double time_step_n_minus_one = 0.0, double error = 0.0);
169  void add_record(unsigned int number, Hermes::vector<Mesh*> meshes, Hermes::vector<Space<Scalar>*> spaces = Hermes::vector<Space<Scalar>*>(), Hermes::vector<Solution<Scalar>*> slns = Hermes::vector<Solution<Scalar>*>(), double time_step = 0.0, double time_step_n_minus_one = 0.0, double error = 0.0);
170 
173  bool have_record_available();
174 
176  Record* get_last_record() const;
177 
179  int get_num() const;
180 
182  static void set_mesh_file_name(std::string mesh_file_nameToSet);
183  static void set_space_file_name(std::string space_file_nameToSet);
184  static void set_solution_file_name(std::string solution_file_nameToSet);
185  static void set_time_step_file_name(std::string time_step_file_nameToSet);
186  static void set_error_file_name(std::string error_file_nameToSet);
187 
188  private:
190  static std::string mesh_file_name;
191  static std::string space_file_name;
192  static std::string solution_file_name;
193  static std::string time_step_file_name;
194  static std::string time_stepNMinusOne_file_name;
195  static std::string error_file_name;
196 
198  std::map<std::pair<double, unsigned int>, Record*> records;
199 
201  std::map<double, Record*> time_records;
202 
204  std::map<unsigned int, Record*> numbered_records;
205 
207  Record* last_record;
208 
210  bool record_available;
211 
213  IdentificationMethod identification_method;
214 
216  int num;
217 
218  friend class Record;
219  };
220  }
221 }