OpenFCST: The open-source Fuel Cell Simulation Toolbox
|
This is a base class for transient solvers. More...
#include <transient_base.h>
Public Member Functions | |
TransientBase (ApplicationBase &app) | |
Constructor, receiving an application with transient model and a data object. More... | |
virtual void | declare_parameters (ParameterHandler ¶m) |
Declare input parameters in section "Transient" of parameter file. More... | |
virtual void | initialize (ParameterHandler ¶m) |
Read the parameters of TransientBase. More... | |
virtual void | solve (FuelCell::ApplicationCore::FEVector &u, const FuelCell::ApplicationCore::FEVectors &in_vectors)=0 |
The actual transient solver. More... | |
Public Member Functions inherited from FuelCell::ApplicationCore::ApplicationWrapper | |
ApplicationWrapper (ApplicationBase &app) | |
Constructor for a derived application. More... | |
~ApplicationWrapper () | |
Destructor. More... | |
virtual void | remesh () |
Generate the next mesh depending on the mesh generation parameters. More... | |
virtual void | init_vector (FEVector &dst) const |
Initialize vector to problem size. More... | |
virtual double | residual (FEVector &dst, const FEVectors &src, bool apply_boundaries=true) |
Compute residual of src and store it into dst . More... | |
virtual void | Tsolve (FEVector &dst, const FEVectors &src) |
Solve the dual system assembled with right hand side rhs and return the result in start . More... | |
virtual double | estimate (const FEVectors &src) |
Estimate cell-wise errors. More... | |
virtual double | evaluate (const FEVectors &src) |
Evaluate a functional. More... | |
virtual void | grid_out (const std::string &filename) const |
virtual void | data_out (const std::string &filename, const FEVectors &src) |
Write data in the format specified by the ParameterHandler. More... | |
virtual std::string | id () const |
Return a unique identification string for this application. More... | |
virtual void | notify (const Event &reason) |
Add a reason for assembling. More... | |
Public Member Functions inherited from FuelCell::ApplicationCore::ApplicationBase | |
ApplicationBase (boost::shared_ptr< ApplicationData > data=boost::shared_ptr< ApplicationData >()) | |
Constructor for an application. More... | |
ApplicationBase (const ApplicationBase &other) | |
Copy constructor. More... | |
virtual | ~ApplicationBase () |
Virtual destructor. More... | |
void | print_parameters_to_file (ParameterHandler ¶m, const std::string &file_name, const ParameterHandler::OutputStyle &style) |
Print default parameters for the application to a file. More... | |
virtual void | start_vector (FEVector &dst, std::string) const |
Initialize vector to problem size. More... | |
virtual void | grid_out (const std::string &) |
Write the mesh in the format specified by the ParameterHandler. More... | |
boost::shared_ptr < ApplicationData > | get_data () |
Get access to the protected variable data. More... | |
const boost::shared_ptr < ApplicationData > | get_data () const |
Get read-only access to the protected variable data. More... | |
virtual void | clear () |
All true in notifications . More... | |
virtual void | clear_events () |
All false in notifications . More... | |
virtual unsigned int | get_solution_index () |
Returns solution index. More... | |
Protected Member Functions | |
void | debug_output (const FEVector &sol) |
Function used to output any necessary information at each time layer for debugging purposes. More... | |
void | responses_output () |
Function used to output boundary responses computed by application. More... | |
void | error_output (const double &err) |
Function used to output the solution error on each layer. More... | |
void | tau_output () |
Function used to output time step on each time layer. More... | |
void | initialize_u_old (const FEVector u, const double n_ref, const FEVector old_solution, const bool force=true) |
If we are inside the adaptive refinement loop, then we receive the old solution from class since it was transferred to a finer mesh and has now a different size. More... | |
void | ats_Richardson (FEVector &u, const FEVector u1, const FEVector u2, int scheme_order, bool &solution_accepted) |
This routine estimates solution error and changes the time step using Richardson extrapolation. More... | |
bool | file_exists (const std::string &file) |
Protected Member Functions inherited from FuelCell::ApplicationCore::ApplicationWrapper | |
SmartPointer< ApplicationBase > | get_wrapped_application () |
Gain access to the inner application. More... | |
Protected Member Functions inherited from FuelCell::ApplicationCore::ApplicationBase | |
void | print_caller_name (const std::string &caller_name) const |
Print caller name. More... | |
Protected Attributes | |
bool | print_last_layer_only |
If this variable is set to true, then only the last time layer data will be printed. More... | |
bool | debug_solution |
Print updated solution after each step into file solution_NNNNN.dat . More... | |
unsigned int | debug |
Write debug output to FcstUtilities::log; the higher the number, the more output. More... | |
unsigned int | step |
Number of the current time layer. More... | |
std::string | ats_method |
Decision varible for selecting the adaptive time stepping method. More... | |
double | tau |
Initial time step size. More... | |
double | max_tau |
Maximal time step size. More... | |
double | min_tau |
Minimal time step size. More... | |
int | max_ats_it |
Maximal number of adaptive time step iterations used to resolve each time layer. More... | |
FEVector | u_old |
A vector to store the solution from the previous time layer in. More... | |
int | ar_freq |
If adaptive refinement is selected, then it will be performed at each ar_freq -th layer. More... | |
double | total_time |
Total time of simulation in seconds. More... | |
double | time |
Current time of simulation. More... | |
double | abs_err_estimate |
double | rel_err_estimate |
double | abs_error_tolerance |
double | rel_error_tolerance |
bool | output_error |
bool | output_tau |
std::ofstream | responses_outfile |
Variable used in printing responses data into a file. More... | |
std::ofstream | error_outfile |
Variable used in printing solution error data into a file. More... | |
std::ofstream | tau_outfile |
Variable used in printing time step into a file. More... | |
const std::string | fname_err ="Solution_error.dat" |
File name for solution error output. More... | |
const std::string | fname_tau ="Time_step.dat" |
File name for solution error output. More... | |
std::vector< double > | all_time_values |
A vector of all time values. More... | |
bool | everything_is_fine =true |
unsigned int | n_ref |
Protected Attributes inherited from FuelCell::ApplicationCore::ApplicationWrapper | |
SmartPointer< ApplicationBase > | app |
Pointer to the application this one depends upon. More... | |
Protected Attributes inherited from FuelCell::ApplicationCore::ApplicationBase | |
boost::shared_ptr < ApplicationData > | data |
Object for auxiliary data. More... | |
Event | notifications |
Accumulate reasons for assembling here. More... | |
Private Member Functions | |
const std::string | get_time_stepping_method_names () const |
This function returns the string of names for the adaptive time stepping methods. More... | |
Private Attributes | |
std::string | fname |
File name for debug output. More... | |
std::ofstream | streamOut |
Variable for streaming to file. More... | |
double | precaution_factor |
Precaution factor in optimal time step computation. More... | |
This is a base class for transient solvers.
All it does is sets some basic parameters common for all numerical methods implementing marching in time (such as time step and its value's limits, debug level for output, etc.) and outputs solution to a .dat file if required.
Default parameters in data input file are as follows:
FuelCell::ApplicationCore::TransientBase::TransientBase | ( | ApplicationBase & | app | ) |
Constructor, receiving an application with transient model and a data object.
|
protected |
This routine estimates solution error and changes the time step using Richardson extrapolation.
Assuming -th order method,
where is the exact solution, is the solution obtained from previous time layer with a single time step of the size and is the solution obtained from the same previous time layer with two time steps of the size . From these two relations, we can find constant :
Decision on time step change is made based on the absolute and relative difference between solutions and in some norm, here - in the l2 norm defined as L2 norm of the solution divided by the square root of number of DoFs minus one. Suppose that we want to find such step that the solution (computed with that new time step) satisfies , where is absolute solution error tolerance prescribed by the user.
Then, given
we can assume
from where we get
In practice, a precaution factor is introduced:
For most of the cases, value can be safely used [1].
To satisfy the relative error tolerance as well, we want
In this case, we get
The resulting time step is chosen as minimum between the two values obtained based on absolute and relative error estimation.
The resulting solution
has accuracy of order .
References
|
protected |
Function used to output any necessary information at each time layer for debugging purposes.
|
virtual |
Declare input parameters in section "Transient" of parameter file.
Reimplemented from FuelCell::ApplicationCore::ApplicationWrapper.
Reimplemented in FuelCell::ApplicationCore::ThetaScheme.
|
protected |
Function used to output the solution error on each layer.
Data can be used to plot solution error vs. time and see if there were any oscillations.
This is the most convenient way to check stability of the numerical scheme (after theoretical analysis, of course, if it is not too hard to do). If the plot is not monotonous, then you might need to use a smaller time step, a finer mesh, or try adaptive time stepping algorithms.
|
inlineprotected |
|
inlineprivate |
This function returns the string of names for the adaptive time stepping methods.
|
virtual |
Read the parameters of TransientBase.
Those are general parameters for transient loop, e.g. time step.
Reimplemented from FuelCell::ApplicationCore::ApplicationWrapper.
Reimplemented in FuelCell::ApplicationCore::ThetaScheme.
|
protected |
If we are inside the adaptive refinement loop, then we receive the old solution from class since it was transferred to a finer mesh and has now a different size.
The transferred solution will be stored in the local variable u_old. If no adaptive refinement is used, then u_old is initialized with u. Variable force is used in adaptive time stepping algorithm. Forced initialization, i.e., initialization with force=true, sets u_old to u, which is previous iterate of the model - it can be different from the old solution u^n in transient sense. For example, when we do two half-steps in Richardson extrapolation, the first half-step uses the old_solution solution from class and the second half-step - the old solution in a global sense, u, which was obtained from the first half-step.
|
protected |
Function used to output boundary responses computed by application.
|
pure virtual |
The actual transient solver.
Performs loop over time.
This function's definition is used in classes derived from TransientBase (such as ThetaScheme), but not in current class itself.
Reimplemented from FuelCell::ApplicationCore::ApplicationWrapper.
Implemented in FuelCell::ApplicationCore::ThetaScheme.
|
protected |
Function used to output time step on each time layer.
Data can be used to analyze the adaptive time stepping algorithm that was used in the simulation.
|
protected |
|
protected |
|
protected |
A vector of all time values.
Used in the funciton.
|
protected |
If adaptive refinement is selected, then it will be performed at each ar_freq
-th layer.
|
protected |
Decision varible for selecting the adaptive time stepping method.
This variable is set in the input file in:
Possible options are:
|
protected |
Write debug output to FcstUtilities::log; the higher the number, the more output.
|
protected |
Print updated solution after each step into file solution_NNNNN.dat
.
|
protected |
Variable used in printing solution error data into a file.
|
protected |
|
private |
File name for debug output.
|
protected |
File name for solution error output.
|
protected |
File name for solution error output.
|
protected |
Maximal number of adaptive time step iterations used to resolve each time layer.
No convergence error will be thrown if the number of iterations exceeds this value.
|
protected |
Maximal time step size.
Used in adaptive time stepping.
|
protected |
Minimal time step size.
Used in adaptive time stepping.
|
protected |
|
protected |
|
protected |
|
private |
Precaution factor in optimal time step computation.
|
protected |
If this variable is set to true, then only the last time layer data will be printed.
|
protected |
|
protected |
|
protected |
Variable used in printing responses data into a file.
|
protected |
Number of the current time layer.
Time layer 0 contains initial solution.
|
private |
Variable for streaming to file.
|
protected |
Initial time step size.
|
protected |
Variable used in printing time step into a file.
|
protected |
Current time of simulation.
|
protected |
Total time of simulation in seconds.
|
protected |
A vector to store the solution from the previous time layer in.