34 #ifdef OOMPH_HAS_UNISTDH
56 namespace ANSIEscapeCode
87 namespace DebugHelpers
94 const bool& make_new_line)
112 while ((pos = file.find(
"/")) != std::string::npos)
115 token = file.substr(0, pos);
118 file = file.substr(pos + delimiter.length());
122 while ((pos = file.find(delimiter)) != std::string::npos)
125 token = file.substr(0, pos);
131 file = file.substr(pos + delimiter.length());
138 std::ostringstream debug_stream;
144 debug_stream <<
"\n";
148 debug_stream <<
"\033[1;31m" <<
debug_string << line <<
":\033[0m ";
151 return debug_stream.str();
160 namespace SecondInvariantHelper
166 unsigned n = tensor.
nrow();
167 double trace_of_tensor = 0.0;
168 double trace_of_tensor_squared = 0.0;
169 for (
unsigned i = 0;
i < n;
i++)
172 trace_of_tensor += tensor(
i,
i);
174 for (
unsigned j = 0; j < n; j++)
176 trace_of_tensor_squared += tensor(
i, j) * tensor(j,
i);
182 (trace_of_tensor * trace_of_tensor - trace_of_tensor_squared);
198 std::string error_message =
"Assignment operator for class\n\n";
199 error_message += class_name;
200 error_message +=
"\n\n";
201 error_message +=
"is deliberately broken to avoid the accidental \n";
202 error_message +=
"use of the inappropriate C++ default.\n";
203 error_message +=
"If you really need an assignment operator\n";
204 error_message +=
"for this class, write it yourself...\n";
207 error_message,
"broken_assign()", OOMPH_EXCEPTION_LOCATION);
215 std::string error_message =
"Copy constructor for class\n\n";
216 error_message += class_name;
217 error_message +=
"\n\n";
218 error_message +=
"is deliberately broken to avoid the accidental\n";
219 error_message +=
"use of the inappropriate C++ default.\n";
221 "All function arguments should be passed by reference or\n";
223 "constant reference. If you really need a copy constructor\n";
224 error_message +=
"for this class, write it yourself...\n";
227 error_message, OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
240 namespace CumulativeTimings
257 return double(
Timing[
i]) / CLOCKS_PER_SEC;
269 unsigned n =
Timing.size();
270 for (
unsigned i = 0;
i < n;
i++)
279 Timing.resize(ntimers, clock_t(0.0));
301 std::ostringstream filename;
302 filename << directory_ <<
"/.dummy_check.dat";
303 std::ofstream some_file;
304 some_file.open(filename.str().c_str());
305 if (!some_file.is_open())
308 std::string error_message =
"Problem opening output file.\n";
309 error_message +=
"I suspect you haven't created the output directory ";
310 error_message += directory_;
311 error_message +=
"\n";
318 error_message,
"set_directory()", OOMPH_EXCEPTION_LOCATION);
323 error_message +=
"and the Directory_must_exist flag is true.\n";
325 error_message, OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
329 some_file <<
"Dummy file, opened to check if output directory "
331 some_file <<
"exists. Can be deleted...." << std::endl;
342 namespace StringConversion
348 std::string::iterator it;
361 std::string::iterator it;
378 std::stringstream ss(
s);
380 while (std::getline(ss, item, delim))
382 elems.push_back(item);
404 namespace CommandLineArgs
425 std::map<std::string, ArgInfo<std::string>>
440 oomph_info <<
"with the following command line args: " << std::endl;
441 std::stringstream str;
508 if (it->first == flag)
510 return it->second.is_set;
519 if (it->first == flag)
521 return (it->second).is_set;
530 if (it->first == flag)
532 return (it->second).is_set;
541 if (it->first == flag)
543 return (it->second).is_set;
552 if (it->first == flag)
554 return (it->second).is_set;
569 outstream << it->first <<
" " << it->second.is_set << std::endl;
576 outstream << it->first <<
" " << *(it->second.arg_pt) << std::endl;
583 outstream << it->first <<
" " << *(it->second.arg_pt) << std::endl;
590 outstream << it->first <<
" " << *(it->second.arg_pt) << std::endl;
600 if (arg_string ==
"")
605 outstream << it->first <<
" " << arg_string << std::endl;
613 oomph_info <<
"Specified (and recognised) command line flags:\n";
614 oomph_info <<
"----------------------------------------------\n";
621 if (it->second.is_set)
632 if (it->second.is_set)
634 oomph_info << it->first <<
" " << *(it->second.arg_pt) << std::endl;
643 if (it->second.is_set)
645 oomph_info << it->first <<
" " << *(it->second.arg_pt) << std::endl;
654 if (it->second.is_set)
656 oomph_info << it->first <<
" " << *(it->second.arg_pt) << std::endl;
665 if (it->second.is_set)
667 oomph_info << it->first <<
" " << *(it->second.arg_pt) << std::endl;
679 oomph_info <<
"Available command line flags:\n";
680 oomph_info <<
"-----------------------------\n";
688 << it->second.doc << std::endl
697 oomph_info << it->first <<
" <double> " << std::endl
698 << it->second.doc << std::endl
707 oomph_info << it->first <<
" <int> " << std::endl
708 << it->second.doc << std::endl
717 oomph_info << it->first <<
" <unsigned> " << std::endl
718 << it->second.doc << std::endl
727 oomph_info << it->first <<
" <string> " << std::endl
728 << it->second.doc << std::endl
739 if (arg_index >= argc)
743 std::stringstream error_stream;
745 <<
"Tried to read more command line arguments than\n"
746 <<
"specified. This tends to happen if a required argument\n"
747 <<
"to a command line flag was omitted, e.g. by running \n\n"
748 <<
" ./a.out -some_double \n\n rather than\n\n"
749 <<
" ./a.out -some_double 1.23 \n\n"
750 <<
"To aid the debugging I've output the available\n"
751 <<
"command line arguments above.\n";
753 error_stream.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
762 const bool& throw_on_unrecognised_args)
766 while (arg_index < argc)
768 bool found_match =
false;
770 if ((strcmp(argv[arg_index],
"-help") == 0) ||
771 (strcmp(argv[arg_index],
"--help") == 0))
774 <<
"NOTE: You entered --help or -help on the command line\n";
775 oomph_info <<
"so I'm going to tell you about this code's\n";
776 oomph_info <<
"available command line flags and then return.\n";
781 MPI_Initialized(&flag);
796 if (it->first == argv[arg_index])
813 if (it->first == argv[arg_index])
819 it->second.is_set =
true;
820 *(it->second.arg_pt) = atof(argv[arg_index]);
837 if (it->first == argv[arg_index])
843 it->second.is_set =
true;
844 *(it->second.arg_pt) = atoi(argv[arg_index]);
862 if (it->first == argv[arg_index])
868 it->second.is_set =
true;
869 *(it->second.arg_pt) =
unsigned(atoi(argv[arg_index]));
886 if (it->first == argv[arg_index])
892 it->second.is_set =
true;
893 *(it->second.arg_pt) = argv[arg_index];
906 std::string error_message =
"Command line argument\n\n";
907 error_message += argv[arg_index];
908 error_message +=
"\n\nwas not recognised. This may be legal\n";
909 error_message +=
"but seems sufficiently suspicious to flag up.\n";
910 error_message +=
"If it should have been recognised, make sure you\n";
911 error_message +=
"used the right number of \"-\" signs...\n";
913 if (throw_on_unrecognised_args)
915 error_message +=
"Throwing an error because you requested it with";
916 error_message +=
" throw_on_unrecognised_args option.";
918 error_message, OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
924 error_message, OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
958 stream <<
"Processor " << my_rank <<
": ";
966 stream <<
"Processor " << my_rank <<
": ";
985 const bool& make_duplicate_of_mpi_comm_world)
989 MPI_Init(&argc, &argv);
994 MPI_Comm oomph_comm_world = MPI_COMM_WORLD;
995 if (make_duplicate_of_mpi_comm_world)
997 MPI_Comm_dup(MPI_COMM_WORLD, &oomph_comm_world);
1000 if (MPI_COMM_WORLD != oomph_comm_world)
1002 oomph_info <<
"Oomph-lib communicator is a duplicate of MPI_COMM_WORLD\n";
1006 oomph_info <<
"Oomph-lib communicator is MPI_COMM_WORLD\n";
1016 MPI_Comm_set_errhandler(oomph_comm_world, MPI_ERRORS_RETURN);
1038 #ifdef OOMPH_HAS_MPI
1052 std::ostringstream error_message_stream;
1053 error_message_stream
1054 <<
"MPI has not been initialised.\n Call MPI_Helpers::init(...)";
1056 OOMPH_CURRENT_FUNCTION,
1057 OOMPH_EXCEPTION_LOCATION);
1096 namespace ObsoleteCode
1107 oomph_info <<
"\n\n--------------------------------------------\n";
1108 oomph_info <<
"You are using obsolete code " << std::endl;
1109 oomph_info <<
"--------------------------------------------\n\n";
1110 oomph_info <<
"Enter: \"s\" to suppress further messages" << std::endl;
1111 oomph_info <<
" \"k\" to crash the code to allow a trace back in "
1115 oomph_info <<
" any other key to continue\n \n";
1118 "ObsoleteCode::FlagObsoleteCode=false;\n \n";
1119 oomph_info <<
" into your code to suppress these "
1131 "Killed", OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
1142 oomph_info <<
"\n\n------------------------------------" << std::endl;
1144 oomph_info <<
"----------------------------------------" << std::endl;
1156 namespace TecplotNames
1183 namespace LeakCheckNames
1214 oomph_info <<
"\n Leak check: # of builds - # of deletes for the "
1215 "following objects: \n\n";
1216 oomph_info <<
"LeakCheckNames::QuadTree_build "
1218 oomph_info <<
"LeakCheckNames::QuadTreeForest_build "
1220 oomph_info <<
"LeakCheckNames::OcTree_build "
1222 oomph_info <<
"LeakCheckNames::OcTreeForest_build "
1224 oomph_info <<
"LeakCheckNames::RefineableQElement<2>_build "
1225 << LeakCheckNames::RefineableQElement<2>
_build << std::endl;
1226 oomph_info <<
"LeakCheckNames::RefineableQElement<3>_build "
1227 << LeakCheckNames::RefineableQElement<3>
_build << std::endl;
1228 oomph_info <<
"LeakCheckNames::MacroElement_build "
1230 oomph_info <<
"LeakCheckNames::HangInfo_build "
1234 oomph_info <<
"LeakCheckNames::GeomReference_build "
1236 oomph_info <<
"LeakCheckNames::AlgebraicNode_build "
1255 namespace PauseFlags
1270 oomph_info << message <<
"\n hit any key to continue [hit \"S\" "
1271 <<
"to suppress further interruptions]\n";
1280 oomph_info <<
"\n[Suppressed pause message] \n";
1292 namespace TimingHelpers
1297 #ifdef OOMPH_HAS_MPI
1306 return double(
t) / double(CLOCKS_PER_SEC);
1318 std::ostringstream ss;
1320 unsigned sec_within_day = unsigned(time_in_sec) % (3600 * 24);
1322 unsigned days = unsigned(time_in_sec) / (3600 * 24);
1323 unsigned hours = sec_within_day / 3600;
1324 unsigned minutes = (sec_within_day % 3600) / 60;
1325 unsigned seconds = (sec_within_day % 3600) % 60;
1334 ss << hours <<
"h:";
1335 ss << std::setw(2) << std::setfill(
'0');
1336 ss << minutes <<
":";
1339 else if (minutes > 0)
1341 ss << minutes <<
"m:";
1342 ss << std::setw(2) << std::setfill(
'0');
1347 double seconds_double = seconds + (time_in_sec - double(seconds));
1348 ss << std::setprecision(1) << std::fixed << seconds_double <<
"s";
1371 namespace MemoryUsage
1408 std::ofstream the_file;
1410 the_file <<
"# My memory usage: \n";
1415 #ifdef OOMPH_HAS_UNISTDH
1430 std::ofstream the_file;
1432 the_file << prefix_string <<
" ";
1436 #ifdef OOMPH_HAS_MPI
1445 std::stringstream tmp;
1448 int success = system(tmp.str().c_str());
1460 "ps aux | awk 'BEGIN{sum=0}{sum+=$4}END{print sum}'";
1478 std::ofstream the_file;
1480 the_file <<
"# Total memory usage: \n";
1495 std::ofstream the_file;
1497 the_file << prefix_string <<
" ";
1501 #ifdef OOMPH_HAS_MPI
1510 std::stringstream tmp;
1513 int success = system(tmp.str().c_str());
1540 #ifdef OOMPH_HAS_UNISTDH
1570 std::ofstream the_file;
1572 the_file <<
"# Continuous output from top obtained with: \n";
1591 #ifdef OOMPH_HAS_MPI
1598 std::stringstream tmp;
1600 modifier = tmp.str();
1605 std::stringstream tmp;
1612 tmp <<
"echo \"#/bin/bash\" > run_continuous_top" << modifier <<
".bash; "
1613 <<
"echo \" echo " << backslash <<
"\" kill " << backslash << dollar
1614 << backslash << dollar <<
" " << backslash
1615 <<
"\" > kill_continuous_top" << modifier
1616 <<
".bash; chmod a+x kill_continuous_top" << modifier <<
".bash; "
1618 <<
".bash; chmod a+x run_continuous_top" << modifier <<
".bash ";
1619 int success = system(tmp.str().c_str());
1628 std::stringstream tmp2;
1629 tmp2 <<
"./run_continuous_top" << modifier <<
".bash >> "
1631 success = system(tmp2.str().c_str());
1649 #ifdef OOMPH_HAS_MPI
1656 std::stringstream tmp;
1658 modifier = tmp.str();
1669 std::stringstream tmp2;
1670 tmp2 <<
"./kill_continuous_top" << modifier <<
".bash >> "
1672 int success = system(tmp2.str().c_str());
1685 std::stringstream tmp;
1686 tmp <<
" echo \"OOMPH-LIB EVENT: " << comment <<
"\" >> "
1688 int success = system(tmp.str().c_str());
unsigned long nrow() const
Return the number of rows of the matrix.
bool Directory_must_exist
Boolean flag to decide response if an output directory doesn't exist: If true, we terminate code exec...
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...
MPI output modifier: Precedes every output by specification of the processor ID. Output can be restri...
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.
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
An oomph-lib wrapper to the MPI_Comm communicator object. Just contains an MPI_Comm object (which is ...
OutputModifier *& output_modifier_pt()
Access function for the output modifier pointer.
An OomphLibError object which should be thrown when an run-time error is encountered....
An OomphLibWarning object which should be created as a temporary object to issue a warning....
Refineable version of QElement<2,NNODE_1D>.
Refineable version of QElement<3,NNODE_1D>.
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.
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.
long QuadTreeForest_build
long RefineableQElement< 2 > _build
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_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...
//////////////////////////////////////////////////////////////////// ////////////////////////////////...
void pause(std::string message)
Pause and display message.
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.