basic_ode.cc File Reference
#include "generic.h"
#include "ode.h"
#include "../ode_problem.h"
#include "../ode_element_for_imr.h"
#include "../ode_example_functions.h"

Functions

int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int argc  ,
char argv[] 
)
37 {
38  using namespace CommandLineArgs;
39 
40  // Parse cli arguments
41  double dt = 0.1;
42  specify_command_line_flag("-dt", &dt, "Time step size");
43 
44  double tmax = 99999.0;
45  specify_command_line_flag("-tmax", &tmax, "Time at which to stop");
46 
47  double max_step = 50;
48  specify_command_line_flag("-max-step", &max_step, "Maximum number of steps to run");
49 
50  double tol = 0.0;
51  specify_command_line_flag("-tol", &tol,
52  "Adaptive time step tolerance (default 0 = fixed step)");
53 
54  double dt_initial = 1e-5;
55  specify_command_line_flag("-dt-initial", &dt_initial,
56  "Initial dt for adaptive time step selection.");
57 
58  std::string ts_name = "bdf2";
59  specify_command_line_flag("-ts", &ts_name, "The time stepper to use.");
60 
61  std::string ode_name = "sin";
62  specify_command_line_flag("-ode", &ode_name, "The ODE to solve.");
63 
64  std::string outdir = "results";
65  specify_command_line_flag("-outdir", &outdir, "Directory to write output to.");
66 
67  std::string element_type = "normal";
68  specify_command_line_flag("-element-type", &element_type, "Element to use.");
69 
70  setup(argc, argv);
71  parse_and_assign(argc, argv, true);
72  doc_all_flags();
73 
74 
75  // Build problem
77 
78  // For some reason using stored mass matrix + CG + lumped prec (for mass
79  // matrix solves) causes some issues with 1D ODEs, so disable it.
80  problem.Disable_mass_matrix_solver_optimisations = true;
81 
82  problem.Exact_solution_pt = ODEFactories::exact_solutions_factory(ode_name);
83 
84  TimeStepper* time_stepper_pt = Factories::time_stepper_factory(ts_name);
85 
86  Vector<Mesh*> mesh_pt;
87  mesh_pt.push_back(new Mesh);
88  if(element_type == "normal")
89  {
90  mesh_pt[0]->add_element_pt(new ODEElement(time_stepper_pt, problem.Exact_solution_pt));
91  }
92  else if(element_type == "imr-element")
93  {
94  mesh_pt[0]->add_element_pt(new IMRODEElement(time_stepper_pt, problem.Exact_solution_pt));
95  }
96  else
97  {
98  std::string err = "Unrecognised element type.";
101  }
102  problem.build(mesh_pt);
103 
104  problem.Doc_info.set_directory(outdir);
105 
106 
107 
108  // Set all dts to the value given in args
109  problem.initialise_dt(dt);
110 
111  // Set values using the initial condition function (initialisation for
112  // trapezoid rule is automatically handled here by the
113  // actions_after_set_initial_conditions() function in MyProblem).
114  problem.my_set_initial_condition(*problem.Exact_solution_pt);
115 
116  problem.initial_doc();
117 
118  // Time step to end or to max number of steps
119  while((problem.time() < tmax)
120  && (problem.N_steps_taken < max_step))
121  {
122  // Output some basic info
123  oomph_info
124  << std::endl
125  << std::endl
126  << "Time step " << problem.N_steps_taken
127  << ", time = " << problem.time()
128  << ", dt = " << dt << std::endl
129  << "=============================================" << std::endl
130  << std::endl;
131 
132  // Do the newton solve (adaptive or not depending on tol)
133  dt = problem.smart_time_step(dt, tol);
134 
135  // Output
136  problem.doc_solution();
137  }
138 
139  problem.final_doc();
140 
141  return 0;
142 }
Array< double, 1, 3 > e(1./3., 0.5, 2.)
Definition: ode_element_for_imr.h:40
Definition: mesh.h:67
Element for integrating an initial value ODE.
Definition: ode_elements.h:41
Definition: ode_problem.h:57
Definition: oomph_definitions.h:222
Definition: timesteppers.h:231
void setup(Time *time_pt)
Create all GeomObjects needed to define the cylinder and the flag.
Definition: turek_flag_non_fsi.cc:277
void specify_command_line_flag(const std::string &command_line_flag, const std::string &doc)
Specify possible argument-free command line flag.
Definition: oomph_utilities.cc:451
void doc_all_flags(std::ostream &outstream)
Document the values of all flags (specified or not).
Definition: oomph_utilities.cc:562
void parse_and_assign(int argc, char *argv[], const bool &throw_on_unrecognised_args)
Definition: oomph_utilities.cc:760
TimeStepper * time_stepper_factory(const std::string &ts_name)
Definition: ode_problem.h:250
std::string string(const unsigned &i)
Definition: oomph_definitions.cc:286
SolutionFunctorBase * exact_solutions_factory(const std::string &exact_name)
Definition: ode_example_functions.h:255
OomphInfo oomph_info
Definition: oomph_definitions.cc:319
#define OOMPH_EXCEPTION_LOCATION
Definition: oomph_definitions.h:61
#define OOMPH_CURRENT_FUNCTION
Definition: oomph_definitions.h:86
Constructor for SteadyAxisymAdvectionDiffusion problem
Definition: steady_axisym_advection_diffusion.cc:213

References oomph::CommandLineArgs::doc_all_flags(), e(), oomph::ODEFactories::exact_solutions_factory(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, oomph::oomph_info, oomph::CommandLineArgs::parse_and_assign(), problem, oomph::CommandLineArgs::setup(), oomph::CommandLineArgs::specify_command_line_flag(), oomph::Global_string_for_annotation::string(), and oomph::Factories::time_stepper_factory().