29#ifndef OOMPH_UTILITIES_HEADER
30#define OOMPH_UTILITIES_HEADER
34#include <oomph-lib-config.h>
84 namespace ANSIEscapeCode
94 extern std::string
Black;
95 extern std::string
Red;
96 extern std::string
Green;
98 extern std::string
Blue;
100 extern std::string
Cyan;
101 extern std::string
Reset;
110 namespace DebugHelpers
115 extern std::string
debug_string(
const std::string& filename,
116 const int& line_number,
117 const std::string& message,
118 const bool& shorten =
false,
119 const bool& start_on_new_line =
true);
123#define OOMPH_DEBUG(msg) \
124 oomph_info << DebugHelpers::debug_string( \
125 __FILE__, __LINE__, msg, false, true) \
138 namespace SecondInvariantHelper
156 extern void broken_copy(
const std::string& class_name);
164 namespace MathematicalConstants
167 const double Pi = 3.1415926535897932384626433832795028841971693993751;
170 const std::complex<double>
I(0.0, 1.0);
185 return std::abs(x) < std::abs(y);
194 namespace StringConversion
201 std::stringstream
ss;
238 using namespace StringConversion;
248 " in demangler, see documentation of "
249 "abi::__cxa_demangle for the meaning";
278 namespace CumulativeTimings
281 extern void start(
const unsigned&
i);
284 extern void halt(
const unsigned&
i);
287 extern void reset(
const unsigned&
i);
299 extern Vector<clock_t>
Timing;
322 template<
class Target,
class Source>
344 template<
class Target,
class Source>
349 if (
dynamic_cast<Target>(x) != x)
355 return static_cast<Target>(x);
402 for (
unsigned i = 0;
i <
n;
i++)
458 std::ostringstream error_message;
459 error_message <<
"Iterations_and_times is empty. "
460 <<
"Call setup_new_time_step()\n";
629 namespace CommandLineArgs
682 extern std::map<std::string, ArgInfo<double>>
689 extern std::map<std::string, ArgInfo<unsigned>>
693 extern std::map<std::string, ArgInfo<std::string>>
886 namespace ObsoleteCode
902 namespace TecplotNames
905 extern Vector<std::string>
colour;
919 namespace LeakCheckNames
925 extern long RefineableQElement<2>
_build;
926 extern long RefineableQElement<3>
_build;
954 void pause(std::string message);
960 namespace TimingHelpers
991 namespace MemoryUsage
1024#ifdef OOMPH_HAS_UNISTDH
1157 std::string
err =
"No Jacobian function implemented";
1225 std::string
err =
"Solution_fpt is null!";
1241 std::string
err =
"Derivative_fpt is null!";
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()
String used (e.g.) for labeling output files.
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.
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 set_directory(const std::string &directory)
Set output directory (we try to open a file in it to see if the directory exists – if it doesn't we'l...
unsigned & number()
Number used (e.g.) for labeling output files.
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 ...
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
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.
Vector< Vector< Vector< double > > > & iterations_and_times()
Accessor function for the iteration and times.
void add_iteration_and_time(unsigned iter, double prec_setup_time, double linear_solver_time)
Add a new iteration and time pair.
Vector< Vector< Vector< double > > > iterations_and_times() const
Accessor function for the iteration and times (const version).
void clear_current_time_step()
unsigned current_ntime_step() const
The number of time steps.
double size() const
Calculate the size of the element (length, area, volume,...) in Eulerian computational coordinates....
MPI output modifier: Precedes every output by specification of the processor ID. Output can be restri...
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()
Return pointer to communicator.
OomphCommunicator * Communicator_pt
Communicator.
virtual bool operator()(std::ostream &stream)
Precede the output by the processor ID but output everything.
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 void finalize()
finalize mpi (oomph-lib equivalent of MPI_Finalize()) Deletes the global oomph-lib communicator and f...
static void init(int argc, char **argv, const bool &make_duplicate_of_mpi_comm_world=true)
initialise mpi (oomph-libs equivalent of MPI_Init(...)) Initialises MPI and creates the global oomph-...
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.
static OomphCommunicator * communicator_pt()
access to global communicator. This is the oomph-lib equivalent of MPI_COMM_WORLD
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....
A base class that contains a single virtual member function: The () operator that may be used to modi...
////////////////////////////////////////////////////////////////// //////////////////////////////////...
Function base class for exact solutions/initial conditions/boundary conditions. This is needed so tha...
virtual Vector< double > operator()(const double &t, const Vector< double > &x) const =0
Call the function.
virtual void initialise_from_problem(const Problem *problem_pt)
Overload to grab data from the problem.
Vector< double >(* TimeSpaceValueToDoubleVectFctPt)(const double &t, const Vector< double > &x, const Vector< double > &u)
General function of time, space and a value vector which returns a vector of doubles.
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.
double(* TimeSpaceToDoubleFctPt)(const double &t, const Vector< double > &x)
General function of space and time which returns a double.
virtual Vector< double > derivative(const double &t, const Vector< double > &x, const Vector< double > &u) const =0
Call the derivative function.
Vector< double >(* TimeSpaceToDoubleVectFctPt)(const double &t, const Vector< double > &x)
General function of space and time which returns a vector of doubles.
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()
void operator=(const SolutionFunctor &that)
TimeSpaceValueToDoubleVectFctPt Derivative_fpt
Storage for derivative.
virtual Vector< double > operator()(const double &t, const Vector< double > &x) const
Call the function.
SolutionFunctor(TimeSpaceToDoubleVectFctPt solution_fpt, TimeSpaceValueToDoubleVectFctPt derivative_fpt)
TimeSpaceToDoubleVectFctPt Solution_fpt
Storage for solution.
virtual Vector< double > derivative(const double &t, const Vector< double > &x, const Vector< double > &u) const
Call the derivative function.
SolutionFunctor(const SolutionFunctor &that)
SolutionFunctor(TimeSpaceToDoubleVectFctPt solution_fpt)
TAdvectionDiffusionReactionElement<NREAGENT,DIM,NNODE_1D> elements are isoparametric triangular DIM-d...
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.
A slight extension to the standard template vector class so that we can include "graceful" array rang...
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 setup(int argc, char **argv)
Set values.
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.
void reset()
Reset all timers.
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.
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_number, const std::string &message, const bool &shorten, const bool &start_on_new_line)
Return the concaternation of the initials of the input file name and line number. The make_new_line f...
long QuadTreeForest_build
long AlgebraicNodeNodeUpdateInfo_build
long RefineableQElement< 2 > _build
const std::complex< double > I(0.0, 1.0)
The imaginary unit.
const double Pi
50 digits from maple
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 namespace.
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...
DRAIG: Change all instances of (SPATIAL_DIM) to (DIM-1).
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?