OpenFCST: The open-source Fuel Cell Simulation Toolbox
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
transient_base.h
Go to the documentation of this file.
1 //---------------------------------------------------------------------------
2 //
3 // FCST: Fuel Cell Simulation Toolbox
4 //
5 // Copyright (C) 2015 by Energy Systems Design Laboratory, University of Alberta
6 //
7 // This software is distributed under the MIT License.
8 // For more information, see the README file in /doc/LICENSE
9 //
10 // - Class: transient_base.h
11 // - Description: Base class for a variety of transient solvers
12 // - Developers: A. Kosakian, University of Alberta
13 //
14 //---------------------------------------------------------------------------
15 
16 #ifndef __transient_base_h
17 #define __transient_base_h
18 
20 
21 #include <sys/stat.h>
22 #include <fstream>
23 
24 using namespace dealii;
25 using namespace FuelCell::ApplicationCore;
26 
27 namespace FuelCell
28 {
29 namespace ApplicationCore
30 {
54  {
55  public:
60 
64  virtual void declare_parameters (ParameterHandler& param);
65 
69  virtual void initialize (ParameterHandler& param);
70 
77  virtual void solve(FuelCell::ApplicationCore::FEVector& u,
78  const FuelCell::ApplicationCore::FEVectors& in_vectors) = 0;
79 
80  protected:
85  void debug_output(const FEVector& sol);
86 
90  void responses_output();
91 
100  void error_output(const double& err);
101 
106  void tau_output();
107 
118  void initialize_u_old(const FEVector u, const double n_ref, const FEVector old_solution, const bool force=true);
119 
204  void ats_Richardson(FEVector& u, const FEVector u1, const FEVector u2, int scheme_order, bool& solution_accepted);
205 
210 
215 
220  unsigned int debug;
221 
225  unsigned int step;
226 
241  std::string ats_method;
242 
248  double tau;
249 
253  double max_tau;
254 
258  double min_tau;
259 
264 
269 
273  int ar_freq;
274 
278  double total_time;
279 
283  double time;
284 
285  /*
286  * Absolute error of the solution in the l2 norm (defined here as L2 norm of the solution divided by the square root of number of DoFs minus one).
287  */
289 
290  /*
291  * Relative error of the solution in the l2 norm (defined here as L2 norm of the solution divided by the square root of number of DoFs minus one).
292  */
294 
295  /*
296  * Tolerance used for the absolute error of the solution.
297  */
299 
300  /*
301  * Tolerance used for the relative error of the solution.
302  */
304 
305  /*
306  * If true, solution error from each time layer will be output to Solution_error.dat.
307  */
309 
310  /*
311  * If true, time step from each time layer will be output to Time_step.dat.
312  */
313  bool output_tau;
314 
318  std::ofstream responses_outfile;
319 
323  std::ofstream error_outfile;
324 
328  std::ofstream tau_outfile;
329 
333  const std::string fname_err="Solution_error.dat";
334 
338  const std::string fname_tau="Time_step.dat";
339 
340  /*
341  * Returns true if and only if file exists.
342  */
343  bool file_exists(const std::string& file)
344  {
345  struct stat buf;
346  return (stat(file.c_str(), &buf) ==0);
347  }
348 
352  std::vector<double> all_time_values;
353 
354  /*
355  * True if simulations is healthy (everything went fine). Used to notify the user in case something went wrong and assertions did not work properly.
356  */
357  bool everything_is_fine=true;
358 
359  /*
360  * Number of mesh refinements.
361  */
362  unsigned int n_ref;
363 
364  private:
368  std::string fname;
369 
373  std::ofstream streamOut;
374 
378  const std::string get_time_stepping_method_names() const
379  {
380  std::stringstream result;
381 
382  result << "None"
383  << "|"
384  << "Richardson";
385 
386  return result.str();
387  }
388 
393  };
394 }
395 }
396 
397 #endif
double rel_err_estimate
Definition: transient_base.h:293
double precaution_factor
Precaution factor in optimal time step computation.
Definition: transient_base.h:392
double rel_error_tolerance
Definition: transient_base.h:303
double abs_err_estimate
Definition: transient_base.h:288
double total_time
Total time of simulation in seconds.
Definition: transient_base.h:278
bool debug_solution
Print updated solution after each step into file solution_NNNNN.dat.
Definition: transient_base.h:214
bool output_error
Definition: transient_base.h:308
std::ofstream error_outfile
Variable used in printing solution error data into a file.
Definition: transient_base.h:323
std::ofstream streamOut
Variable for streaming to file.
Definition: transient_base.h:373
int max_ats_it
Maximal number of adaptive time step iterations used to resolve each time layer.
Definition: transient_base.h:263
double tau
Initial time step size.
Definition: transient_base.h:248
bool print_last_layer_only
If this variable is set to true, then only the last time layer data will be printed.
Definition: transient_base.h:209
std::ofstream tau_outfile
Variable used in printing time step into a file.
Definition: transient_base.h:328
double min_tau
Minimal time step size.
Definition: transient_base.h:258
double abs_error_tolerance
Definition: transient_base.h:298
std::ofstream responses_outfile
Variable used in printing responses data into a file.
Definition: transient_base.h:318
unsigned int debug
Write debug output to FcstUtilities::log; the higher the number, the more output. ...
Definition: transient_base.h:220
double max_tau
Maximal time step size.
Definition: transient_base.h:253
const std::string get_time_stepping_method_names() const
This function returns the string of names for the adaptive time stepping methods. ...
Definition: transient_base.h:378
bool output_tau
Definition: transient_base.h:313
Base class for applications.
Definition: application_base.h:113
std::string ats_method
Decision varible for selecting the adaptive time stepping method.
Definition: transient_base.h:241
This class implements either iterative or time-stepping wrapper of applications.
Definition: application_wrapper.h:39
double time
Current time of simulation.
Definition: transient_base.h:283
bool file_exists(const std::string &file)
Definition: transient_base.h:343
This is a base class for transient solvers.
Definition: transient_base.h:53
int ar_freq
If adaptive refinement is selected, then it will be performed at each ar_freq-th layer.
Definition: transient_base.h:273
unsigned int n_ref
Definition: transient_base.h:362
BlockVector< double > FEVector
The vector class used by applications.
Definition: application_data.h:46
The data type used in function calls of Application.
Definition: fe_vectors.h:59
std::vector< double > all_time_values
A vector of all time values.
Definition: transient_base.h:352
FEVector u_old
A vector to store the solution from the previous time layer in.
Definition: transient_base.h:268
std::string fname
File name for debug output.
Definition: transient_base.h:368
unsigned int step
Number of the current time layer.
Definition: transient_base.h:225