29 #ifndef OOMPH_UTILITIES_HEADER
30 #define OOMPH_UTILITIES_HEADER
34 #include <oomph-lib-config.h>
84 namespace ANSIEscapeCode
110 namespace DebugHelpers
117 const bool& make_new_line =
false);
128 namespace SecondInvariantHelper
154 namespace MathematicalConstants
157 const double Pi = 3.1415926535897932384626433832795028841971693993751;
160 const std::complex<double>
I(0.0, 1.0);
175 return std::abs(x) < std::abs(y);
184 namespace StringConversion
191 std::stringstream ss;
192 ss.precision(float_precision);
228 using namespace StringConversion;
232 to_string(abi::__cxa_demangle(
typeid(obj).name(), 0, 0, &status));
238 " in demangler, see documentation of "
239 "abi::__cxa_demangle for the meaning";
241 err, OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
268 namespace CumulativeTimings
271 extern void start(
const unsigned&
i);
274 extern void halt(
const unsigned&
i);
277 extern void reset(
const unsigned&
i);
289 extern Vector<clock_t>
Timing;
312 template<
class Target,
class Source>
315 Target tmp =
dynamic_cast<Target
>(x);
320 "Bad cast.", OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
334 template<
class Target,
class Source>
339 if (
dynamic_cast<Target
>(x) != x)
342 "Bad cast.", OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
345 return static_cast<Target
>(x);
379 return double(
Timing[
i]) / CLOCKS_PER_SEC;
391 unsigned n =
Timing.size();
392 for (
unsigned i = 0;
i < n;
i++)
401 Timing.resize(ntimers, clock_t(0.0));
436 Iterations_and_times.pop_back();
437 setup_new_time_step();
442 double prec_setup_time,
443 double linear_solver_time)
446 if (Iterations_and_times.size() == 0)
448 std::ostringstream error_message;
449 error_message <<
"Iterations_and_times is empty. "
450 <<
"Call setup_new_time_step()\n";
452 OOMPH_CURRENT_FUNCTION,
453 OOMPH_EXCEPTION_LOCATION);
457 tmp_iter_time_vec[0] = (double)iter;
458 tmp_iter_time_vec[1] = prec_setup_time;
459 tmp_iter_time_vec[2] = linear_solver_time;
460 Iterations_and_times.back().push_back(tmp_iter_time_vec);
466 return Iterations_and_times.size();
472 return Iterations_and_times.back().size();
478 return Iterations_and_times;
484 return Iterations_and_times;
509 Directory_must_exist(true)
515 : Directory(directory),
519 Directory_must_exist(true)
586 Directory_must_exist =
true;
592 Directory_must_exist =
false;
619 namespace CommandLineArgs
628 this->is_set = is_set;
629 this->arg_pt = arg_pt;
637 this->is_set =
false;
672 extern std::map<std::string, ArgInfo<double>>
679 extern std::map<std::string, ArgInfo<unsigned>>
683 extern std::map<std::string, ArgInfo<std::string>>
687 extern void setup(
int argc,
char** argv);
695 const std::string& documentation =
"Undocumented");
702 const std::string& documentation =
"Undocumented");
709 const std::string& documentation =
"Undocumented");
716 const std::string& documentation =
"Undocumented");
723 const std::string& documentation =
"Undocumented");
745 int argc,
char* argv[],
const bool& throw_on_unrecognised_args =
false);
750 const bool& throw_on_unrecognised_args =
false);
784 return Communicator_pt;
788 virtual bool operator()(std::ostream& stream);
794 Output_from_single_processor =
true;
795 Output_rank = output_rank;
803 Output_from_single_processor =
false;
838 static void init(
int argc,
840 const bool& make_duplicate_of_mpi_comm_world =
true);
844 static void finalize();
853 return MPI_has_been_initialised;
876 namespace ObsoleteCode
892 namespace TecplotNames
895 extern Vector<std::string>
colour;
909 namespace LeakCheckNames
915 extern long RefineableQElement<2>
_build;
916 extern long RefineableQElement<3>
_build;
950 namespace TimingHelpers
981 namespace MemoryUsage
1014 #ifdef OOMPH_HAS_UNISTDH
1114 typedef double (*TimeSpaceToDoubleFctPt)(
const double&
t,
1147 std::string err =
"No Jacobian function implemented";
1149 err, OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
1183 Solution_fpt = solution_fpt;
1188 TimeSpaceValueToDoubleVectFctPt derivative_fpt)
1190 Solution_fpt = solution_fpt;
1191 Derivative_fpt = derivative_fpt;
1213 if (Solution_fpt == 0)
1217 err, OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
1220 return Solution_fpt(
t, x);
1229 if (Derivative_fpt == 0)
1233 err, OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
1236 return Derivative_fpt(
t, x, u);
Function-type-object to perform absolute comparison of objects. Apparently this inlines better.
bool operator()(const T &x, const T &y) const
Comparison. Are the values identical or not?
Information for documentation of results: Directory and file number to enable output in the form RESL...
std::string label() const
String used (e.g.) for labeling output files. Const version.
unsigned Number
Number to label output file, say.
void enable_doc()
Enable documentation.
bool Doc_flag
Doc or don't?
unsigned number() const
Number used (e.g.) for labeling output files. Const version.
bool is_doc_enabled() const
Are we documenting?
bool Directory_must_exist
Boolean flag to decide response if an output directory doesn't exist: If true, we terminate code exec...
void disable_doc()
Disable documentation.
std::string & label()
String used (e.g.) for labeling output files.
void disable_error_if_directory_does_not_exist()
Call to issue a warning if the directory does not exists.
std::string directory() const
Output directory.
std::string Directory
Directory name.
void enable_error_if_directory_does_not_exist()
Call to throw an error if directory does not exist.
DocInfo(const std::string &directory)
Constructor with specific directory.
std::string number_as_string() const
Get number as a string (useful to completely avoid C-strings).
std::string Label
String to label output file, say.
DocInfo()
Constructor. Default settings: Current directory, step ‘0’, label="", full documentation enabled and ...
unsigned & number()
Number used (e.g.) for labeling output files.
Collection of data structures for storing information about linear solves. Currently only contains st...
void setup_new_time_step()
Set up a new vector of pairs for a new time step.
Vector< Vector< Vector< double > > > & iterations_and_times()
Accessor function for the iteration and times.
Vector< Vector< Vector< double > > > Iterations_and_times
Storage for number of iterations during Newton steps.
unsigned current_nnewton_step() const
The number of Newton steps.
DocLinearSolverInfo()
Constructor. Initialised the Iterations_and_times vector of vector of pairs.
void add_iteration_and_time(unsigned iter, double prec_setup_time, double linear_solver_time)
Add a new iteration and time pair.
void clear_current_time_step()
unsigned current_ntime_step() const
The number of time steps.
Vector< Vector< Vector< double > > > iterations_and_times() const
Accessor function for the iteration and times (const version).
MPI output modifier: Precedes every output by specification of the processor ID. Output can be restri...
OomphCommunicator *& communicator_pt()
Return pointer to communicator.
MPIOutputModifier()
Constructor – initialise flags for output from all processors.
void restrict_output_to_single_processor(const unsigned &output_rank=0)
Switch to ensure output is only produced from a single processor (default: Master node,...
OomphCommunicator * Communicator_pt
Communicator.
bool Output_from_single_processor
Boolean to control if output is performed only on a single processor (default: false)
unsigned Output_rank
Rank of single processor that produces output (only used if Output_from_single_processor=true.
void allow_output_from_all_processors()
Switch to ensure output is only produced from a single processor (default: Master node,...
MPI_Helpers class contains static helper methods to support MPI within oomph-lib. The methods init(....
static OomphCommunicator * Communicator_pt
the global communicator
static bool mpi_has_been_initialised()
return true if MPI has been initialised
static bool MPI_has_been_initialised
Bool set to true if MPI has been initialised.
MPI_Helpers(const MPI_Helpers &)
private copy constructor definition (to prevent instances of the class being instantiated)
MPI_Helpers()
private default constructor definition (to prevent instances of the class being instantiated)
An oomph-lib wrapper to the MPI_Comm communicator object. Just contains an MPI_Comm object (which is ...
std::ostream *& stream_pt()
Access function for the stream pointer.
An OomphLibError object which should be thrown when an run-time error is encountered....
///////////////////////////////////////////////////////////////////// ///////////////////////////////...
////////////////////////////////////////////////////////////////// //////////////////////////////////...
Function base class for exact solutions/initial conditions/boundary conditions. This is needed so tha...
virtual void initialise_from_problem(const Problem *problem_pt)
Overload to grab data from the problem.
virtual void jacobian(const double &t, const Vector< double > &x, const Vector< double > &u, DenseMatrix< double > &jacobian) const
The derivatives of the derivative function with respect to u (note that this is not quite the jacobia...
virtual ~SolutionFunctorBase()
Virtual destructor.
virtual Vector< double > derivative(const double &t, const Vector< double > &x, const Vector< double > &u) const =0
Call the derivative function.
virtual Vector< double > operator()(const double &t, const Vector< double > &x) const =0
Call the function.
virtual bool have_jacobian() const
Is a jacobian function implemented?
Function class for a simple function with no external parameters (just stores a function pointer,...
virtual ~SolutionFunctor()
virtual Vector< double > derivative(const double &t, const Vector< double > &x, const Vector< double > &u) const
Call the derivative function.
void operator=(const SolutionFunctor &that)
TimeSpaceValueToDoubleVectFctPt Derivative_fpt
Storage for derivative.
SolutionFunctor(TimeSpaceToDoubleVectFctPt solution_fpt, TimeSpaceValueToDoubleVectFctPt derivative_fpt)
TimeSpaceToDoubleVectFctPt Solution_fpt
Storage for solution.
SolutionFunctor(const SolutionFunctor &that)
virtual Vector< double > operator()(const double &t, const Vector< double > &x) const
Call the function.
SolutionFunctor(TimeSpaceToDoubleVectFctPt solution_fpt)
/////////////////////////////////////////////////////////////// /////////////////////////////////////...
Vector< clock_t > Timing
Cumulative timings.
double cumulative_time(const unsigned &i)
Report time accumulated by i-th timer.
void set_ntimers(const unsigned &ntimers)
Set number of timings that can be recorded in parallel.
Timer(const unsigned &n_timer)
Constructor: Specify number of timers.
Vector< clock_t > Start_time
Start times of active timers.
void reset(const unsigned &i)
Reset i-th timer.
void reset()
Reset all timers.
void start(const unsigned &i)
(Re-)start i-th timer
void halt(const unsigned &i)
Halt i-th timer.
void set_text_effect(std::string text_effect)
Function to change text effect. NOTE: This assumes the user knows what they're doing/assigning; no er...
std::string Text_effect
Variable to decide on effects.
std::string Black
The code for each type of colour.
void broken_assign(const std::string &class_name)
Issue error message and terminate execution.
void broken_copy(const std::string &class_name)
Issue error message and terminate execution.
void doc_available_flags()
Document available command line flags.
std::map< std::string, ArgInfo< bool > > Specified_command_line_flag
Map to indicate an input flag as having been set.
char ** Argv
Arguments themselves.
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).
void specify_command_line_flag(const std::string &command_line_flag, const std::string &doc)
Specify possible argument-free command line flag.
void check_arg_index(const int &argc, const int &arg_index)
Helper function to check if command line index is legal.
void doc_all_flags(std::ostream &outstream)
Document the values of all flags (specified or not).
std::map< std::string, ArgInfo< std::string > > Specified_command_line_string_pt
Map to associate an input flag with a string – specified via pointer.
std::map< std::string, ArgInfo< int > > Specified_command_line_int_pt
Map to associate an input flag with an int – specified via pointer.
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.
std::map< std::string, ArgInfo< double > > Specified_command_line_double_pt
Map to associate an input flag with a double – specified via pointer.
int Argc
Number of arguments + 1.
void output()
Doc the command line arguments.
std::map< std::string, ArgInfo< unsigned > > Specified_command_line_unsigned_pt
Map to associate an input flag with an unsigned – specified via pointer.
void doc_specified_flags()
Document specified command line flags.
double cumulative_time(const unsigned &i)
Report time accumulated by i-th timer.
void set_ntimers(const unsigned &ntimers)
Set number of timings that can be recorded in parallel.
void reset(const unsigned &i)
Reset i-th timer.
Vector< clock_t > Timing
Cumulative timings.
void halt(const unsigned &i)
Halt i-th timer.
Vector< clock_t > Start_time
Start times of active timers.
void start(const unsigned &i)
(Re-)start i-th timer
std::string debug_string(const std::string &filename, const int &line, const bool &make_new_line)
Return the concaternation of the initials of the input file name and line number. The make_new_line f...
std::string string(const unsigned &i)
Return the i-th string or "" if the relevant string hasn't been defined.
unsigned Number
The unsigned.
long QuadTreeForest_build
long AlgebraicNodeNodeUpdateInfo_build
long RefineableQElement< 2 > _build
const double Pi
50 digits from maple
const std::complex< double > I(0.0, 1.0)
The imaginary unit.
void empty_top_file()
Function to empty file that records continuous output from top in file whose name is specified by Top...
std::string Top_output_filename
String containing name of file in which we document "continuous" output from "top" (or equivalent)– y...
bool Bypass_all_memory_usage_monitoring
Bool allowing quick bypassing of ALL operations related to memory usage monitoring – this allows the ...
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...
void insert_comment_to_continous_top(const std::string &comment)
Insert comment into running continuous top output.
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 empty_memory_usage_files()
Function to empty file that records total and local memory usage in appropriate files.
void run_continous_top(const std::string &comment)
Start running top continuously and output (append) into file specified by Top_output_filename....
std::string Top_system_string
String containing system command that runs "top" (or equivalent) "indefinitely" and writes to file sp...
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...
bool Suppress_mpi_synchronisation
Boolean to suppress synchronisation of doc memory usage on processors (via mpi barriers)....
void empty_total_memory_usage_file()
Function to empty file that records total memory usage in file whose name is specified by Total_memor...
std::string Total_memory_usage_system_string
String containing system command that obtains total memory usage. Default assignment for linux....
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...
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 ...
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...
std::string My_memory_usage_system_string
String containing system command that obtains memory usage of all processes. Default assignment for l...
std::string Total_memory_usage_filename
String containing name of file in which we document total memory usage – you may want to change this ...
void obsolete()
Output warning message.
bool FlagObsoleteCode
Flag up obsolete parts of the code.
bool PauseFlag
Flag to enable pausing code – pause the code by default.
double second_invariant(const DenseMatrix< double > &tensor)
Compute second invariant of tensor.
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 to_string(T object, unsigned float_precision=8)
Conversion function that should work for anything with operator<< defined (at least all basic types).
std::string to_lower(const std::string &input)
Convert a string to lower case (outputs a copy).
std::string to_upper(const std::string &input)
Convert a string to upper case (outputs a copy).
Vector< std::string > colour
Tecplot colours.
void setup()
Setup terminate helper.
double timer()
returns the time in seconds after some point in past
std::string convert_secs_to_formatted_string(const double &time_in_sec)
Returns a nicely formatted string from an input time in seconds; the format depends on the size of ti...
std::string get_type_name(T &obj)
Get the type name of an object. Only for use in debugging, do not write real code using this function...
//////////////////////////////////////////////////////////////////// ////////////////////////////////...
Target checked_static_cast(Source *x)
Checked static cast. Only use this cast if ALL of these are true:
void pause(std::string message)
Pause and display message.
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...
MPIOutputModifier oomph_mpi_output
Single (global) instantiation of the mpi output modifier.
OomphInfo oomph_info
Single (global) instantiation of the OomphInfo object – this is used throughout the library as a "rep...
Structure to store information on a command line argument.
ArgInfo()
Default constructor. We need this to be able to store these things in maps.
T * arg_pt
The place to put the argument's value when it is set.
std::string doc
Information about what the argument does.
ArgInfo(const bool &is_set, T *arg_pt, const std::string &doc)
Proper constructor.
bool is_set
Has this argument been set?