33 #ifndef OOMPH_UTILITIES_HEADER 34 #define OOMPH_UTILITIES_HEADER 38 #include <oomph-lib-config.h> 85 namespace SecondInvariantHelper
113 namespace MathematicalConstants
116 const double Pi=3.1415926535897932384626433832795028841971693993751;
119 const std::complex<double>
I(0.0,1.0);
135 return std::abs(x) < std::abs(y);
144 namespace StringConversion
151 std::stringstream ss;
152 ss.precision(float_precision);
186 using namespace StringConversion;
195 " in demangler, see documentation of abi::__cxa_demangle for the meaning";
196 throw OomphLibError(err, OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
223 namespace CumulativeTimings
227 extern void start(
const unsigned&
i);
230 extern void halt(
const unsigned& i);
233 extern void reset(
const unsigned& i);
268 template <
class Target,
class Source>
271 Target tmp =
dynamic_cast<Target
>(x);
276 OOMPH_EXCEPTION_LOCATION);
290 template <
class Target,
class Source>
295 if(dynamic_cast<Target>(x) != x)
298 OOMPH_EXCEPTION_LOCATION);
301 return static_cast<Target
>(x);
337 return double(
Timing[i])/CLOCKS_PER_SEC;
350 for (
unsigned i=0;
i<n;
i++)
359 Timing.resize(ntimers,clock_t(0.0));
383 namespace BlackBoxFDNewtonSolver
424 const double half_residual_squared_old,
430 double& half_residual_squared,
431 const double& stpmax);
461 Iterations_and_times.pop_back();
462 setup_new_time_step();
466 void add_iteration_and_time
467 (
unsigned iter,
double prec_setup_time,
double linear_solver_time)
470 if(Iterations_and_times.size() == 0)
472 std::ostringstream error_message;
473 error_message <<
"Iterations_and_times is empty. " 474 <<
"Call setup_new_time_step()\n";
476 error_message.str(),OOMPH_CURRENT_FUNCTION,
477 OOMPH_EXCEPTION_LOCATION);
481 tmp_iter_time_vec[0] = (double)iter;
482 tmp_iter_time_vec[1] = prec_setup_time;
483 tmp_iter_time_vec[2] = linear_solver_time;
484 Iterations_and_times.back().push_back(tmp_iter_time_vec);
489 {
return Iterations_and_times.size();}
493 {
return Iterations_and_times.back().size();}
497 {
return Iterations_and_times;}
501 {
return Iterations_and_times;}
524 Label(
""), Directory_must_exist(true)
529 Directory(directory), Doc_flag(true),
Number(0),
530 Label(
""), Directory_must_exist(true)
600 namespace CommandLineArgs
613 this->is_set = is_set;
614 this->arg_pt = arg_pt;
622 this->is_set =
false;
656 extern std::map<std::string, ArgInfo<double> >
660 extern std::map<std::string, ArgInfo<int> >
664 extern std::map<std::string, ArgInfo<unsigned> >
668 extern std::map<std::string, ArgInfo<std::string> >
672 extern void setup(
int argc,
char** argv);
685 (
const std::string& command_line_flag,
double* arg_pt,
691 (
const std::string& command_line_flag,
int* arg_pt,
697 (
const std::string& command_line_flag,
unsigned* arg_pt,
725 const bool& throw_on_unrecognised_args=
true);
763 Output_from_single_processor(false)
770 virtual bool operator()(std::ostream &stream);
776 Output_from_single_processor=
true;
777 Output_rank=output_rank;
785 Output_from_single_processor=
false;
824 static void init(
int argc,
char **argv,
825 const bool& make_duplicate_of_mpi_comm_world=
true);
829 static void finalize();
859 namespace ObsoleteCode
876 namespace TecplotNames
894 namespace LeakCheckNames
938 namespace TimingHelpers
966 namespace MemoryUsage
1000 #ifdef OOMPH_HAS_UNISTDH 1098 typedef double (*TimeSpaceToDoubleFctPt)(
const double&
t,
1129 std::string err =
"No Jacobian function implemented";
1131 OOMPH_EXCEPTION_LOCATION);
1163 Solution_fpt = solution_fpt;
1168 TimeSpaceValueToDoubleVectFctPt derivative_fpt)
1170 Solution_fpt = solution_fpt;
1171 Derivative_fpt = derivative_fpt;
1192 if(Solution_fpt == 0)
1196 OOMPH_EXCEPTION_LOCATION);
1199 return Solution_fpt(t, x);
1207 if(Derivative_fpt == 0)
1211 OOMPH_EXCEPTION_LOCATION);
1214 return Derivative_fpt(t, x, u);
bool Directory_must_exist
void doc_total_memory_usage(const std::string &prefix_string)
Doc total memory usage, prepended by string (which allows identification from where the function is c...
Vector< clock_t > Start_time
Start times of active timers.
DocInfo(const std::string &directory)
Constructor with specific directory.
Target checked_static_cast(Source *x)
Checked static cast. Only use this cast if ALL of these are true:
long QuadTreeForest_build
void broken_copy(const std::string &class_name)
Issue error message and terminate execution.
TimeSpaceValueToDoubleVectFctPt Derivative_fpt
Storage for derivative.
unsigned number() const
Number used (e.g.) for labeling output files. Const version.
void specify_command_line_flag(const std::string &command_line_flag, const std::string &doc)
Specify possible argument-free command line flag.
virtual bool have_jacobian() const
Is a jacobian function implemented?
virtual void jacobian(const double &t, const Vector< double > &x, const Vector< double > &u, DenseMatrix< double > &jacobian) const
double Tol
Relative tolerance to within radius of points on DtN boundary are allowed to deviate from specified v...
bool is_doc_enabled() const
Are we documenting?
char ** Argv
Arguments themselves.
std::string to_lower(const std::string &input)
Convert a string to lower case (outputs a copy).
Structure to store information on a command line argument.
Vector< clock_t > Timing
Cumulative timings.
bool Doc_Progress
Flag to indicate if progress of Newton iteration is to be documented (defaults to false) ...
Information for documentation of results: Directory and file number to enable output in the form RESL...
void restrict_output_to_single_processor(const unsigned &output_rank=0)
std::string directory() const
Output directory.
std::string My_memory_usage_system_string
String containing system command that obtains memory usage of all processes. Default assignment for l...
void setup_new_time_step()
Set up a new vector of pairs for a new time step.
std::string Top_system_string
String containing system command that runs "top" (or equivalent) "indefinitely" and writes to file sp...
const double Pi
50 digits from maple
MPI_Helpers class contains static helper methods to support MPI within oomph-lib. The methods init(...
std::map< std::string, ArgInfo< int > > Specified_command_line_int_pt
Map to associate an input flag with an int – specified via pointer.
void check_arg_index(const int &argc, const int &arg_index)
Helper function to check if command line index is legal.
void obsolete()
Output warning message.
std::string Directory
Directory name.
std::string & label()
String used (e.g.) for labeling output files.
void enable_doc()
Enable documentation.
Timer(const unsigned &n_timer)
Constructor: Specify number of timers.
virtual Vector< double > derivative(const double &t, const Vector< double > &x, const Vector< double > &u) const
Call the derivative function.
void run_continous_top(const std::string &comment)
Start running top continuously and output (append) into file specified by Top_output_filename. Wipe that file with empty_top_file() if you wish. Note that this is again quite Linux specific and unlikely to work on other operating systems. Insert optional comment into output file before starting.
std::map< std::string, ArgInfo< std::string > > Specified_command_line_string_pt
Map to associate an input flag with a string – specified via pointer.
unsigned N_iter_taken
Number of Newton iterations taken in most recent invocation.
Target checked_dynamic_cast(Source *x)
Runtime checked dynamic cast. This is the safe but slightly slower cast. Use it in any of these cases...
void empty_total_memory_usage_file()
Function to empty file that records total memory usage in file whose name is specified by Total_memor...
unsigned Output_rank
Rank of single processor that produces output (only used if Output_from_single_processor=true.
double cumulative_time(const unsigned &i)
Report time accumulated by i-th timer.
static bool mpi_has_been_initialised()
return true if MPI has been initialised
std::string number_as_string() const
Get number as a string (useful to completely avoid C-strings).
OomphCommunicator *& communicator_pt()
Return pointer to communicator.
std::map< std::string, ArgInfo< bool > > Specified_command_line_flag
Map to indicate an input flag as having been set.
void set_ntimers(const unsigned &ntimers)
Set number of timings that can be recorded in parallel.
bool Use_step_length_control
Use steplength control do make globally convergent (default false)
void empty_memory_usage_files()
Function to empty file that records total and local memory usage in appropriate files.
std::map< std::string, ArgInfo< unsigned > > Specified_command_line_unsigned_pt
Map to associate an input flag with an unsigned – specified via pointer.
unsigned current_ntime_step() const
The number of time steps.
bool operator()(const T &x, const T &y) const
Comparison. Are the values identical or not?
unsigned & number()
Number used (e.g.) for labeling output files.
OomphCommunicator * Communicator_pt
Communicator.
std::string to_upper(const std::string &input)
Convert a string to upper case (outputs a copy).
void insert_comment_to_continous_top(const std::string &comment)
Insert comment into running continuous top output.
long AlgebraicNodeNodeUpdateInfo_build
bool is_set
Has this argument been set?
unsigned Number
The unsigned.
virtual void initialise_from_problem(const Problem *problem_pt)
Overload to grab data from the problem.
void start(const unsigned &i)
(Re-)start i-th timer
void setup()
Setup terminate helper.
void reset(const unsigned &i)
Reset i-th timer.
SolutionFunctor(TimeSpaceToDoubleVectFctPt solution_fpt, TimeSpaceValueToDoubleVectFctPt derivative_fpt)
static OomphCommunicator * Communicator_pt
the global communicator
std::map< std::string, ArgInfo< double > > Specified_command_line_double_pt
Map to associate an input flag with a double – specified via pointer.
Vector< Vector< Vector< double > > > & iterations_and_times()
Accessor function for the iteration and times.
void reset(const unsigned &i)
Reset i-th timer.
std::ostream *& stream_pt()
Access function for the stream pointer.
DocLinearSolverInfo()
Constructor. Initialised the Iterations_and_times vector of vector of pairs.
const std::complex< double > I(0.0, 1.0)
The imaginary unit.
static bool MPI_has_been_initialised
Bool set to true if MPI has been initialised.
void start(const unsigned &i)
(Re-)start i-th timer
bool Output_from_single_processor
std::string Label
String to label output file, say.
void split_string(const std::string &s, char delim, Vector< std::string > &elems)
Split a string, s, into a vector of strings where ever there is an instance of delimiter (i...
std::string Top_output_filename
String containing name of file in which we document "continuous" output from "top" (or equivalent)– ...
std::string get_type_name(T *obj)
Get the type name of an object from a pointer to the object (we usually want the type of the object i...
Vector< clock_t > Timing
Cumulative timings.
void parse_and_assign(int argc, char *argv[], const bool &throw_on_unrecognised_args)
Parse command line, check for recognised flags and assign associated values.
DocInfo()
Constructor. Default settings: Current directory, step `0', label="", full documentation enabled and ...
unsigned Max_iter
Max. # of Newton iterations.
Vector< Vector< Vector< double > > > Iterations_and_times
Storage for number of iterations during Newton steps.
std::string My_memory_usage_filename
String containing name of file in which we document my memory usage – you may want to change this to...
virtual Vector< double > operator()(const double &t, const Vector< double > &x) const
Call the function.
void halt(const unsigned &i)
Halt i-th timer.
std::string doc
Information about what the argument does.
Vector< Vector< Vector< double > > > iterations_and_times() const
Accessor function for the iteration and times (const version).
MPIOutputModifier oomph_mpi_output
Single (global) instantiation of the mpi output modifier.
SolutionFunctor(const SolutionFunctor &that)
double timer()
returns the time in seconds after some point in past
void output(std::ostream &outfile)
Output with default number of plot points.
bool command_line_flag_has_been_set(const std::string &flag)
Check if command line flag has been set (value will have been assigned directly). ...
virtual ~SolutionFunctor()
void allow_output_from_all_processors()
void empty_my_memory_usage_file()
Function to empty file that records my memory usage in file whose name is specified by My_memory_usag...
void doc_my_memory_usage(const std::string &prefix_string)
Doc my memory usage, prepended by string (which allows identification from where the function is call...
void black_box_fd_newton_solve(ResidualFctPt residual_fct, const Vector< double > ¶ms, Vector< double > &unknowns)
Black-box FD Newton solver: Calling sequence for residual function is.
void disable_error_if_directory_does_not_exist()
Call to issue a warning if the directory does not exists.
unsigned current_nnewton_step() const
The number of Newton steps.
void disable_doc()
Disable documentation.
std::string label() const
String used (e.g.) for labeling output files. Const version.
int Argc
Number of arguments + 1.
void broken_assign(const std::string &class_name)
Issue error message and terminate execution.
std::string Total_memory_usage_filename
String containing name of file in which we document total memory usage – you may want to change this...
bool Suppress_mpi_synchronisation
Boolean to suppress synchronisation of doc memory usage on processors (via mpi barriers). True (i.e. sync is suppressed) by default because not all processors may reach the relevant doc memory usage statements causing the code to hang).
void enable_error_if_directory_does_not_exist()
Call to throw an error if directory does not exist.
unsigned Number
Number to label output file, say.
bool PauseFlag
Flag to enable pausing code – pause the code by default.
Vector< clock_t > Start_time
Start times of active timers.
bool Bypass_all_memory_usage_monitoring
Bool allowing quick bypassing of ALL operations related to memory usage monitoring – this allows the...
std::string string(const unsigned &i)
Return the i-th string or "" if the relevant string hasn't been defined.
std::string Total_memory_usage_system_string
String containing system command that obtains total memory usage. Default assignment for linux...
bool Doc_flag
Doc or don't?
void pause(std::string message)
Pause and display message.
void clear_current_time_step()
Class for dense matrices, storing all the values of the matrix as a pointer to a pointer with assorte...
void empty_top_file()
Function to empty file that records continuous output from top in file whose name is specified by Top...
virtual ~SolutionFunctorBase()
Virtual destructor.
Vector< std::string > colour
Tecplot colours.
void doc_available_flags()
Document available command line flags.
SolutionFunctor(TimeSpaceToDoubleVectFctPt solution_fpt)
long RefineableQElement< 2 > _build
void stop_continous_top(const std::string &comment)
Stop running top continuously. Note that this is again quite Linux specific and unlikely to work on o...
void line_search(const Vector< double > &x_old, const double half_residual_squared_old, const Vector< double > &gradient, ResidualFctPt residual_fct, const Vector< double > ¶ms, Vector< double > &newton_dir, Vector< double > &x, double &half_residual_squared, const double &stpmax)
Line search helper for globally convergent Newton method.
double cumulative_time(const unsigned &i)
Report time accumulated by i-th timer.
MPIOutputModifier()
Constructor – initialise flags for output from all processors.
ArgInfo(const bool &is_set, T *arg_pt, const std::string &doc)
Proper constructor.
void doc_memory_usage(const std::string &prefix_string)
Doc total and local memory usage, prepended by string (which allows identification from where the fun...
void reset()
Reset all timers.
void doc_specified_flags()
Document specified command line flags.
void doc_all_flags(std::ostream &outstream)
Document the values of all flags (specified or not).
void(* ResidualFctPt)(const Vector< double > &, const Vector< double > &, Vector< double > &)
Function pointer for residual function: Parameters, unknowns, residuals.
double second_invariant(const DenseMatrix< double > &tensor)
Compute second invariant of tensor.
bool FlagObsoleteCode
Flag up obsolete parts of the code.
void operator=(const SolutionFunctor &that)
void halt(const unsigned &i)
Halt i-th timer.
void set_ntimers(const unsigned &ntimers)
Set number of timings that can be recorded in parallel.
Collection of data structures for storing information about linear solves. Currently only contains st...
std::string to_string(T object, unsigned float_precision=8)
Conversion function that should work for anything with operator<< defined (at least all basic types)...
T * arg_pt
The place to put the argument's value when it is set.
TimeSpaceToDoubleVectFctPt Solution_fpt
Storage for solution.
An oomph-lib wrapper to the MPI_Comm communicator object. Just contains an MPI_Comm object (which is ...