Hermes2D  2.0
calculation_continuity.cpp
1 // This file is part of Hermes2D
2 //
3 // Hermes2D is free software; you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation; either version 2 of the License, or
6 // (at your option) any later version.
7 //
8 // Hermes2D is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with Hermes2D; if not, see <http://www.gnu.prg/licenses/>.
15 
16 #include "calculation_continuity.h"
17 #include "mesh_reader_h2d_xml.h"
18 #include "space_h1.h"
19 #include "space_hdiv.h"
20 #include "space_hcurl.h"
21 #include "space_l2.h"
22 #include <fstream>
23 
24 namespace Hermes
25 {
26  namespace Hermes2D
27  {
28  CalculationContinuityException::CalculationContinuityException() : Exception()
29  {
30  }
31 
32  CalculationContinuityException::CalculationContinuityException(exceptionEntityType type, const char * reason) : Exception()
33  {
34  this->init(type, reason);
35  }
36 
37  void CalculationContinuityException::init(exceptionEntityType type, const char * reason)
38  {
39  char * msg = new char[34 + strlen(reason)];
40  char * typeMsg = new char[15];
41  switch(type)
42  {
43  case meshes:
44  sprintf(typeMsg, "meshes");
45  break;
46  case spaces:
47  sprintf(typeMsg, "spaces");
48  break;
49  case solutions:
50  sprintf(typeMsg, "solutions");
51  break;
52  case time_steps:
53  sprintf(typeMsg, "time steps");
54  break;
55  case error:
56  sprintf(typeMsg, "error info");
57  break;
58  case general:
59  sprintf(typeMsg, "general");
60  break;
61  }
62 
63  sprintf(msg, "Exception in CalculationContinuity (%s): \"%s\"", typeMsg, reason);
64  message = msg;
65  delete [] typeMsg;
66  }
67 
68  IOCalculationContinuityException::IOCalculationContinuityException(exceptionEntityType type, inputOutput inputOutput, const char * filename) : CalculationContinuityException()
69  {
70  char * msg = new char[34 + strlen(filename)];
71  char * typeMsg = new char[7];
72  switch(inputOutput)
73  {
74  case input:
75  sprintf(typeMsg, "input");
76  break;
77  case output:
78  sprintf(typeMsg, "output");
79  break;
80  }
81  sprintf(msg, "I/O exception: %s, filename: \"%s\"", typeMsg, filename);
82  this->init(type, msg);
83  }
84 
85  IOCalculationContinuityException::IOCalculationContinuityException(exceptionEntityType type, inputOutput inputOutput, const char * filename, const char * reason) : CalculationContinuityException()
86  {
87  char * msg = new char[34 + strlen(filename)];
88  char * typeMsg = new char[7];
89  switch(inputOutput)
90  {
91  case input:
92  sprintf(typeMsg, "input");
93  break;
94  case output:
95  sprintf(typeMsg, "output");
96  break;
97  }
98  sprintf(msg, "I/O exception: %s, filename: \"%s\", reason: %s", typeMsg, filename, reason);
99  this->init(type, msg);
100  }
101 
102  template<typename Scalar>
103  CalculationContinuity<Scalar>::CalculationContinuity(IdentificationMethod identification_method) : last_record(NULL), record_available(false), identification_method(identification_method), num(0)
104  {
105  double last_time;
106  unsigned int last_number;
107  std::stringstream ss;
108  switch(identification_method)
109  {
110  case timeAndNumber:
111  ss << "timeAndNumber.h2d";
112  break;
113  case onlyTime:
114  ss << "onlyTime.h2d";
115  break;
116  case onlyNumber:
117  ss << "onlyNumber.h2d";
118  break;
119  }
120 
121  std::ifstream ifile(ss.str().c_str());
122  if(ifile)
123  {
124  while(!ifile.eof())
125  {
126  switch(identification_method)
127  {
128  case timeAndNumber:
129  ifile >> this->num >> last_time >> last_number;
130  record_available = true;
131  break;
132  case onlyTime:
133  ifile >> this->num >> last_time;
134  record_available = true;
135  break;
136  case onlyNumber:
137  ifile >> this->num >> last_number;
138  record_available = true;
139  break;
140  }
141  }
142  ifile.close();
143 
144  CalculationContinuity<Scalar>::Record* record;
145  switch(identification_method)
146  {
147  case timeAndNumber:
148  record = new CalculationContinuity<Scalar>::Record(last_time, last_number);
149  this->records.insert(std::pair<std::pair<double, unsigned int>, CalculationContinuity<Scalar>::Record*>(std::pair<double, unsigned int>(last_time, last_number), record));
150  this->last_record = record;
151  break;
152  case onlyTime:
153  record = new CalculationContinuity<Scalar>::Record(last_time);
154  this->time_records.insert(std::pair<double, CalculationContinuity<Scalar>::Record*>(last_time, record));
155  this->last_record = record;
156  break;
157  case onlyNumber:
158  record = new CalculationContinuity<Scalar>::Record(last_number);
159  this->numbered_records.insert(std::pair<unsigned int, CalculationContinuity<Scalar>::Record*>(last_number, record));
160  this->last_record = record;
161  break;
162  }
163  }
164  }
165 
166  template<typename Scalar>
167  void CalculationContinuity<Scalar>::add_record(double time, unsigned int number, Mesh* mesh, Space<Scalar>* space, Solution<Scalar>* sln, double time_step, double time_step_n_minus_one, double error)
168  {
169  std::ofstream ofile("timeAndNumber.h2d", std::ios_base::app);
170  if(ofile)
171  {
172  ofile << ++this->num << ' ' << time << ' ' << number << std::endl;
173  ofile.close();
174  }
175  else
176  throw IOCalculationContinuityException(CalculationContinuityException::general, IOCalculationContinuityException::output, "timeAndNumber.h2d");
177 
179  record->save_mesh(mesh);
180  if(space != NULL)
181  record->save_space(space);
182  if(sln != NULL)
183  record->save_solution(sln);
184  if(time_step > 0.0)
185  record->save_time_step_length(time_step);
186  if(time_step_n_minus_one > 0.0)
187  record->save_time_step_length_n_minus_one(time_step_n_minus_one);
188  if(error > 0.0)
189  record->save_error(error);
190 
191  this->records.insert(std::pair<std::pair<double, unsigned int>, CalculationContinuity<Scalar>::Record*>(std::pair<double, unsigned int>(time, number), record));
192  this->last_record = record;
193  }
194 
195  template<typename Scalar>
196  void CalculationContinuity<Scalar>::add_record(double time, unsigned int number, Hermes::vector<Mesh*> meshes, Hermes::vector<Space<Scalar>*> spaces, Hermes::vector<Solution<Scalar>*> slns, double time_step, double time_step_n_minus_one, double error)
197  {
198  std::ofstream ofile("timeAndNumber.h2d", std::ios_base::app);
199  if(ofile)
200  {
201  ofile << ++this->num << ' ' << time << ' ' << number << std::endl;
202  ofile.close();
203  }
204  else
205  throw IOCalculationContinuityException(CalculationContinuityException::general, IOCalculationContinuityException::output, "timeAndNumber.h2d");
206 
207  CalculationContinuity<Scalar>::Record* record = new CalculationContinuity<Scalar>::Record(time, number);
208  record->save_meshes(meshes);
209  if(spaces != Hermes::vector<Space<Scalar>*>())
210  record->save_spaces(spaces);
211  if(slns != Hermes::vector<Solution<Scalar>*>())
212  record->save_solutions(slns);
213  if(time_step > 0.0)
214  record->save_time_step_length(time_step);
215  if(time_step_n_minus_one > 0.0)
216  record->save_time_step_length_n_minus_one(time_step_n_minus_one);
217  if(error > 0.0)
218  record->save_error(error);
219 
220  this->records.insert(std::pair<std::pair<double, unsigned int>, CalculationContinuity<Scalar>::Record*>(std::pair<double, unsigned int>(time, number), record));
221  this->last_record = record;
222  }
223 
224  template<typename Scalar>
225  void CalculationContinuity<Scalar>::add_record(double time, Mesh* mesh, Space<Scalar>* space, Solution<Scalar>* sln, double time_step, double time_step_n_minus_one, double error)
226  {
227  std::ofstream ofile("onlyTime.h2d", std::ios_base::app);
228  if(ofile)
229  {
230  ofile << ++this->num << ' ' << time << std::endl;
231  ofile.close();
232  }
233  else
234  throw IOCalculationContinuityException(CalculationContinuityException::general, IOCalculationContinuityException::output, "onlyTime.h2d");
235 
237  record->save_mesh(mesh);
238  if(space != NULL)
239  record->save_space(space);
240  if(sln != NULL)
241  record->save_solution(sln);
242  if(time_step > 0.0)
243  record->save_time_step_length(time_step);
244  if(time_step_n_minus_one > 0.0)
245  record->save_time_step_length_n_minus_one(time_step_n_minus_one);
246  if(error > 0.0)
247  record->save_error(error);
248 
249  this->time_records.insert(std::pair<double, CalculationContinuity<Scalar>::Record*>(time, record));
250  this->last_record = record;
251  }
252 
253  template<typename Scalar>
254  void CalculationContinuity<Scalar>::add_record(double time, Hermes::vector<Mesh*> meshes, Hermes::vector<Space<Scalar>*> spaces, Hermes::vector<Solution<Scalar>*> slns, double time_step, double time_step_n_minus_one, double error)
255  {
256  std::ofstream ofile("onlyTime.h2d", std::ios_base::app);
257  if(ofile)
258  {
259  ofile << ++this->num << ' ' << time << std::endl;
260  ofile.close();
261  }
262  else
263  throw IOCalculationContinuityException(CalculationContinuityException::general, IOCalculationContinuityException::output, "onlyTime.h2d");
264  CalculationContinuity<Scalar>::Record* record = new CalculationContinuity<Scalar>::Record(time);
265  record->save_meshes(meshes);
266  if(spaces != Hermes::vector<Space<Scalar>*>())
267  record->save_spaces(spaces);
268  if(slns != Hermes::vector<Solution<Scalar>*>())
269  record->save_solutions(slns);
270  if(time_step > 0.0)
271  record->save_time_step_length(time_step);
272  if(time_step_n_minus_one > 0.0)
273  record->save_time_step_length_n_minus_one(time_step_n_minus_one);
274  if(error > 0.0)
275  record->save_error(error);
276  this->time_records.insert(std::pair<double, CalculationContinuity<Scalar>::Record*>(time, record));
277  this->last_record = record;
278  }
279 
280  template<typename Scalar>
281  void CalculationContinuity<Scalar>::add_record(unsigned int number, Mesh* mesh, Space<Scalar>* space, Solution<Scalar>* sln, double time_step, double time_step_n_minus_one, double error)
282  {
283  std::ofstream ofile("onlyNumber.h2d", std::ios_base::app);
284  if(ofile)
285  {
286  ofile << ++this->num << ' ' << number << std::endl;
287  ofile.close();
288  }
289  else
290  throw IOCalculationContinuityException(CalculationContinuityException::general, IOCalculationContinuityException::output, "onlyNumber.h2d");
291 
293  record->save_mesh(mesh);
294  if(space != NULL)
295  record->save_space(space);
296  if(sln != NULL)
297  record->save_solution(sln);
298  if(time_step > 0.0)
299  record->save_time_step_length(time_step);
300  if(time_step_n_minus_one > 0.0)
301  record->save_time_step_length_n_minus_one(time_step_n_minus_one);
302  if(error > 0.0)
303  record->save_error(error);
304 
305  this->numbered_records.insert(std::pair<unsigned int, CalculationContinuity<Scalar>::Record*>(number, record));
306  this->last_record = record;
307  }
308 
309  template<typename Scalar>
310  void CalculationContinuity<Scalar>::add_record(unsigned int number, Hermes::vector<Mesh*> meshes, Hermes::vector<Space<Scalar>*> spaces, Hermes::vector<Solution<Scalar>*> slns, double time_step, double time_step_n_minus_one, double error)
311  {
312  std::ofstream ofile("onlyNumber.h2d", std::ios_base::app);
313  if(ofile)
314  {
315  ofile << ++this->num << ' ' << number << std::endl;
316  ofile.close();
317  }
318  else
319  throw IOCalculationContinuityException(CalculationContinuityException::general, IOCalculationContinuityException::output, "onlyNumber.h2d");
320 
321  CalculationContinuity<Scalar>::Record* record = new CalculationContinuity<Scalar>::Record(number);
322  record->save_meshes(meshes);
323  if(spaces != Hermes::vector<Space<Scalar>*>())
324  record->save_spaces(spaces);
325  if(slns != Hermes::vector<Solution<Scalar>*>())
326  record->save_solutions(slns);
327  if(time_step > 0.0)
328  record->save_time_step_length(time_step);
329  if(time_step_n_minus_one > 0.0)
330  record->save_time_step_length_n_minus_one(time_step_n_minus_one);
331  if(error > 0.0)
332  record->save_error(error);
333  this->numbered_records.insert(std::pair<unsigned int, CalculationContinuity<Scalar>::Record*>(number, record));
334  this->last_record = record;
335  }
336 
337  template<typename Scalar>
338  CalculationContinuity<Scalar>::Record::Record(double time, unsigned int number) : time(time), number(number)
339  {
340  }
341 
342  template<typename Scalar>
343  CalculationContinuity<Scalar>::Record::Record(double time) : time(time), number(0)
344  {
345  }
346 
347  template<typename Scalar>
348  CalculationContinuity<Scalar>::Record::Record(unsigned int number) : time(0.0), number(number)
349  {
350  }
351 
352  template<typename Scalar>
354  {
355  return this->record_available;
356  }
357 
358  template<typename Scalar>
360  {
361  if(this->last_record != NULL)
362  return this->last_record;
363  else
364  throw CalculationContinuityException(CalculationContinuityException::general, "no last_record in get_last_record()");
365  }
366 
367  template<typename Scalar>
369  {
370  return this->num;
371  }
372 
373  template<typename Scalar>
374  void CalculationContinuity<Scalar>::Record::save_meshes(Hermes::vector<Mesh*> meshes)
375  {
376  MeshReaderH2DXML reader;
377  for(unsigned int i = 0; i < meshes.size(); i++)
378  {
379  std::stringstream filename;
380  filename << CalculationContinuity<Scalar>::mesh_file_name << i << '_' << (std::string)"t = " << this->time << (std::string)"n = " << this->number << (std::string)".h2d";
381  try
382  {
383  reader.save(filename.str().c_str(), meshes[i]);
384  }
385  catch(std::exception& e)
386  {
387  throw IOCalculationContinuityException(CalculationContinuityException::meshes, IOCalculationContinuityException::output, filename.str().c_str(), e.what());
388  }
389  }
390  }
391  template<typename Scalar>
393  {
394  MeshReaderH2DXML reader;
395  std::stringstream filename;
396  filename << CalculationContinuity<Scalar>::mesh_file_name << 0 << '_' << (std::string)"t = " << this->time << (std::string)"n = " << this->number << (std::string)".h2d";
397  try
398  {
399  reader.save(filename.str().c_str(), mesh);
400  }
401  catch(std::exception& e)
402  {
403  throw IOCalculationContinuityException(CalculationContinuityException::meshes, IOCalculationContinuityException::output, filename.str().c_str(), e.what());
404  }
405  }
406 
407  template<typename Scalar>
409  {
410  for(unsigned int i = 0; i < spaces.size(); i++)
411  {
412  std::stringstream filename;
413  filename << CalculationContinuity<Scalar>::space_file_name << i << '_' << (std::string)"t = " << this->time << (std::string)"n = " << this->number << (std::string)".h2d";
414  try
415  {
416  spaces[i]->save(filename.str().c_str());
417  }
418  catch(std::exception& e)
419  {
420  throw IOCalculationContinuityException(CalculationContinuityException::spaces, IOCalculationContinuityException::output, filename.str().c_str(), e.what());
421  }
422  }
423  }
424 
425  template<typename Scalar>
427  {
428  std::stringstream filename;
429  filename << CalculationContinuity<Scalar>::space_file_name << 0 << '_' << (std::string)"t = " << this->time << (std::string)"n = " << this->number << (std::string)".h2d";
430  try
431  {
432  space->save(filename.str().c_str());
433  }
434  catch(std::exception& e)
435  {
436  throw IOCalculationContinuityException(CalculationContinuityException::spaces, IOCalculationContinuityException::output, filename.str().c_str(), e.what());
437  }
438  }
439 
440  template<typename Scalar>
442  {
443  for(unsigned int i = 0; i < solutions.size(); i++)
444  {
445  std::stringstream filename;
446  filename << CalculationContinuity<Scalar>::solution_file_name << i << '_' << (std::string)"t = " << this->time << (std::string)"n = " << this->number << (std::string)".h2d";
447 
448  try
449  {
450  solutions[i]->save(filename.str().c_str());
451  }
452  catch(Hermes::Exceptions::SolutionSaveFailureException& e)
453  {
454  throw IOCalculationContinuityException(CalculationContinuityException::solutions, IOCalculationContinuityException::output, filename.str().c_str(), e.what());
455  }
456  }
457  }
458  template<typename Scalar>
460  {
461  std::stringstream filename;
462  filename << CalculationContinuity<Scalar>::solution_file_name << 0 << '_' << (std::string)"t = " << this->time << (std::string)"n = " << this->number << (std::string)".h2d";
463  try
464  {
465  solution->save(filename.str().c_str());
466  }
467  catch(Hermes::Exceptions::SolutionSaveFailureException& e)
468  {
469  throw IOCalculationContinuityException(CalculationContinuityException::solutions, IOCalculationContinuityException::output, filename.str().c_str(), e.what());
470  }
471  }
472 
473  template<typename Scalar>
475  {
476  std::stringstream filename;
477  filename << CalculationContinuity<Scalar>::time_step_file_name << '_' << (std::string)"t = " << this->time << (std::string)"n = " << this->number << (std::string)".h2d";
478  try
479  {
480  std::ofstream out(filename.str().c_str());
481  out << time_step_length_to_save;
482  out.close();
483  }
484  catch(std::exception& e)
485  {
486  throw IOCalculationContinuityException(CalculationContinuityException::time_steps, IOCalculationContinuityException::output, filename.str().c_str(), e.what());
487  }
488  }
489 
490  template<typename Scalar>
492  {
493  std::stringstream filename;
494  filename << CalculationContinuity<Scalar>::time_stepNMinusOne_file_name << '_' << (std::string)"t = " << this->time << (std::string)"n = " << this->number << (std::string)".h2d";
495  try
496  {
497  std::ofstream out(filename.str().c_str());
498  out << time_step_length_to_save;
499  out.close();
500  }
501  catch(std::exception& e)
502  {
503  throw IOCalculationContinuityException(CalculationContinuityException::time_steps, IOCalculationContinuityException::output, filename.str().c_str(), e.what());
504  }
505  }
506 
507  template<typename Scalar>
509  {
510  std::stringstream filename;
511  filename << CalculationContinuity<Scalar>::error_file_name << '_' << (std::string)"t = " << this->time << (std::string)"n = " << this->number << (std::string)".h2d";
512  try
513  {
514  std::ofstream out(filename.str().c_str());
515  out << error;
516  out.close();
517  }
518  catch(std::exception& e)
519  {
520  throw IOCalculationContinuityException(CalculationContinuityException::error, IOCalculationContinuityException::output, filename.str().c_str(), e.what());
521  }
522  }
523 
524  template<typename Scalar>
525  void CalculationContinuity<Scalar>::Record::load_meshes(Hermes::vector<Mesh*> meshes)
526  {
527  MeshReaderH2DXML reader;
528  for(unsigned int i = 0; i < meshes.size(); i++)
529  {
530  std::stringstream filename;
531  filename << CalculationContinuity<Scalar>::mesh_file_name << i << '_' << (std::string)"t = " << this->time << (std::string)"n = " << this->number << (std::string)".h2d";
532  try
533  {
534  reader.load(filename.str().c_str(), meshes[i]);
535  }
536  catch(Hermes::Exceptions::MeshLoadFailureException& e)
537  {
538  throw IOCalculationContinuityException(CalculationContinuityException::meshes, IOCalculationContinuityException::input, filename.str().c_str(), e.what());
539  }
540  }
541  }
542  template<typename Scalar>
544  {
545  MeshReaderH2DXML reader;
546  std::stringstream filename;
547  filename << CalculationContinuity<Scalar>::mesh_file_name << 0 << '_' << (std::string)"t = " << this->time << (std::string)"n = " << this->number << (std::string)".h2d";
548 
549  try
550  {
551  reader.load(filename.str().c_str(), mesh);
552  }
553  catch(Hermes::Exceptions::MeshLoadFailureException& e)
554  {
555  throw IOCalculationContinuityException(CalculationContinuityException::meshes, IOCalculationContinuityException::input, filename.str().c_str(), e.what());
556  }
557  }
558 
559  template<typename Scalar>
560  Hermes::vector<Space<Scalar>*> CalculationContinuity<Scalar>::Record::load_spaces(Hermes::vector<Mesh*> meshes, Hermes::vector<EssentialBCs<Scalar>*> essential_bcs, Hermes::vector<Shapeset*> shapesets)
561  {
562  Hermes::vector<Space<Scalar>*> spaces;
563 
564  if(shapesets == Hermes::vector<Shapeset*>())
565  for(unsigned int i = 0; i < meshes.size(); i++)
566  shapesets.push_back(NULL);
567 
568  for(unsigned int i = 0; i < meshes.size(); i++)
569  {
570  std::stringstream filename;
571  filename << CalculationContinuity<Scalar>::space_file_name << i << '_' << (std::string)"t = " << this->time << (std::string)"n = " << this->number << (std::string)".h2d";
572 
573  try
574  {
575  spaces.push_back(Space<Scalar>::load(filename.str().c_str(), meshes[i], false, essential_bcs[i], shapesets[i]));
576  }
577  catch(Hermes::Exceptions::SpaceLoadFailureException& e)
578  {
579  throw IOCalculationContinuityException(CalculationContinuityException::spaces, IOCalculationContinuityException::input, filename.str().c_str(), e.what());
580  }
581  catch(std::exception& e)
582  {
583  throw IOCalculationContinuityException(CalculationContinuityException::spaces, IOCalculationContinuityException::input, filename.str().c_str(), e.what());
584  }
585  }
586  }
587 
588  template<typename Scalar>
589  Hermes::vector<Space<Scalar>*> CalculationContinuity<Scalar>::Record::load_spaces(Hermes::vector<Mesh*> meshes, Hermes::vector<Shapeset*> shapesets)
590  {
591  Hermes::vector<Space<Scalar>*> spaces;
592 
593  if(shapesets == Hermes::vector<Shapeset*>())
594  for(unsigned int i = 0; i < meshes.size(); i++)
595  shapesets.push_back(NULL);
596 
597  for(unsigned int i = 0; i < meshes.size(); i++)
598  {
599  std::stringstream filename;
600  filename << CalculationContinuity<Scalar>::space_file_name << i << '_' << (std::string)"t = " << this->time << (std::string)"n = " << this->number << (std::string)".h2d";
601 
602  try
603  {
604  spaces.push_back(Space<Scalar>::load(filename.str().c_str(), meshes[i], false, NULL, shapesets[i]));
605  }
606  catch(Hermes::Exceptions::SpaceLoadFailureException& e)
607  {
608  throw IOCalculationContinuityException(CalculationContinuityException::spaces, IOCalculationContinuityException::input, filename.str().c_str(), e.what());
609  }
610  catch(std::exception& e)
611  {
612  throw IOCalculationContinuityException(CalculationContinuityException::spaces, IOCalculationContinuityException::input, filename.str().c_str(), e.what());
613  }
614  }
615  }
616 
617  template<typename Scalar>
619  {
620  std::stringstream filename;
621  filename << CalculationContinuity<Scalar>::space_file_name << 0 << '_' << (std::string)"t = " << this->time << (std::string)"n = " << this->number << (std::string)".h2d";
622 
623  try
624  {
625  return Space<Scalar>::load(filename.str().c_str(), mesh, false, essential_bcs, shapeset);
626  }
627  catch(Hermes::Exceptions::SpaceLoadFailureException& e)
628  {
629  throw IOCalculationContinuityException(CalculationContinuityException::spaces, IOCalculationContinuityException::input, filename.str().c_str(), e.what());
630  }
631  catch(std::exception& e)
632  {
633  throw IOCalculationContinuityException(CalculationContinuityException::spaces, IOCalculationContinuityException::input, filename.str().c_str(), e.what());
634  }
635  }
636 
637  template<typename Scalar>
638  void CalculationContinuity<Scalar>::Record::load_solutions(Hermes::vector<Solution<Scalar>*> solutions, Hermes::vector<Space<Scalar>*> spaces)
639  {
640  if(solutions.size() != spaces.size())
641  throw Exceptions::LengthException(1, 2, solutions.size(), spaces.size());
642  for(unsigned int i = 0; i < solutions.size(); i++)
643  {
644  std::stringstream filename;
645  filename << CalculationContinuity<Scalar>::solution_file_name << i << '_' << (std::string)"t = " << this->time << (std::string)"n = " << this->number << (std::string)".h2d";
646  try
647  {
648  solutions[i]->load(filename.str().c_str(), spaces[i]);
649  solutions[i]->space_type = spaces[i]->get_type();
650  }
651  catch(Hermes::Exceptions::SolutionLoadFailureException& e)
652  {
653  throw IOCalculationContinuityException(CalculationContinuityException::solutions, IOCalculationContinuityException::input, filename.str().c_str(), e.what());
654  }
655  catch(std::exception& e)
656  {
657  throw IOCalculationContinuityException(CalculationContinuityException::solutions, IOCalculationContinuityException::input, filename.str().c_str(), e.what());
658  }
659  }
660  }
661  template<typename Scalar>
663  {
664  std::stringstream filename;
665  filename << CalculationContinuity<Scalar>::solution_file_name << 0 << '_' << (std::string)"t = " << this->time << (std::string)"n = " << this->number << (std::string)".h2d";
666  try
667  {
668  solution->load(filename.str().c_str(), space);
669  solution->space_type = space->get_type();
670  }
671  catch(Hermes::Exceptions::SolutionLoadFailureException& e)
672  {
673  throw IOCalculationContinuityException(CalculationContinuityException::solutions, IOCalculationContinuityException::input, filename.str().c_str(), e.what());
674  }
675  catch(std::exception& e)
676  {
677  throw IOCalculationContinuityException(CalculationContinuityException::solutions, IOCalculationContinuityException::input, filename.str().c_str(), e.what());
678  }
679  }
680 
681  template<typename Scalar>
683  {
684  std::stringstream filename;
685  filename << CalculationContinuity<Scalar>::time_step_file_name << '_' << (std::string)"t = " << this->time << (std::string)"n = " << this->number << (std::string)".h2d";
686  try
687  {
688  std::ifstream in(filename.str().c_str());
689  in >> time_step_length;
690  in.close();
691  }
692  catch(std::exception& e)
693  {
694  throw IOCalculationContinuityException(CalculationContinuityException::time_steps, IOCalculationContinuityException::input, filename.str().c_str(), e.what());
695  }
696  }
697 
698  template<typename Scalar>
700  {
701  std::stringstream filename;
702  filename << CalculationContinuity<Scalar>::time_stepNMinusOne_file_name << '_' << (std::string)"t = " << this->time << (std::string)"n = " << this->number << (std::string)".h2d";
703  try
704  {
705  std::ifstream in(filename.str().c_str());
706  in >> time_step_length;
707  in.close();
708  }
709  catch(std::exception& e)
710  {
711  throw IOCalculationContinuityException(CalculationContinuityException::time_steps, IOCalculationContinuityException::input, filename.str().c_str(), e.what());
712  }
713  }
714 
715  template<typename Scalar>
717  {
718  std::stringstream filename;
719  filename << CalculationContinuity<Scalar>::error_file_name << '_' << (std::string)"t = " << this->time << (std::string)"n = " << this->number << (std::string)".h2d";
720  try
721  {
722  std::ifstream in(filename.str().c_str());
723  in >> error;
724  in.close();
725  }
726  catch(std::exception& e)
727  {
728  throw IOCalculationContinuityException(CalculationContinuityException::error, IOCalculationContinuityException::input, filename.str().c_str(), e.what());
729  }
730  }
731 
732  template<typename Scalar>
734  {
735  return this->time;
736  }
737 
738  template<typename Scalar>
740  {
741  return this->number;
742  }
743 
744  template<typename Scalar>
746 
747  template<typename Scalar>
749 
750  template<typename Scalar>
752 
753  template<typename Scalar>
755  template<typename Scalar>
757 
758  template<typename Scalar>
760 
761  template<typename Scalar>
763  {
764  mesh_file_name = mesh_file_nameToSet;
765  }
766  template<typename Scalar>
768  {
769  space_file_name = space_file_nameToSet;
770  }
771  template<typename Scalar>
772  void CalculationContinuity<Scalar>::set_solution_file_name(std::string solution_file_nameToSet)
773  {
774  solution_file_name = solution_file_nameToSet;
775  }
776  template<typename Scalar>
777  void CalculationContinuity<Scalar>::set_time_step_file_name(std::string time_step_file_nameToSet)
778  {
779  time_step_file_name = time_step_file_nameToSet;
780  }
781  template<typename Scalar>
782  void CalculationContinuity<Scalar>::set_error_file_name(std::string error_file_nameToSet)
783  {
784  error_file_name = error_file_nameToSet;
785  }
786 
787  template class HERMES_API CalculationContinuity<double>;
788  template class HERMES_API CalculationContinuity<std::complex<double> >;
789  }
790 }