diff --git a/.gitignore b/.gitignore index 610d927b3f..5aaaf02a74 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,8 @@ # Object and library files *.o /libmfem.a +CMakeCache.txt +CMakeFiles/ # Backup files *~ diff --git a/examples/ex1.cpp b/examples/ex1.cpp index a0298dbd37..463fdd74be 100644 --- a/examples/ex1.cpp +++ b/examples/ex1.cpp @@ -45,10 +45,10 @@ using namespace mfem; int main(int argc, char *argv[]) { // 0. Print out version and configuration info - mout.Disable(); - mout << "MFEM Version: " << get_version_str() << endl; - mout.Enable(); - mout << "MFEM Configuration: " << endl << get_config_str() << endl; + mfem::out.Disable(); + mfem::out << "MFEM Version: " << get_version_str() << endl; + mfem::out.Enable(); + mfem::out << "MFEM Configuration: " << endl << get_config_str() << endl; // 1. Parse command-line options. const char *mesh_file = "../data/star.mesh"; diff --git a/examples/ex1p.cpp b/examples/ex1p.cpp index f581f537fb..2046b88fb9 100644 --- a/examples/ex1p.cpp +++ b/examples/ex1p.cpp @@ -49,6 +49,7 @@ int main(int argc, char *argv[]) MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD, &num_procs); MPI_Comm_rank(MPI_COMM_WORLD, &myid); + mfem::out.Disable(); // 2. Parse command-line options. const char *mesh_file = "../data/star.mesh"; @@ -72,14 +73,14 @@ int main(int argc, char *argv[]) { if (myid == 0) { - args.PrintUsage(cout); + args.PrintUsage(mfem::out); } MPI_Finalize(); return 1; } if (myid == 0) { - args.PrintOptions(cout); + args.PrintOptions(mfem::out); } // 3. Read the (serial) mesh from the given mesh file on all processors. We @@ -127,7 +128,7 @@ int main(int argc, char *argv[]) fec = pmesh->GetNodes()->OwnFEC(); if (myid == 0) { - cout << "Using isoparametric FEs: " << fec->Name() << endl; + mfem::out << "Using isoparametric FEs: " << fec->Name() << endl; } } else @@ -138,7 +139,7 @@ int main(int argc, char *argv[]) HYPRE_Int size = fespace->GlobalTrueVSize(); if (myid == 0) { - cout << "Number of finite element unknowns: " << size << endl; + mfem::out << "Number of finite element unknowns: " << size << endl; } // 7. Determine the list of true (i.e. parallel conforming) essential @@ -186,7 +187,7 @@ int main(int argc, char *argv[]) if (myid == 0) { - cout << "Size of linear system: " << A.GetGlobalNumRows() << endl; + mfem::out << "Size of linear system: " << A.GetGlobalNumRows() << endl; } // 12. Define and apply a parallel PCG solver for AX=B with the BoomerAMG @@ -195,7 +196,7 @@ int main(int argc, char *argv[]) HyprePCG *pcg = new HyprePCG(A); pcg->SetTol(1e-12); pcg->SetMaxIter(200); - pcg->SetPrintLevel(2); + pcg->SetPrintLevel(0); pcg->SetPreconditioner(*amg); pcg->Mult(B, X); diff --git a/fem/fe.cpp b/fem/fe.cpp index 2a1f5d468b..6b21e2bb09 100644 --- a/fem/fe.cpp +++ b/fem/fe.cpp @@ -2666,7 +2666,7 @@ void RT0TriangleFiniteElement::GetLocalInterpolation ( if (j == k) { d -= 1.0; } if (fabs(d) > 1.0e-12) { - cerr << "RT0TriangleFiniteElement::GetLocalInterpolation (...)\n" + mfem::err << "RT0TriangleFiniteElement::GetLocalInterpolation (...)\n" " k = " << k << ", j = " << j << ", d = " << d << endl; mfem_error(); } @@ -2781,7 +2781,7 @@ void RT0QuadFiniteElement::GetLocalInterpolation ( if (j == k) { d -= 1.0; } if (fabs(d) > 1.0e-12) { - cerr << "RT0QuadFiniteElement::GetLocalInterpolation (...)\n" + mfem::err << "RT0QuadFiniteElement::GetLocalInterpolation (...)\n" " k = " << k << ", j = " << j << ", d = " << d << endl; mfem_error(); } @@ -2923,7 +2923,7 @@ void RT1TriangleFiniteElement::GetLocalInterpolation ( if (j == k) { d -= 1.0; } if (fabs(d) > 1.0e-12) { - cerr << "RT1QuadFiniteElement::GetLocalInterpolation (...)\n" + mfem::err << "RT1QuadFiniteElement::GetLocalInterpolation (...)\n" " k = " << k << ", j = " << j << ", d = " << d << endl; mfem_error(); } @@ -3105,7 +3105,7 @@ void RT1QuadFiniteElement::GetLocalInterpolation ( if (j == k) { d -= 1.0; } if (fabs(d) > 1.0e-12) { - cerr << "RT1QuadFiniteElement::GetLocalInterpolation (...)\n" + mfem::err << "RT1QuadFiniteElement::GetLocalInterpolation (...)\n" " k = " << k << ", j = " << j << ", d = " << d << endl; mfem_error(); } @@ -3557,7 +3557,7 @@ void RT2QuadFiniteElement::GetLocalInterpolation ( if (j == k) { d -= 1.0; } if (fabs(d) > 1.0e-12) { - cerr << "RT2QuadFiniteElement::GetLocalInterpolation (...)\n" + mfem::err << "RT2QuadFiniteElement::GetLocalInterpolation (...)\n" " k = " << k << ", j = " << j << ", d = " << d << endl; mfem_error(); } @@ -5188,7 +5188,7 @@ void Nedelec1HexFiniteElement::GetLocalInterpolation ( if (j == k) { d -= 1.0; } if (fabs(d) > 1.0e-12) { - cerr << "Nedelec1HexFiniteElement::GetLocalInterpolation (...)\n" + mfem::err << "Nedelec1HexFiniteElement::GetLocalInterpolation (...)\n" " k = " << k << ", j = " << j << ", d = " << d << endl; mfem_error(); } @@ -5354,7 +5354,7 @@ void Nedelec1TetFiniteElement::GetLocalInterpolation ( if (j == k) { d -= 1.0; } if (fabs(d) > 1.0e-12) { - cerr << "Nedelec1TetFiniteElement::GetLocalInterpolation (...)\n" + mfem::err << "Nedelec1TetFiniteElement::GetLocalInterpolation (...)\n" " k = " << k << ", j = " << j << ", d = " << d << endl; mfem_error(); } @@ -5503,7 +5503,7 @@ void RT0HexFiniteElement::GetLocalInterpolation ( if (j == k) { d -= 1.0; } if (fabs(d) > 1.0e-12) { - cerr << "RT0HexFiniteElement::GetLocalInterpolation (...)\n" + mfem::err << "RT0HexFiniteElement::GetLocalInterpolation (...)\n" " k = " << k << ", j = " << j << ", d = " << d << endl; mfem_error(); } @@ -5892,7 +5892,7 @@ void RT1HexFiniteElement::GetLocalInterpolation ( if (j == k) { d -= 1.0; } if (fabs(d) > 1.0e-12) { - cerr << "RT0HexFiniteElement::GetLocalInterpolation (...)\n" + mfem::err << "RT0HexFiniteElement::GetLocalInterpolation (...)\n" " k = " << k << ", j = " << j << ", d = " << d << endl; mfem_error(); } @@ -6027,7 +6027,7 @@ void RT0TetFiniteElement::GetLocalInterpolation ( if (j == k) { d -= 1.0; } if (fabs(d) > 1.0e-12) { - cerr << "RT0TetFiniteElement::GetLocalInterpolation (...)\n" + mfem::err << "RT0TetFiniteElement::GetLocalInterpolation (...)\n" " k = " << k << ", j = " << j << ", d = " << d << endl; mfem_error(); } @@ -6184,7 +6184,7 @@ Poly_1D::Basis::Basis(const int p, const double *nodes, int _mode) } Ai.Factor(A); - // cout << "Poly_1D::Basis(" << p << ",...) : "; Ai.TestInversion(); + // mfem::out << "Poly_1D::Basis(" << p << ",...) : "; Ai.TestInversion(); } else { @@ -7530,7 +7530,7 @@ H1_TriangleElement::H1_TriangleElement(const int p, const int type) } Ti.Factor(T); - // cout << "H1_TriangleElement(" << p << ") : "; Ti.TestInversion(); + // mfem::out << "H1_TriangleElement(" << p << ") : "; Ti.TestInversion(); } void H1_TriangleElement::CalcShape(const IntegrationPoint &ip, @@ -7693,7 +7693,7 @@ H1_TetrahedronElement::H1_TetrahedronElement(const int p, const int type) } Ti.Factor(T); - // cout << "H1_TetrahedronElement(" << p << ") : "; Ti.TestInversion(); + // mfem::out << "H1_TetrahedronElement(" << p << ") : "; Ti.TestInversion(); } void H1_TetrahedronElement::CalcShape(const IntegrationPoint &ip, @@ -8734,7 +8734,7 @@ L2_TriangleElement::L2_TriangleElement(const int p, const int type) } Ti.Factor(T); - // cout << "L2_TriangleElement(" << p << ") : "; Ti.TestInversion(); + // mfem::out << "L2_TriangleElement(" << p << ") : "; Ti.TestInversion(); } void L2_TriangleElement::CalcShape(const IntegrationPoint &ip, @@ -8915,7 +8915,7 @@ L2_TetrahedronElement::L2_TetrahedronElement(const int p, const int type) } Ti.Factor(T); - // cout << "L2_TetrahedronElement(" << p << ") : "; Ti.TestInversion(); + // mfem::out << "L2_TetrahedronElement(" << p << ") : "; Ti.TestInversion(); } void L2_TetrahedronElement::CalcShape(const IntegrationPoint &ip, @@ -9667,7 +9667,7 @@ RT_TriangleElement::RT_TriangleElement(const int p) } Ti.Factor(T); - // cout << "RT_TriangleElement(" << p << ") : "; Ti.TestInversion(); + // mfem::out << "RT_TriangleElement(" << p << ") : "; Ti.TestInversion(); } void RT_TriangleElement::CalcVShape(const IntegrationPoint &ip, @@ -9844,7 +9844,7 @@ RT_TetrahedronElement::RT_TetrahedronElement(const int p) } Ti.Factor(T); - // cout << "RT_TetrahedronElement(" << p << ") : "; Ti.TestInversion(); + // mfem::out << "RT_TetrahedronElement(" << p << ") : "; Ti.TestInversion(); } void RT_TetrahedronElement::CalcVShape(const IntegrationPoint &ip, @@ -10637,7 +10637,7 @@ ND_TetrahedronElement::ND_TetrahedronElement(const int p) } Ti.Factor(T); - // cout << "ND_TetrahedronElement(" << p << ") : "; Ti.TestInversion(); + // mfem::out << "ND_TetrahedronElement(" << p << ") : "; Ti.TestInversion(); } void ND_TetrahedronElement::CalcVShape(const IntegrationPoint &ip, @@ -10832,7 +10832,7 @@ ND_TriangleElement::ND_TriangleElement(const int p) } Ti.Factor(T); - // cout << "ND_TriangleElement(" << p << ") : "; Ti.TestInversion(); + // mfem::out << "ND_TriangleElement(" << p << ") : "; Ti.TestInversion(); } void ND_TriangleElement::CalcVShape(const IntegrationPoint &ip, diff --git a/fem/fe_coll.cpp b/fem/fe_coll.cpp index fa016fd8ab..c51a605298 100644 --- a/fem/fe_coll.cpp +++ b/fem/fe_coll.cpp @@ -1841,8 +1841,8 @@ L2_FECollection::L2_FECollection(const int p, const int dim, const int type, } else { - cerr << "L2_FECollection::L2_FECollection : dim = " - << dim << endl; + mfem::err << "L2_FECollection::L2_FECollection : dim = " + << dim << endl; mfem_error(); } } @@ -2416,8 +2416,8 @@ Local_FECollection::Local_FECollection(const char *fe_name) } else { - cerr << "Local_FECollection::Local_FECollection : fe_name = " - << fe_name << endl; + mfem::err << "Local_FECollection::Local_FECollection : fe_name = " + << fe_name << endl; mfem_error(); } } diff --git a/fem/gridfunc.cpp b/fem/gridfunc.cpp index 9161d6fb4f..b0c2725555 100644 --- a/fem/gridfunc.cpp +++ b/fem/gridfunc.cpp @@ -2452,10 +2452,10 @@ void GridFunction::SaveSTL(std::ostream &out, int TimesToRefine) } } - cout << "[xmin,xmax] = [" << bbox[0][0] << ',' << bbox[0][1] << "]\n" - << "[ymin,ymax] = [" << bbox[1][0] << ',' << bbox[1][1] << "]\n" - << "[zmin,zmax] = [" << bbox[2][0] << ',' << bbox[2][1] << ']' - << endl; + out << "[xmin,xmax] = [" << bbox[0][0] << ',' << bbox[0][1] << "]\n" + << "[ymin,ymax] = [" << bbox[1][0] << ',' << bbox[1][1] << "]\n" + << "[zmin,zmax] = [" << bbox[2][0] << ',' << bbox[2][1] << ']' + << endl; out << "endsolid GridFunction" << endl; } @@ -2690,8 +2690,8 @@ GridFunction *Extrude1DGridFunction(Mesh *mesh, Mesh *mesh2d, } else { - cerr << "Extrude1DGridFunction : unknown FE collection : " - << cname << endl; + mfem::err << "Extrude1DGridFunction : unknown FE collection : " + << cname << endl; return NULL; } FiniteElementSpace *solfes2d; diff --git a/fem/hybridization.cpp b/fem/hybridization.cpp index 6b210f26d8..55d019f5d0 100644 --- a/fem/hybridization.cpp +++ b/fem/hybridization.cpp @@ -356,7 +356,7 @@ void Hybridization::Init(const Array &ess_tdof_list) #endif int i_size = Af_f_offsets[NE] - b_size; int e_size = num_hat_dofs - (i_size + b_size); - std::cout << "\nHybridization::Init:" + mfem::out << "\nHybridization::Init:" << " [" << myid << "] hat dofs - \"internal\": " << i_size << ", \"boundary\": " << b_size << ", \"essential\": " << e_size << '\n' << std::endl; diff --git a/fem/pgridfunc.hpp b/fem/pgridfunc.hpp index 0e27a0301b..5a9bf7c66c 100644 --- a/fem/pgridfunc.hpp +++ b/fem/pgridfunc.hpp @@ -18,6 +18,7 @@ #include "pfespace.hpp" #include "gridfunc.hpp" +#include "../general/globalostream.hpp" #include #include @@ -271,7 +272,7 @@ public: virtual void Save(std::ostream &out) const; /// Merge the local grid functions - void SaveAsOne(std::ostream &out = std::cout); + void SaveAsOne(std::ostream &out = mfem::out); virtual ~ParGridFunction() { } }; diff --git a/general/array.hpp b/general/array.hpp index 971b1cae53..d290637002 100644 --- a/general/array.hpp +++ b/general/array.hpp @@ -173,7 +173,7 @@ public: inline void GetSubArray(int offset, int sa_size, Array &sa); /// Prints array to stream with width elements per row - void Print(std::ostream &out = mout, int width = 4) const; + void Print(std::ostream &out = mfem::out, int width = 4) const; /** @brief Save the Array to the stream @a out using the format @a fmt. The format @a fmt can be: @@ -309,7 +309,7 @@ public: { N = master.N; array1d.MakeRef(master.array1d);} /// Prints array to stream with width elements per row - void Print(std::ostream &out = mout, int width = 4); + void Print(std::ostream &out = mfem::out, int width = 4); }; diff --git a/general/communication.cpp b/general/communication.cpp index cc2285a1e9..76ff36cecc 100644 --- a/general/communication.cpp +++ b/general/communication.cpp @@ -24,6 +24,7 @@ #include "communication.hpp" #include "text.hpp" #include "sort_pairs.hpp" +#include "globalostream.hpp" #include #include @@ -33,8 +34,12 @@ using namespace std; namespace mfem { -// Use this in place of MPI_COMM_WORLD so that it can be redirectable -MPI_Comm global_mpi_comm = MPI_COMM_WORLD; +void MPI_Session::GetRankAndSize() +{ + MPI_Comm_rank(MFEM_COMM_WORLD, &world_rank); + MPI_Comm_size(MFEM_COMM_WORLD, &world_size); +} + GroupTopology::GroupTopology(const GroupTopology >) : MyComm(gt.MyComm), @@ -187,7 +192,7 @@ void GroupTopology::Create(ListOfIntegerSets &groups, int mpitag) if (lproc_proc[groupmaster_lproc[g]] != status.MPI_SOURCE) { - merr << "\n\n\nGroupTopology::GroupTopology: " + mfem::err << "\n\n\nGroupTopology::GroupTopology: " << MyRank() << ": ERROR\n\n\n" << endl; mfem_error(); } @@ -1171,12 +1176,12 @@ static void DebugRankCoords(int** coords, int dim, int size) { for (int i = 0; i < size; i++) { - mout << "Rank " << i << " coords: "; + mfem::out << "Rank " << i << " coords: "; for (int j = 0; j < dim; j++) { - mout << coords[i][j] << " "; + mfem::out << coords[i][j] << " "; } - mout << endl; + mfem::out << endl; } } diff --git a/general/communication.hpp b/general/communication.hpp index 77236957cb..376e5a8a79 100644 --- a/general/communication.hpp +++ b/general/communication.hpp @@ -13,21 +13,20 @@ #define MFEM_COMMUNICATION #include "../config/config.hpp" -#include "globalostream.hpp" #ifdef MFEM_USE_MPI #include "array.hpp" #include "table.hpp" #include "sets.hpp" +#include "globalostream.hpp" +#include "globalcomm.hpp" #include namespace mfem { -extern MPI_Comm global_mpi_comm = MPI_COMM_WORLD; - /** @brief A simple convenience class that calls MPI_Init() at construction and MPI_Finalize() at destruction. It also provides easy access to to the global_mpi_comm rank and size. */ @@ -35,11 +34,7 @@ class MPI_Session { protected: int world_rank, world_size; - void GetRankAndSize() - { - MPI_Comm_rank(global_mpi_comm, &world_rank); - MPI_Comm_size(global_mpi_comm, &world_size); - } + void GetRankAndSize(); public: MPI_Session() { MPI_Init(NULL, NULL); GetRankAndSize(); } MPI_Session(int &argc, char **&argv) @@ -295,7 +290,7 @@ public: template static void BitOR(OpData); /// Print information about the GroupCommunicator from all MPI ranks. - void PrintInfo(std::ostream &out = mout) const; + void PrintInfo(std::ostream &out = mfem::out) const; /** @brief Destroy a GroupCommunicator object, deallocating internal data structures and buffers. */ diff --git a/general/error.cpp b/general/error.cpp index 3ccbbfa0a3..f5b960ed62 100644 --- a/general/error.cpp +++ b/general/error.cpp @@ -64,7 +64,7 @@ void mfem_backtrace(int mode, int depth) name_p = name_demangle; } - merr << addrs.Size() << ") [0x" << std::hex << ip - 1 << std::dec + mfem::err << addrs.Size() << ") [0x" << std::hex << ip - 1 << std::dec << "]: " << name_p << std::endl; addrs.Append(ip - 1); @@ -76,7 +76,7 @@ void mfem_backtrace(int mode, int depth) #if defined(__APPLE__) || defined(__linux__) if (addrs.Size() > 0 && (mode & 1)) { - merr << "\nLookup backtrace source lines:"; + mfem::err << "\nLookup backtrace source lines:"; const char *fname = NULL; for (int i = 0; i < addrs.Size(); i++) { @@ -89,17 +89,17 @@ void mfem_backtrace(int mode, int depth) else if (fname != info.dli_fname) { fname = info.dli_fname; - merr << '\n'; + mfem::err << '\n'; #ifdef __linux__ - merr << "addr2line -C -e " << fname; + mfem::err << "addr2line -C -e " << fname; #else - merr << "atos -o " << fname << " -l " + mfem::err << "atos -o " << fname << " -l " << (err ? 0 : info.dli_fbase); #endif } - merr << " 0x" << std::hex << addrs[i] << std::dec; + mfem::err << " 0x" << std::hex << addrs[i] << std::dec; } - merr << '\n'; + mfem::err << '\n'; } #endif #endif // MFEM_USE_LIBUNWIND @@ -110,22 +110,22 @@ void mfem_error(const char *msg) if (msg) { // NOTE: By default, each call of the "operator <<" method of the - // merr object results in flushing the I/O stream, which can be a + // mfem::err object results in flushing the I/O stream, which can be a // very bad thing if all your processors try to do it at the same time. - merr << "\n\n" << msg << "\n"; + mfem::err << "\n\n" << msg << "\n"; } #ifdef MFEM_USE_LIBUNWIND - merr << "Backtrace:" << std::endl; + mfem::err << "Backtrace:" << std::endl; mfem_backtrace(1, -1); - merr << std::endl; + mfem::err << std::endl; #endif #ifdef MFEM_USE_MPI int init_flag, fin_flag; MPI_Initialized(&init_flag); MPI_Finalized(&fin_flag); - if (init_flag && !fin_flag) { MPI_Abort(global_mpi_comm, 1); } + if (init_flag && !fin_flag) { MPI_Abort(MPI_COMM_WORLD, 1); } #endif std::abort(); // force crash by calling abort } @@ -134,7 +134,7 @@ void mfem_warning(const char *msg) { if (msg) { - mout << "\n\n" << msg << std::endl; + mfem::out << "\n\n" << msg << std::endl; } } diff --git a/general/globalcomm.cpp b/general/globalcomm.cpp new file mode 100644 index 0000000000..2268bfefe4 --- /dev/null +++ b/general/globalcomm.cpp @@ -0,0 +1,25 @@ +// Copyright (c) 2010, Lawrence Livermore National Security, LLC. Produced at +// the Lawrence Livermore National Laboratory. LLNL-CODE-443211. All Rights +// reserved. See file COPYRIGHT for details. +// +// This file is part of the MFEM library. For more information and source code +// availability see http://mfem.org. +// +// MFEM is free software; you can redistribute it and/or modify it under the +// terms of the GNU Lesser General Public License (as published by the Free +// Software Foundation) version 2.1 dated February 1999. + + +#include "../config/config.hpp" +#include "globalcomm.hpp" + +#ifdef MFEM_USE_MPI + +namespace mfem +{ + +extern MPI_Comm MFEM_COMM_WORLD = MPI_COMM_WORLD; + +} + +#endif \ No newline at end of file diff --git a/general/globalcomm.hpp b/general/globalcomm.hpp new file mode 100644 index 0000000000..b54e35f8a2 --- /dev/null +++ b/general/globalcomm.hpp @@ -0,0 +1,29 @@ +// Copyright (c) 2010, Lawrence Livermore National Security, LLC. Produced at +// the Lawrence Livermore National Laboratory. LLNL-CODE-443211. All Rights +// reserved. See file COPYRIGHT for details. +// +// This file is part of the MFEM library. For more information and source code +// availability see http://mfem.org. +// +// MFEM is free software; you can redistribute it and/or modify it under the +// terms of the GNU Lesser General Public License (as published by the Free +// Software Foundation) version 2.1 dated February 1999. + +#ifndef MFEM_GLOBAL_COMM +#define MFEM_GLOBAL_COMM + +#include "../config/config.hpp" +#include + +#ifdef MFEM_USE_MPI + +namespace mfem +{ + +extern MPI_Comm MFEM_COMM_WORLD; + +} + +#endif + +#endif \ No newline at end of file diff --git a/general/globalostream.cpp b/general/globalostream.cpp index 3912bc1c73..357f3ba207 100644 --- a/general/globalostream.cpp +++ b/general/globalostream.cpp @@ -1,9 +1,20 @@ +// Copyright (c) 2010, Lawrence Livermore National Security, LLC. Produced at +// the Lawrence Livermore National Laboratory. LLNL-CODE-443211. All Rights +// reserved. See file COPYRIGHT for details. +// +// This file is part of the MFEM library. For more information and source code +// availability see http://mfem.org. +// +// MFEM is free software; you can redistribute it and/or modify it under the +// terms of the GNU Lesser General Public License (as published by the Free +// Software Foundation) version 2.1 dated February 1999. + #include "globalostream.hpp" namespace mfem { -WrappedOStream mout(&std::cout); -WrappedOStream merr(&std::cerr); +WrappedOStream out(&std::cout); +WrappedOStream err(&std::cerr); } \ No newline at end of file diff --git a/general/globalostream.hpp b/general/globalostream.hpp index d29729df9a..6717de7660 100644 --- a/general/globalostream.hpp +++ b/general/globalostream.hpp @@ -13,7 +13,7 @@ #define MFEM_GLOBAL_OUTPUT_STREAM #include -#include "communication.hpp" +#include "globalcomm.hpp" namespace mfem { @@ -31,7 +31,7 @@ public: NullBuffer* rdbuf() { return this; } }; -class WrappedOStream +class WrappedOStream : public std::ostream { private: std::ostream *theStream; @@ -40,47 +40,44 @@ private: public: WrappedOStream() { theStream = &std::cout; Enable(); } WrappedOStream(std::ostream *stream) { theStream = stream; Enable(); } - void SetStream(std::ostream *stream) { theStream = stream; } - std::ostream& GetStream() { return *theStream; } - inline void Enable(); + inline void SetStream(std::ostream *stream) { theStream = stream; } + inline std::ostream& GetStream(); + inline void Enable() { enabled = true; } inline void Disable() { enabled = false; } - template - inline std::ostream& operator<<(T val); + inline bool IsEnabled() {return enabled;} }; -inline void WrappedOStream::Enable() -{ -#ifdef MFEM_USE_MPI - int rank; - MPI_Comm_rank(global_mpi_comm, &world_rank); - if (world_rank == 0) - { - enabled = true; - } - else - { - enabled = false; - } -#else - enabled = true; -#endif -} -template -inline std::ostream& WrappedOStream::operator<<(T val) -{ - if (enabled) +inline std::ostream& WrappedOStream::GetStream() +{ +#ifdef MFEM_USE_MPI + int world_rank; + MPI_Comm_rank(MFEM_COMM_WORLD, &world_rank); + if (enabled && world_rank == 0) { - (*theStream) << val; return *theStream; } +#else + if (enabled) + { + return *theStream; + } +#endif - nullStream << val; return nullStream; } -extern WrappedOStream mout; -extern WrappedOStream merr; + +template +std::ostream& operator <<(WrappedOStream& wos, T const& value) +{ + wos.GetStream() << value; + return wos.GetStream(); +} + + +extern WrappedOStream out; +extern WrappedOStream err; } diff --git a/general/hash.hpp b/general/hash.hpp index cc00b526af..18c14a4e03 100644 --- a/general/hash.hpp +++ b/general/hash.hpp @@ -413,7 +413,7 @@ void HashTable::DoRehash() mask = new_table_size-1; #if defined(MFEM_DEBUG) && !defined(MFEM_USE_MPI) - mout << _MFEM_FUNC_NAME << ": rehashing to size " << new_table_size + mfem::out << _MFEM_FUNC_NAME << ": rehashing to size " << new_table_size << std::endl; #endif @@ -500,7 +500,7 @@ long HashTable::MemoryUsage() const template void HashTable::PrintMemoryDetail() const { - mout << Base::MemoryUsage() << " + " << (mask+1) * sizeof(int) + mfem::out << Base::MemoryUsage() << " + " << (mask+1) * sizeof(int) << " + " << unused.MemoryUsage(); } diff --git a/general/isockstream.cpp b/general/isockstream.cpp index 0c580b943d..7d15d4178f 100644 --- a/general/isockstream.cpp +++ b/general/isockstream.cpp @@ -40,7 +40,7 @@ isockstream::isockstream(int port) portnum = port; if ( (portID = establish()) < 0) - mout << "Server couldn't be established on port " + mfem::out << "Server couldn't be established on port " << portnum << endl; Buf = NULL; } @@ -59,9 +59,9 @@ int isockstream::establish() if (hp == NULL) { - merr << "isockstream::establish(): gethostbyname() failed!\n" - << "isockstream::establish(): gethostname() returned: '" - << myname << "'" << endl; + mfem::err << "isockstream::establish(): gethostbyname() failed!\n" + << "isockstream::establish(): gethostname() returned: '" + << myname << "'" << endl; error = 1; return (-1); } @@ -71,7 +71,7 @@ int isockstream::establish() if ((port = socket(AF_INET, SOCK_STREAM, 0)) < 0) { - merr << "isockstream::establish(): socket() failed!" << endl; + mfem::err << "isockstream::establish(): socket() failed!" << endl; error = 2; return (-1); } @@ -81,7 +81,7 @@ int isockstream::establish() if (bind(port,(const sockaddr*)&sa,(socklen_t)sizeof(struct sockaddr_in)) < 0) { - merr << "isockstream::establish(): bind() failed!" << endl; + mfem::err << "isockstream::establish(): bind() failed!" << endl; close(port); error = 3; return (-1); @@ -132,7 +132,7 @@ void isockstream::receive(std::istringstream **in) if ((socketID = accept(portID, NULL, NULL)) < 0) { - mout << "Server failed to accept connection." << endl; + mfem::out << "Server failed to accept connection." << endl; error = 5; return; } @@ -151,12 +151,12 @@ void isockstream::receive(std::istringstream **in) Buf = new char[size+1]; if (size != read_data(socketID, Buf, size)) { - mout << "Not all the data has been read" << endl; + mfem::out << "Not all the data has been read" << endl; } #ifdef DEBUG else { - mout << "Reading " << size << " bytes is successful" << endl; + mfem::out << "Reading " << size << " bytes is successful" << endl; } #endif Buf[size] = '\0'; diff --git a/general/osockstream.cpp b/general/osockstream.cpp index f7503f17c0..7717a94c19 100644 --- a/general/osockstream.cpp +++ b/general/osockstream.cpp @@ -19,8 +19,8 @@ osockstream::osockstream(int port, const char *hostname) : socketstream(hostname, port) { if (!is_open()) - merr << "Unable to connect to port " << port << " on " - << hostname << '\n'; + mfem::err << "Unable to connect to port " << port << " on " + << hostname << '\n'; } } diff --git a/general/socketstream.cpp b/general/socketstream.cpp index 8d68139678..017165c41d 100644 --- a/general/socketstream.cpp +++ b/general/socketstream.cpp @@ -116,7 +116,7 @@ int socketbuf::close() int socketbuf::sync() { ssize_t bw, n = pptr() - pbase(); - // mout << "[socketbuf::sync n=" << n << ']' << std::endl; + // mfem::out << "[socketbuf::sync n=" << n << ']' << std::endl; while (n > 0) { #ifdef MSG_NOSIGNAL @@ -127,7 +127,7 @@ int socketbuf::sync() if (bw < 0) { #ifdef MFEM_DEBUG - mout << "Error in send(): " << strerror(errno) << std::endl; + mfem::out << "Error in send(): " << strerror(errno) << std::endl; #endif setp(pptr() - n, obuf + buflen); pbump(n); @@ -143,14 +143,14 @@ socketbuf::int_type socketbuf::underflow() { // assuming (gptr() < egptr()) is false ssize_t br = recv(socket_descriptor, ibuf, buflen, 0); - // mout << "[socketbuf::underflow br=" << br << ']' + // mfem::out << "[socketbuf::underflow br=" << br << ']' // << std::endl; if (br <= 0) { #ifdef MFEM_DEBUG if (br < 0) { - mout << "Error in recv(): " << strerror(errno) << std::endl; + mfem::out << "Error in recv(): " << strerror(errno) << std::endl; } #endif setg(NULL, NULL, NULL); @@ -177,7 +177,7 @@ socketbuf::int_type socketbuf::overflow(int_type c) std::streamsize socketbuf::xsgetn(char_type *__s, std::streamsize __n) { - // mout << "[socketbuf::xsgetn __n=" << __n << ']' + // mfem::out << "[socketbuf::xsgetn __n=" << __n << ']' // << std::endl; const std::streamsize bn = egptr() - gptr(); if (__n <= bn) @@ -199,7 +199,7 @@ std::streamsize socketbuf::xsgetn(char_type *__s, std::streamsize __n) #ifdef MFEM_DEBUG if (br < 0) { - mout << "Error in recv(): " << strerror(errno) << std::endl; + mfem::out << "Error in recv(): " << strerror(errno) << std::endl; } #endif return (__n - remain); @@ -211,7 +211,7 @@ std::streamsize socketbuf::xsgetn(char_type *__s, std::streamsize __n) std::streamsize socketbuf::xsputn(const char_type *__s, std::streamsize __n) { - // mout << "[socketbuf::xsputn __n=" << __n << ']' + // mfem::out << "[socketbuf::xsputn __n=" << __n << ']' // << std::endl; if (pptr() + __n <= epptr()) { @@ -236,7 +236,7 @@ std::streamsize socketbuf::xsputn(const char_type *__s, std::streamsize __n) if (bw < 0) { #ifdef MFEM_DEBUG - mout << "Error in send(): " << strerror(errno) << std::endl; + mfem::out << "Error in send(): " << strerror(errno) << std::endl; #endif return (__n - remain); } @@ -322,7 +322,7 @@ int socketserver::accept(socketstream &sockstr) static void mfem_gnutls_log_func(int level, const char *str) { - mout << "GnuTLS <" << level << "> " << str << std::flush; + mfem::out << "GnuTLS <" << level << "> " << str << std::flush; } GnuTLS_global_state::GnuTLS_global_state() @@ -361,10 +361,10 @@ void GnuTLS_global_state::generate_dh_params() #else unsigned bits = 1024; #endif - mout << "Generating DH params (" << bits << " bits) ..." + mfem::out << "Generating DH params (" << bits << " bits) ..." << std::flush; status.set_result(gnutls_dh_params_generate2(dh_params, bits)); - mout << " done." << std::endl; + mfem::out << " done." << std::endl; status.print_on_error("gnutls_dh_params_generate2"); if (!status.good()) { @@ -383,7 +383,7 @@ static int mfem_gnutls_verify_callback(gnutls_session_t session) int ret = gnutls_certificate_verify_peers3(session, hostname, &status); if (ret < 0) { - mout << "Error in gnutls_certificate_verify_peers3:" + mfem::out << "Error in gnutls_certificate_verify_peers3:" << gnutls_strerror(ret) << std::endl; return GNUTLS_E_CERTIFICATE_ERROR; } @@ -394,23 +394,23 @@ static int mfem_gnutls_verify_callback(gnutls_session_t session) ret = gnutls_certificate_verification_status_print(status, type, &out, 0); if (ret < 0) { - mout << "Error in gnutls_certificate_verification_status_print:" + mfem::out << "Error in gnutls_certificate_verification_status_print:" << gnutls_strerror(ret) << std::endl; return GNUTLS_E_CERTIFICATE_ERROR; } - mout << out.data << std::endl; + mfem::out << out.data << std::endl; gnutls_free(out.data); #endif #else // --> GNUTLS_VERSION_NUMBER < 0x030104 int ret = gnutls_certificate_verify_peers2(session, &status); if (ret < 0) { - mout << "Error in gnutls_certificate_verify_peers2:" + mfem::out << "Error in gnutls_certificate_verify_peers2:" << gnutls_strerror(ret) << std::endl; return GNUTLS_E_CERTIFICATE_ERROR; } #ifdef MFEM_DEBUG - mout << (status ? + mfem::out << (status ? "The certificate is NOT trusted." : "The certificate is trusted.") << std::endl; #endif @@ -483,7 +483,7 @@ GnuTLS_session_params::GnuTLS_session_params( void GnuTLS_socketbuf::handshake() { #ifdef MFEM_USE_GNUTLS_DEBUG - mout << "[GnuTLS_socketbuf::handshake]" << std::endl; + mfem::out << "[GnuTLS_socketbuf::handshake]" << std::endl; #endif // Called at the end of start_session. @@ -495,7 +495,7 @@ void GnuTLS_socketbuf::handshake() if (status.good()) { #if 0 - mout << "handshake successful, TLS version is " + mfem::out << "handshake successful, TLS version is " << gnutls_protocol_get_name( gnutls_protocol_get_version(session)) << std::endl; #endif @@ -521,7 +521,7 @@ static ssize_t mfem_gnutls_push_function( void GnuTLS_socketbuf::start_session() { #ifdef MFEM_USE_GNUTLS_DEBUG - mout << "[GnuTLS_socketbuf::start_session]" << std::endl; + mfem::out << "[GnuTLS_socketbuf::start_session]" << std::endl; #endif // check for valid 'socket_descriptor' and inactive session @@ -561,7 +561,7 @@ void GnuTLS_socketbuf::start_session() status.print_on_error("gnutls_priority_set_direct"); if (!status.good()) { - mout << "Error ptr = \"" << err_ptr << '"' << std::endl; + mfem::out << "Error ptr = \"" << err_ptr << '"' << std::endl; } } @@ -637,7 +637,7 @@ void GnuTLS_socketbuf::start_session() void GnuTLS_socketbuf::end_session() { #ifdef MFEM_USE_GNUTLS_DEBUG - mout << "[GnuTLS_socketbuf::end_session]" << std::endl; + mfem::out << "[GnuTLS_socketbuf::end_session]" << std::endl; #endif // check for valid 'socket_descriptor' @@ -647,7 +647,7 @@ void GnuTLS_socketbuf::end_session() { pubsync(); #ifdef MFEM_USE_GNUTLS_DEBUG - mout << "[GnuTLS_socketbuf::end_session: gnutls_bye]" << std::endl; + mfem::out << "[GnuTLS_socketbuf::end_session: gnutls_bye]" << std::endl; #endif int err; do @@ -667,7 +667,7 @@ void GnuTLS_socketbuf::end_session() int GnuTLS_socketbuf::attach(int sd) { #ifdef MFEM_USE_GNUTLS_DEBUG - mout << "[GnuTLS_socketbuf::attach]" << std::endl; + mfem::out << "[GnuTLS_socketbuf::attach]" << std::endl; #endif end_session(); @@ -682,7 +682,7 @@ int GnuTLS_socketbuf::attach(int sd) int GnuTLS_socketbuf::open(const char hostname[], int port) { #ifdef MFEM_USE_GNUTLS_DEBUG - mout << "[GnuTLS_socketbuf::open]" << std::endl; + mfem::out << "[GnuTLS_socketbuf::open]" << std::endl; #endif int err = socketbuf::open(hostname, port); // calls close() @@ -696,7 +696,7 @@ int GnuTLS_socketbuf::open(const char hostname[], int port) int GnuTLS_socketbuf::close() { #ifdef MFEM_USE_GNUTLS_DEBUG - mout << "[GnuTLS_socketbuf::close]" << std::endl; + mfem::out << "[GnuTLS_socketbuf::close]" << std::endl; #endif end_session(); @@ -710,7 +710,7 @@ int GnuTLS_socketbuf::sync() { ssize_t bw, n = pptr() - pbase(); #ifdef MFEM_USE_GNUTLS_DEBUG - mout << "[GnuTLS_socketbuf::sync n=" << n << ']' << std::endl; + mfem::out << "[GnuTLS_socketbuf::sync n=" << n << ']' << std::endl; #endif if (!session_started || !status.good()) { return -1; } while (n > 0) @@ -736,7 +736,7 @@ int GnuTLS_socketbuf::sync() GnuTLS_socketbuf::int_type GnuTLS_socketbuf::underflow() { #ifdef MFEM_USE_GNUTLS_DEBUG - mout << "[GnuTLS_socketbuf::underflow ...]" << std::endl; + mfem::out << "[GnuTLS_socketbuf::underflow ...]" << std::endl; #endif if (!session_started || !status.good()) { return traits_type::eof(); } @@ -751,7 +751,7 @@ GnuTLS_socketbuf::int_type GnuTLS_socketbuf::underflow() } while (br == GNUTLS_E_INTERRUPTED || br == GNUTLS_E_AGAIN); #ifdef MFEM_USE_GNUTLS_DEBUG - mout << "[GnuTLS_socketbuf::underflow br=" << br << ']' << std::endl; + mfem::out << "[GnuTLS_socketbuf::underflow br=" << br << ']' << std::endl; #endif if (br <= 0) @@ -773,7 +773,7 @@ GnuTLS_socketbuf::int_type GnuTLS_socketbuf::underflow() std::streamsize GnuTLS_socketbuf::xsgetn(char_type *__s, std::streamsize __n) { #ifdef MFEM_USE_GNUTLS_DEBUG - mout << "[GnuTLS_socketbuf::xsgetn __n=" << __n << ']' << std::endl; + mfem::out << "[GnuTLS_socketbuf::xsgetn __n=" << __n << ']' << std::endl; #endif if (!session_started || !status.good()) { return 0; } @@ -820,7 +820,7 @@ std::streamsize GnuTLS_socketbuf::xsputn(const char_type *__s, std::streamsize __n) { #ifdef MFEM_USE_GNUTLS_DEBUG - mout << "[GnuTLS_socketbuf::xsputn __n=" << __n << ']' << std::endl; + mfem::out << "[GnuTLS_socketbuf::xsputn __n=" << __n << ']' << std::endl; #endif if (!session_started || !status.good()) { return 0; } @@ -842,7 +842,7 @@ std::streamsize GnuTLS_socketbuf::xsputn(const char_type *__s, bw = gnutls_record_send(session, end - remain, remain); if (bw == GNUTLS_E_INTERRUPTED || bw == GNUTLS_E_AGAIN) { continue; } #ifdef MFEM_USE_GNUTLS_DEBUG - mout << "[GnuTLS_socketbuf::xsputn bw=" << bw << ']' << std::endl; + mfem::out << "[GnuTLS_socketbuf::xsputn bw=" << bw << ']' << std::endl; #endif if (bw < 0) { @@ -884,10 +884,10 @@ GnuTLS_session_params &socketstream::add_socket() GNUTLS_CLIENT); if (!params->status.good()) { - mout << " public key = " << pubkey << '\n' + mfem::out << " public key = " << pubkey << '\n' << " private key = " << privkey << '\n' << " trusted keys = " << trustedkeys << std::endl; - mout << "Error setting GLVis client parameters.\n" + mfem::out << "Error setting GLVis client parameters.\n" "Use the following GLVis script to create your GLVis keys:\n" " bash glvis-keygen.sh [\"Your Name\"] [\"Your Email\"]" << std::endl; diff --git a/general/socketstream.hpp b/general/socketstream.hpp index 642d931255..73fa458648 100644 --- a/general/socketstream.hpp +++ b/general/socketstream.hpp @@ -99,7 +99,7 @@ public: void print_on_error(const char *msg) const { if (good()) { return; } - mout << "Error in " << msg << ": " << gnutls_strerror(res) + mfem::out << "Error in " << msg << ": " << gnutls_strerror(res) << std::endl; } }; diff --git a/general/table.cpp b/general/table.cpp index f749179716..a15a237459 100644 --- a/general/table.cpp +++ b/general/table.cpp @@ -292,7 +292,7 @@ int Table::Width() const return width + 1; } -void Table::Print(WrappedOStream & out, int width) const +void Table::Print(std::ostream & out, int width) const { int i, j; diff --git a/general/table.hpp b/general/table.hpp index 518d882461..884ecd3028 100644 --- a/general/table.hpp +++ b/general/table.hpp @@ -142,7 +142,7 @@ public: void LoseData() { size = -1; I = J = NULL; } /// Prints the table to stream out. - void Print(WrappedOStream & out = mout, int width = 4) const; + void Print(std::ostream & out = mfem::out, int width = 4) const; void PrintMatlab(std::ostream & out) const; void Save(std::ostream &out) const; diff --git a/general/version.cpp b/general/version.cpp index e036112b34..26fcab2d33 100644 --- a/general/version.cpp +++ b/general/version.cpp @@ -18,16 +18,41 @@ namespace mfem { + +int get_version() +{ + return MFEM_VERSION; +} + + +int get_version_major() +{ + return MFEM_VERSION_MAJOR; +} + + +int get_version_minor() +{ + return MFEM_VERSION_MINOR; +} + + +int get_version_patch() +{ + return MFEM_VERSION_PATCH; +} + + const char *get_version_str() { - static const char *version_str = EXPAND_AND_QUOTE(MFEM_VERSION); - return version_str; + static const char *version_str = EXPAND_AND_QUOTE(MFEM_VERSION); + return version_str; } const char *get_config_str() { - static const char *config_str = "" + static const char *config_str = "" #ifdef MFEM_USE_MPI "MFEM_USE_MPI\n" #endif @@ -94,7 +119,7 @@ const char *get_config_str() "MFEM_TIMER_TYPE = " EXPAND_AND_QUOTE(MFEM_TIMER_TYPE) ; - return config_str; + return config_str; } } \ No newline at end of file diff --git a/general/version.hpp b/general/version.hpp index b264111acd..1231595953 100644 --- a/general/version.hpp +++ b/general/version.hpp @@ -15,6 +15,11 @@ namespace mfem { +int get_version(); +int get_version_major(); +int get_version_minor(); +int get_version_patch(); + const char *get_version_str(); const char *get_config_str(); diff --git a/linalg/blockmatrix.cpp b/linalg/blockmatrix.cpp index f5ac83b550..c02d25e321 100644 --- a/linalg/blockmatrix.cpp +++ b/linalg/blockmatrix.cpp @@ -10,6 +10,7 @@ // Software Foundation) version 2.1 dated February 1999. #include "../general/array.hpp" +#include "../general/globalostream.hpp" #include "matrix.hpp" #include "sparsemat.hpp" #include "blockvector.hpp" @@ -213,7 +214,7 @@ void BlockMatrix::EliminateRowCol(Array & ess_bc_dofs, Vector & sol, for (int iiblock = 0; iiblock < nRowBlocks; ++iiblock) if (row_offsets[iiblock] != col_offsets[iiblock]) { - std::cout << "BlockMatrix::EliminateRowCol: row_offests[" + mfem::out << "BlockMatrix::EliminateRowCol: row_offests[" << iiblock << "] != col_offsets["< nnz) { - std::cout<<"glob_start_index = " << glob_start_index << "\n"; - std::cout<<"Block:" << iblock << " " << jblock << "\n"; - std::cout< #include @@ -860,17 +861,17 @@ void dsyevr_Eigensystem(DenseMatrix &a, Vector &ev, DenseMatrix *evect) if (INFO != 0) { - cerr << "dsyevr_Eigensystem(...): DSYEVR error code: " - << INFO << endl; + mfem::err << "dsyevr_Eigensystem(...): DSYEVR error code: " + << INFO << endl; mfem_error(); } #ifdef MFEM_DEBUG if (M < N) { - cerr << "dsyevr_Eigensystem(...):\n" - << " DSYEVR did not find all eigenvalues " - << M << "/" << N << endl; + mfem::err << "dsyevr_Eigensystem(...):\n" + << " DSYEVR did not find all eigenvalues " + << M << "/" << N << endl; mfem_error(); } if (CheckFinite(W, N) > 0) @@ -904,19 +905,19 @@ void dsyevr_Eigensystem(DenseMatrix &a, Vector &ev, DenseMatrix *evect) } if (VU > 0.5) { - cerr << "dsyevr_Eigensystem(...):" - << " Z^t Z - I deviation = " << VU - << "\n W[max] = " << W[N-1] << ", W[min] = " - << W[0] << ", N = " << N << endl; + mfem::err << "dsyevr_Eigensystem(...):" + << " Z^t Z - I deviation = " << VU + << "\n W[max] = " << W[N-1] << ", W[min] = " + << W[0] << ", N = " << N << endl; mfem_error(); } } if (VU > 1e-9) { - cerr << "dsyevr_Eigensystem(...):" - << " Z^t Z - I deviation = " << VU - << "\n W[max] = " << W[N-1] << ", W[min] = " - << W[0] << ", N = " << N << endl; + mfem::err << "dsyevr_Eigensystem(...):" + << " Z^t Z - I deviation = " << VU + << "\n W[max] = " << W[N-1] << ", W[min] = " + << W[0] << ", N = " << N << endl; } if (VU > 1e-5) { @@ -939,10 +940,10 @@ void dsyevr_Eigensystem(DenseMatrix &a, Vector &ev, DenseMatrix *evect) } if (VU > 1e-9) { - cerr << "dsyevr_Eigensystem(...):" - << " max matrix deviation = " << VU - << "\n W[max] = " << W[N-1] << ", W[min] = " - << W[0] << ", N = " << N << endl; + mfem::err << "dsyevr_Eigensystem(...):" + << " max matrix deviation = " << VU + << "\n W[max] = " << W[N-1] << ", W[min] = " + << W[0] << ", N = " << N << endl; } if (VU > 1e-5) { @@ -1004,7 +1005,7 @@ void dsyev_Eigensystem(DenseMatrix &a, Vector &ev, DenseMatrix *evect) if (INFO != 0) { - cerr << "dsyev_Eigensystem: DSYEV error code: " << INFO << endl; + mfem::err << "dsyev_Eigensystem: DSYEV error code: " << INFO << endl; mfem_error(); } @@ -1059,7 +1060,7 @@ void DenseMatrix::SingularValues(Vector &sv) const delete [] work; if (info) { - cerr << "DenseMatrix::SingularValues : info = " << info << endl; + mfem::err << "DenseMatrix::SingularValues : info = " << info << endl; mfem_error(); } #else @@ -2864,8 +2865,8 @@ void DenseMatrix::TestInversion() { C(i,i) -= 1.0; } - cout << "size = " << width << ", i_max = " << C.MaxMaxNorm() - << ", cond_F = " << FNorm()*copy.FNorm() << endl; + mfem::out << "size = " << width << ", i_max = " << C.MaxMaxNorm() + << ", cond_F = " << FNorm()*copy.FNorm() << endl; } DenseMatrix::~DenseMatrix() @@ -4120,7 +4121,7 @@ void DenseMatrixInverse::TestInversion() { C(i,i) -= 1.0; } - cout << "size = " << width << ", i_max = " << C.MaxMaxNorm() << endl; + mfem::out << "size = " << width << ", i_max = " << C.MaxMaxNorm() << endl; } DenseMatrixInverse::~DenseMatrixInverse() @@ -4167,8 +4168,8 @@ void DenseMatrixEigensystem::Eval() if (info != 0) { - cerr << "DenseMatrixEigensystem::Eval(): DSYEV error code: " - << info << endl; + mfem::err << "DenseMatrixEigensystem::Eval(): DSYEV error code: " + << info << endl; mfem_error(); } #else @@ -4233,7 +4234,7 @@ void DenseMatrixSVD::Eval(DenseMatrix &M) if (info) { - cerr << "DenseMatrixSVD::Eval() : info = " << info << endl; + mfem::err << "DenseMatrixSVD::Eval() : info = " << info << endl; mfem_error(); } #else diff --git a/linalg/densemat.hpp b/linalg/densemat.hpp index 6a28118b8e..402d92168e 100644 --- a/linalg/densemat.hpp +++ b/linalg/densemat.hpp @@ -13,6 +13,7 @@ #define MFEM_DENSEMAT #include "../config/config.hpp" +#include "../general/globalostream.hpp" #include "matrix.hpp" namespace mfem @@ -303,10 +304,10 @@ public: int CheckFinite() const { return mfem::CheckFinite(data, height*width); } /// Prints matrix to stream out. - virtual void Print(std::ostream &out = std::cout, int width_ = 4) const; - virtual void PrintMatlab(std::ostream &out = std::cout) const; + virtual void Print(std::ostream &out = mfem::out, int width_ = 4) const; + virtual void PrintMatlab(std::ostream &out = mfem::out) const; /// Prints the transpose matrix to stream out. - virtual void PrintT(std::ostream &out = std::cout, int width_ = 4) const; + virtual void PrintT(std::ostream &out = mfem::out, int width_ = 4) const; /// Invert and print the numerical conditioning of the inversion. void TestInversion(); diff --git a/linalg/hypre.cpp b/linalg/hypre.cpp index 17999fa443..ab8673b2ca 100644 --- a/linalg/hypre.cpp +++ b/linalg/hypre.cpp @@ -2176,9 +2176,9 @@ void HyprePCG::Mult(const HypreParVector &b, HypreParVector &x) const if (myid == 0) { - cout << "PCG Iterations = " << num_iterations << endl - << "Final PCG Relative Residual Norm = " << final_res_norm - << endl; + mfem::out << "PCG Iterations = " << num_iterations << endl + << "Final PCG Relative Residual Norm = " << final_res_norm + << endl; } } HYPRE_ParCSRPCGSetPrintLevel(pcg_solver, print_level); @@ -2302,9 +2302,9 @@ void HypreGMRES::Mult(const HypreParVector &b, HypreParVector &x) const if (myid == 0) { - cout << "GMRES Iterations = " << num_iterations << endl - << "Final GMRES Relative Residual Norm = " << final_res_norm - << endl; + mfem::out << "GMRES Iterations = " << num_iterations << endl + << "Final GMRES Relative Residual Norm = " << final_res_norm + << endl; } } } diff --git a/linalg/hypre.hpp b/linalg/hypre.hpp index 73b8c9795f..d73b4eaab4 100644 --- a/linalg/hypre.hpp +++ b/linalg/hypre.hpp @@ -26,6 +26,7 @@ #include "_hypre_parcsr_mv.h" #include "_hypre_parcsr_ls.h" #include "temp_multivector.h" +#include "../general/globalostream.hpp" #ifdef HYPRE_COMPLEX #error "MFEM does not work with HYPRE's complex numbers support" @@ -465,7 +466,7 @@ public: void Read_IJMatrix(MPI_Comm comm, const char *fname); /// Print information about the hypre_ParCSRCommPkg of the HypreParMatrix. - void PrintCommPkg(std::ostream &out = std::cout) const; + void PrintCommPkg(std::ostream &out = mfem::out) const; /// Calls hypre's destroy function virtual ~HypreParMatrix() { Destroy(); } diff --git a/linalg/matrix.hpp b/linalg/matrix.hpp index 9be099ba8c..8e52bc8faa 100644 --- a/linalg/matrix.hpp +++ b/linalg/matrix.hpp @@ -13,6 +13,7 @@ #define MFEM_MATRIX #include "../general/array.hpp" +#include "../general/globalostream.hpp" #include "operator.hpp" #include @@ -47,7 +48,7 @@ public: virtual void Finalize(int) { } /// Prints matrix to stream out. - virtual void Print (std::ostream & out = std::cout, int width_ = 4) const; + virtual void Print (std::ostream & out = mfem::out, int width_ = 4) const; /// Destroys matrix. virtual ~Matrix() { } diff --git a/linalg/solvers.cpp b/linalg/solvers.cpp index 21d0a62f51..b412cac574 100644 --- a/linalg/solvers.cpp +++ b/linalg/solvers.cpp @@ -10,6 +10,7 @@ // Software Foundation) version 2.1 dated February 1999. #include "linalg.hpp" +#include "../general/globalostream.hpp" #include #include #include @@ -176,7 +177,7 @@ void SLISolver::Mult(const Vector &b, Vector &x) const } if (print_level == 1) - cout << " Iteration : " << setw(3) << 0 << " (B r, r) = " + mfem::out << " Iteration : " << setw(3) << 0 << " (B r, r) = " << nom << '\n'; r0 = std::max(nom*rel_tol*rel_tol, abs_tol*abs_tol); @@ -217,17 +218,17 @@ void SLISolver::Mult(const Vector &b, Vector &x) const cf = sqrt(nom/nomold); if (print_level == 1) - cout << " Iteration : " << setw(3) << i << " (B r, r) = " + mfem::out << " Iteration : " << setw(3) << i << " (B r, r) = " << nom << "\tConv. rate: " << cf << '\n'; nomold = nom; if (nom < r0) { if (print_level == 2) - cout << "Number of SLI iterations: " << i << '\n' + mfem::out << "Number of SLI iterations: " << i << '\n' << "Conv. rate: " << cf << '\n'; else if (print_level == 3) - cout << "(B r_0, r_0) = " << nom0 << '\n' + mfem::out << "(B r_0, r_0) = " << nom0 << '\n' << "(B r_N, r_N) = " << nom << '\n' << "Number of SLI iterations: " << i << '\n'; converged = 1; @@ -243,14 +244,14 @@ void SLISolver::Mult(const Vector &b, Vector &x) const if (print_level >= 0 && !converged) { - cerr << "SLI: No convergence!" << '\n'; - cout << "(B r_0, r_0) = " << nom0 << '\n' + mfem::err << "SLI: No convergence!" << '\n'; + mfem::out << "(B r_0, r_0) = " << nom0 << '\n' << "(B r_N, r_N) = " << nom << '\n' << "Number of SLI iterations: " << final_iter << '\n'; } if (print_level >= 1 || (print_level >= 0 && !converged)) { - cout << "Average reduction factor = " + mfem::out << "Average reduction factor = " << pow (nom/nom0, 0.5/final_iter) << '\n'; } final_norm = sqrt(nom); @@ -321,7 +322,7 @@ void CGSolver::Mult(const Vector &b, Vector &x) const if (print_level == 1 || print_level == 3) { - cout << " Iteration : " << setw(3) << 0 << " (B r, r) = " + mfem::out << " Iteration : " << setw(3) << 0 << " (B r, r) = " << nom << (print_level == 3 ? " ...\n" : "\n"); } @@ -340,7 +341,7 @@ void CGSolver::Mult(const Vector &b, Vector &x) const if (print_level >= 0 && den < 0.0) { - cout << "Negative denominator in step 0 of PCG: " << den << '\n'; + mfem::out << "Negative denominator in step 0 of PCG: " << den << '\n'; } if (den == 0.0) @@ -373,7 +374,7 @@ void CGSolver::Mult(const Vector &b, Vector &x) const if (print_level == 1) { - cout << " Iteration : " << setw(3) << i << " (B r, r) = " + mfem::out << " Iteration : " << setw(3) << i << " (B r, r) = " << betanom << '\n'; } @@ -381,11 +382,11 @@ void CGSolver::Mult(const Vector &b, Vector &x) const { if (print_level == 2) { - cout << "Number of PCG iterations: " << i << '\n'; + mfem::out << "Number of PCG iterations: " << i << '\n'; } else if (print_level == 3) { - cout << " Iteration : " << setw(3) << i << " (B r, r) = " + mfem::out << " Iteration : " << setw(3) << i << " (B r, r) = " << betanom << '\n'; } converged = 1; @@ -413,7 +414,7 @@ void CGSolver::Mult(const Vector &b, Vector &x) const if (den <= 0.0) { if (print_level >= 0 && Dot(d, d) > 0.0) - cout << "PCG: The operator is not positive definite. (Ad, d) = " + mfem::out << "PCG: The operator is not positive definite. (Ad, d) = " << den << '\n'; } nom = betanom; @@ -424,17 +425,17 @@ void CGSolver::Mult(const Vector &b, Vector &x) const { if (print_level != 3) { - cout << " Iteration : " << setw(3) << 0 << " (B r, r) = " + mfem::out << " Iteration : " << setw(3) << 0 << " (B r, r) = " << nom0 << " ...\n"; } - cout << " Iteration : " << setw(3) << final_iter << " (B r, r) = " + mfem::out << " Iteration : " << setw(3) << final_iter << " (B r, r) = " << betanom << '\n'; } - cout << "PCG: No convergence!" << '\n'; + mfem::out << "PCG: No convergence!" << '\n'; } if (print_level >= 1 || (print_level >= 0 && !converged)) { - cout << "Average reduction factor = " + mfem::out << "Average reduction factor = " << pow (betanom/nom0, 0.5/final_iter) << '\n'; } final_norm = sqrt(betanom); @@ -580,7 +581,7 @@ void GMRESSolver::Mult(const Vector &b, Vector &x) const if (print_level == 1 || print_level == 3) { - cout << " Pass : " << setw(2) << 1 + mfem::out << " Pass : " << setw(2) << 1 << " Iteration : " << setw(3) << 0 << " ||B r|| = " << beta << (print_level == 3 ? " ...\n" : "\n"); } @@ -639,7 +640,7 @@ void GMRESSolver::Mult(const Vector &b, Vector &x) const if (print_level == 1) { - cout << " Pass : " << setw(2) << (j-1)/m+1 + mfem::out << " Pass : " << setw(2) << (j-1)/m+1 << " Iteration : " << setw(3) << j << " ||B r|| = " << resid << '\n'; } @@ -647,7 +648,7 @@ void GMRESSolver::Mult(const Vector &b, Vector &x) const if (print_level == 1 && j <= max_iter) { - cout << "Restarting..." << '\n'; + mfem::out << "Restarting..." << '\n'; } Update(x, i-1, H, s, v); @@ -680,17 +681,17 @@ void GMRESSolver::Mult(const Vector &b, Vector &x) const finish: if (print_level == 1 || print_level == 3) { - cout << " Pass : " << setw(2) << (final_iter-1)/m+1 + mfem::out << " Pass : " << setw(2) << (final_iter-1)/m+1 << " Iteration : " << setw(3) << final_iter << " ||B r|| = " << final_norm << '\n'; } else if (print_level == 2) { - cout << "GMRES: Number of iterations: " << final_iter << '\n'; + mfem::out << "GMRES: Number of iterations: " << final_iter << '\n'; } if (print_level >= 0 && !converged) { - cout << "GMRES: No convergence!\n"; + mfem::out << "GMRES: No convergence!\n"; } for (i = 0; i < v.Size(); i++) { @@ -731,7 +732,7 @@ void FGMRESSolver::Mult(const Vector &b, Vector &x) const } if (print_level>=0) - cout << " Pass : " << setw(2) << 1 + mfem::out << " Pass : " << setw(2) << 1 << " Iteration : " << setw(3) << 0 << " || r || = " << beta << endl; @@ -783,7 +784,7 @@ void FGMRESSolver::Mult(const Vector &b, Vector &x) const double resid = fabs(s(i+1)); MFEM_ASSERT(IsFinite(resid), "resid = " << resid); if (print_level >= 0) - cout << " Pass : " << setw(2) << j + mfem::out << " Pass : " << setw(2) << j << " Iteration : " << setw(3) << i+1 << " || r || = " << resid << endl; @@ -804,7 +805,7 @@ void FGMRESSolver::Mult(const Vector &b, Vector &x) const if (print_level>=0) { - cout << "Restarting..." << endl; + mfem::out << "Restarting..." << endl; } Update(x, i-1, H, s, z); @@ -900,7 +901,7 @@ void BiCGSTABSolver::Mult(const Vector &b, Vector &x) const resid = Norm(r); MFEM_ASSERT(IsFinite(resid), "resid = " << resid); if (print_level >= 0) - cout << " Iteration : " << setw(3) << 0 + mfem::out << " Iteration : " << setw(3) << 0 << " ||r|| = " << resid << '\n'; tol_goal = std::max(resid*rel_tol, abs_tol); @@ -919,7 +920,7 @@ void BiCGSTABSolver::Mult(const Vector &b, Vector &x) const if (rho_1 == 0) { if (print_level >= 0) - cout << " Iteration : " << setw(3) << i + mfem::out << " Iteration : " << setw(3) << i << " ||r|| = " << resid << '\n'; final_norm = resid; final_iter = i; @@ -953,7 +954,7 @@ void BiCGSTABSolver::Mult(const Vector &b, Vector &x) const { x.Add(alpha, phat); // x = x + alpha * phat if (print_level >= 0) - cout << " Iteration : " << setw(3) << i + mfem::out << " Iteration : " << setw(3) << i << " ||s|| = " << resid << '\n'; final_norm = resid; final_iter = i; @@ -961,7 +962,7 @@ void BiCGSTABSolver::Mult(const Vector &b, Vector &x) const return; } if (print_level >= 0) - cout << " Iteration : " << setw(3) << i + mfem::out << " Iteration : " << setw(3) << i << " ||s|| = " << resid; if (prec) { @@ -982,7 +983,7 @@ void BiCGSTABSolver::Mult(const Vector &b, Vector &x) const MFEM_ASSERT(IsFinite(resid), "resid = " << resid); if (print_level >= 0) { - cout << " ||r|| = " << resid << '\n'; + mfem::out << " ||r|| = " << resid << '\n'; } if (resid < tol_goal) { @@ -1086,7 +1087,7 @@ void MINRESSolver::Mult(const Vector &b, Vector &x) const if (print_level == 1 || print_level == 3) { - cout << "MINRES: iteration " << setw(3) << 0 << ": ||r||_B = " + mfem::out << "MINRES: iteration " << setw(3) << 0 << ": ||r||_B = " << eta << (print_level == 3 ? " ...\n" : "\n"); } @@ -1153,7 +1154,7 @@ void MINRESSolver::Mult(const Vector &b, Vector &x) const if (print_level == 1) { - cout << "MINRES: iteration " << setw(3) << it << ": ||r||_B = " + mfem::out << "MINRES: iteration " << setw(3) << it << ": ||r||_B = " << fabs(eta) << '\n'; } @@ -1173,12 +1174,12 @@ loop_end: if (print_level == 1 || print_level == 3) { - cout << "MINRES: iteration " << setw(3) << final_iter << ": ||r||_B = " + mfem::out << "MINRES: iteration " << setw(3) << final_iter << ": ||r||_B = " << final_norm << '\n'; } else if (print_level == 2) { - cout << "MINRES: number of iterations: " << final_iter << '\n'; + mfem::out << "MINRES: number of iterations: " << final_iter << '\n'; } #if 0 if (print_level >= 1) @@ -1190,13 +1191,13 @@ loop_end: prec->Mult(v1, u1); } eta = sqrt(Dot(*z, v1)); - cout << "MINRES: iteration " << setw(3) << it << ": ||r||_B = " + mfem::out << "MINRES: iteration " << setw(3) << it << ": ||r||_B = " << eta << " (re-computed)" << '\n'; } #endif if (!converged && print_level >= 0) { - cout << "MINRES: No convergence!\n"; + mfem::out << "MINRES: No convergence!\n"; } } @@ -1267,7 +1268,7 @@ void NewtonSolver::Mult(const Vector &b, Vector &x) const { MFEM_ASSERT(IsFinite(norm), "norm = " << norm); if (print_level >= 0) - cout << "Newton iteration " << setw(2) << it + mfem::out << "Newton iteration " << setw(2) << it << " : ||r|| = " << norm << '\n'; if (norm <= norm_goal) @@ -1340,7 +1341,7 @@ int aGMRES(const Operator &A, Vector &x, const Vector &b, } if (printit) - cout << " Pass : " << setw(2) << 1 + mfem::out << " Pass : " << setw(2) << 1 << " Iteration : " << setw(3) << 0 << " (r, r) = " << beta*beta << '\n'; @@ -1390,7 +1391,7 @@ int aGMRES(const Operator &A, Vector &x, const Vector &b, resid = fabs(s(i+1)); if (printit) - cout << " Pass : " << setw(2) << j + mfem::out << " Pass : " << setw(2) << j << " Iteration : " << setw(3) << i+1 << " (r, r) = " << resid*resid << '\n'; @@ -1409,7 +1410,7 @@ int aGMRES(const Operator &A, Vector &x, const Vector &b, if (printit) { - cout << "Restarting..." << '\n'; + mfem::out << "Restarting..." << '\n'; } Update(x, i-1, H, s, v); @@ -1480,7 +1481,7 @@ void SLBQPOptimizer::SetOperator(const Operator &op) inline void SLBQPOptimizer::print_iteration(int it, double r, double l) const { if (print_level > 1) - cout << "SLBQP iteration " << it << ": residual = " << r + mfem::out << "SLBQP iteration " << it << ": residual = " << r << ", lambda = " << l << '\n'; } @@ -1510,7 +1511,7 @@ void SLBQPOptimizer::Mult(const Vector& xt, Vector& x) const // *** Start bracketing phase of SLBQP *** if (print_level > 1) { - cout << "SLBQP bracketing phase" << '\n'; + mfem::out << "SLBQP bracketing phase" << '\n'; } // Solve QP with fixed Lagrange multiplier @@ -1579,7 +1580,7 @@ void SLBQPOptimizer::Mult(const Vector& xt, Vector& x) const // *** Start secant phase of SLBQP *** if (print_level > 1) { - cout << "SLBQP secant phase" << '\n'; + mfem::out << "SLBQP secant phase" << '\n'; } s = 1.0 - rlow/rupp; dl = dl/s; l = lupp - dl; @@ -1638,7 +1639,7 @@ void SLBQPOptimizer::Mult(const Vector& xt, Vector& x) const converged = (fabs(r) <= tol); if (!converged && print_level >= 0) { - cerr << "SLBQP not converged!" << '\n'; + mfem::err << "SLBQP not converged!" << '\n'; } slbqp_done: @@ -1648,9 +1649,9 @@ slbqp_done: if (print_level == 1 || (!converged && print_level >= 0)) { - cout << "SLBQP iterations = " << nclip << '\n'; - cout << "SLBQP lambda = " << l << '\n'; - cout << "SLBQP residual = " << r << '\n'; + mfem::out << "SLBQP iterations = " << nclip << '\n'; + mfem::out << "SLBQP lambda = " << l << '\n'; + mfem::out << "SLBQP residual = " << r << '\n'; } } diff --git a/linalg/sparsemat.hpp b/linalg/sparsemat.hpp index d391abdb69..8242e78bdb 100644 --- a/linalg/sparsemat.hpp +++ b/linalg/sparsemat.hpp @@ -16,6 +16,7 @@ #include "../general/mem_alloc.hpp" #include "../general/table.hpp" +#include "../general/globalostream.hpp" #include "densemat.hpp" #include @@ -352,13 +353,13 @@ public: SparseMatrix &operator*=(double a); /// Prints matrix to stream out. - void Print(std::ostream &out = std::cout, int width_ = 4) const; + void Print(std::ostream &out = mfem::out, int width_ = 4) const; /// Prints matrix in matlab format. - void PrintMatlab(std::ostream &out = std::cout) const; + void PrintMatlab(std::ostream &out = mfem::out) const; /// Prints matrix in Matrix Market sparse format. - void PrintMM(std::ostream &out = std::cout) const; + void PrintMM(std::ostream &out = mfem::out) const; /// Prints matrix to stream out in hypre_CSRMatrix format. void PrintCSR(std::ostream &out) const; diff --git a/linalg/sundials.cpp b/linalg/sundials.cpp index d9dae5b805..41e0bfd0f4 100644 --- a/linalg/sundials.cpp +++ b/linalg/sundials.cpp @@ -356,7 +356,7 @@ void CVODESolver::PrintInfo() const { CVodeMem mem = Mem(this); - cout << + mfem::out << "CVODE:\n " "num steps: " << mem->cv_nst << ", " "num evals: " << mem->cv_nfe << ", " @@ -637,7 +637,7 @@ void ARKODESolver::PrintInfo() const { ARKodeMem mem = Mem(this); - cout << + mfem::out << "ARKODE:\n " "num steps: " << mem->ark_nst << ", " "num evals: " << mem->ark_nfe << ", " diff --git a/linalg/superlu.cpp b/linalg/superlu.cpp index 36d2fc0133..5c37257d3b 100644 --- a/linalg/superlu.cpp +++ b/linalg/superlu.cpp @@ -410,9 +410,9 @@ void SuperLUSolver::SetupGrid() { if ( myid_ == 0 ) { - cerr << "Warning: User specified nprow and npcol are such that " - << "(nprow * npcol) > numProcs or (nprow * npcol) < 1. " - << "Using default values for nprow and npcol instead." << endl; + mfem:err << "Warning: User specified nprow and npcol are such that " + << "(nprow * npcol) > numProcs or (nprow * npcol) < 1. " + << "Using default values for nprow and npcol instead." << endl; } nprow_ = (int)superlu_internal::sqrti((unsigned int)numProcs_); diff --git a/linalg/vector.hpp b/linalg/vector.hpp index e08642f186..4bf98b645c 100644 --- a/linalg/vector.hpp +++ b/linalg/vector.hpp @@ -15,6 +15,7 @@ // Data type vector #include "../general/array.hpp" +#include "../general/globalostream.hpp" #ifdef MFEM_USE_SUNDIALS #include #endif @@ -230,7 +231,7 @@ public: void SetSubVectorComplement(const Array &dofs, const double val); /// Prints vector to stream out. - void Print(std::ostream & out = std::cout, int width = 8) const; + void Print(std::ostream & out = mfem::out, int width = 8) const; /// Prints vector to stream out in HYPRE_Vector format. void Print_HYPRE(std::ostream &out) const; diff --git a/mesh/mesh.cpp b/mesh/mesh.cpp index 388aef7e66..fd06351581 100644 --- a/mesh/mesh.cpp +++ b/mesh/mesh.cpp @@ -1507,7 +1507,7 @@ void Mesh::DoNodeReorder(DSTable *old_v_to_v, Table *old_elem_vert) offset += NumOfEdges * num_edge_dofs; } #ifdef MFEM_DEBUG - cout << "Mesh::DoNodeReorder : redges = " << redges << endl; + mfem::out << "Mesh::DoNodeReorder : redges = " << redges << endl; #endif // face dofs: @@ -1607,7 +1607,7 @@ void Mesh::DoNodeReorder(DSTable *old_v_to_v, Table *old_elem_vert) break; default: new_or = 0; - cerr << "Mesh::DoNodeReorder : " << Geometry::Name[geom] + mfem::err << "Mesh::DoNodeReorder : " << Geometry::Name[geom] << " elements (" << fec->Name() << " FE collection) are not supported yet!" << endl; mfem_error(); @@ -1616,7 +1616,7 @@ void Mesh::DoNodeReorder(DSTable *old_v_to_v, Table *old_elem_vert) dof_ord = fec->DofOrderForOrientation(geom, new_or); if (dof_ord == NULL) { - cerr << "Mesh::DoNodeReorder : FE collection '" << fec->Name() + mfem::err << "Mesh::DoNodeReorder : FE collection '" << fec->Name() << "' does not define reordering for " << Geometry::Name[geom] << " elements!" << endl; mfem_error(); @@ -3437,7 +3437,7 @@ int Mesh::CheckElementOrientation(bool fix_it) } #if (!defined(MFEM_USE_MPI) || defined(MFEM_DEBUG)) if (wo > 0) - cout << "Elements with wrong orientation: " << wo << " / " + mfem::out << "Elements with wrong orientation: " << wo << " / " << NumOfElements << " (" << fixed_or_not[(wo == fo) ? 0 : 1] << ")" << endl; #endif @@ -3516,18 +3516,18 @@ int Mesh::GetQuadOrientation(const int *base, const int *test) for (int j = 0; j < 4; j++) if (test[aor[j]] != base[j]) { - cerr << "Mesh::GetQuadOrientation(...)" << endl; - cerr << " base = ["; + mfem::err << "Mesh::GetQuadOrientation(...)" << endl; + mfem::err << " base = ["; for (int k = 0; k < 4; k++) { - cerr << " " << base[k]; + mfem::err << " " << base[k]; } - cerr << " ]\n test = ["; + mfem::err << " ]\n test = ["; for (int k = 0; k < 4; k++) { - cerr << " " << test[k]; + mfem::err << " " << test[k]; } - cerr << " ]" << endl; + mfem::err << " ]" << endl; mfem_error(); } #endif @@ -3634,7 +3634,7 @@ int Mesh::CheckBdrElementOrientation(bool fix_it) #ifdef MFEM_DEBUG if (wo > 0) { - cout << "Boundary elements with wrong orientation: " << wo << " / " + mfem::out << "Boundary elements with wrong orientation: " << wo << " / " << NumOfBdrElements << " (" << fixed_or_not[fix_it ? 0 : 1] << ")" << endl; } @@ -4767,7 +4767,7 @@ int *Mesh::GeneratePartitioning(int nparts, int part_method) } #ifdef MFEM_DEBUG - cout << "Mesh::GeneratePartitioning(...): edgecut = " + mfem::out << "Mesh::GeneratePartitioning(...): edgecut = " << edgecut << endl; #endif } @@ -4803,7 +4803,7 @@ int *Mesh::GeneratePartitioning(int nparts, int part_method) // Do we need to replace it with something better? if (empty_parts) { - cerr << "Mesh::GeneratePartitioning returned " << empty_parts + mfem::err << "Mesh::GeneratePartitioning returned " << empty_parts << " empty parts!" << endl; SortPairs(psize, nparts); @@ -4934,28 +4934,28 @@ void Mesh::CheckPartitioning(int *partitioning) if (n_empty > 0) { - cout << "Mesh::CheckPartitioning(...) :\n" + mfem::out << "Mesh::CheckPartitioning(...) :\n" << "The following subdomains are empty :\n"; for (i = 0; i < num_comp.Size(); i++) if (num_comp[i] == 0) { - cout << ' ' << i; + mfem::out << ' ' << i; } - cout << endl; + mfem::out << endl; } if (n_mcomp > 0) { - cout << "Mesh::CheckPartitioning(...) :\n" + mfem::out << "Mesh::CheckPartitioning(...) :\n" << "The following subdomains are NOT connected :\n"; for (i = 0; i < num_comp.Size(); i++) if (num_comp[i] > 1) { - cout << ' ' << i; + mfem::out << ' ' << i; } - cout << endl; + mfem::out << endl; } if (n_empty == 0 && n_mcomp == 0) - cout << "Mesh::CheckPartitioning(...) : " + mfem::out << "Mesh::CheckPartitioning(...) : " "All subdomains are connected." << endl; if (el_to_el) @@ -5933,7 +5933,7 @@ void Mesh::LocalRefinement(const Array &marked_el, int type) } while (need_refinement == 1); - // cout << "Maximum generation: " << max_gen << endl; + // mfem::out << "Maximum generation: " << max_gen << endl; // 5. Update the boundary elements. do @@ -6559,7 +6559,7 @@ void Mesh::Bisection(int i, const DSTable &v_to_v, if (bisect == -1) { tet->ParseRefinementFlag(old_redges, type, flag); - cerr << "Error in Bisection(...) of tetrahedron!" << endl + mfem::err << "Error in Bisection(...) of tetrahedron!" << endl << " redge[0] = " << old_redges[0] << " redge[1] = " << old_redges[1] << " type = " << type @@ -7258,7 +7258,7 @@ void Mesh::PrintVTK(std::ostream &out) } if (order == -1) { - cerr << "Mesh::PrintVTK : can not save '" + mfem::err << "Mesh::PrintVTK : can not save '" << fec_name << "' elements!" << endl; mfem_error(); } @@ -8668,7 +8668,7 @@ Mesh *Extrude1D(Mesh *mesh, const int ny, const double sy, const bool closed) { if (mesh->Dimension() != 1) { - cerr << "Extrude1D : Not a 1D mesh!" << endl; + mfem::err << "Extrude1D : Not a 1D mesh!" << endl; mfem_error(); } @@ -8796,7 +8796,7 @@ Mesh *Extrude1D(Mesh *mesh, const int ny, const double sy, const bool closed) else { delete mesh2d; - cerr << "Extrude1D : The mesh uses unknown FE collection : " + mfem::err << "Extrude1D : The mesh uses unknown FE collection : " << cname << endl; mfem_error(); } diff --git a/mesh/mesh.hpp b/mesh/mesh.hpp index 5a36d31c6e..8a91afbb29 100644 --- a/mesh/mesh.hpp +++ b/mesh/mesh.hpp @@ -14,6 +14,7 @@ #include "../config/config.hpp" #include "../general/stable3d.hpp" +#include "../general/globalostream.hpp" #include "triangle.hpp" #include "tetrahedron.hpp" #include "vertex.hpp" @@ -375,7 +376,7 @@ protected: // If NURBS mesh, write NURBS format. If NCMesh, write mfem v1.1 format. // If section_delimiter is empty, write mfem v1.0 format. Otherwise, write // mfem v1.2 format with the given section_delimiter at the end. - void Printer(std::ostream &out = std::cout, + void Printer(std::ostream &out = mfem::out, std::string section_delimiter = "") const; /** Creates mesh for the parallelepiped [0,sx]x[0,sy]x[0,sz], divided into @@ -1014,11 +1015,11 @@ public: long GetSequence() const { return sequence; } /// Print the mesh to the given stream using Netgen/Truegrid format. - virtual void PrintXG(std::ostream &out = std::cout) const; + virtual void PrintXG(std::ostream &out = mfem::out) const; /// Print the mesh to the given stream using the default MFEM mesh format. /// \see mfem::ogzstream() for on-the-fly compression of ascii outputs - virtual void Print(std::ostream &out = std::cout) const { Printer(out); } + virtual void Print(std::ostream &out = mfem::out) const { Printer(out); } /// Print the mesh in VTK format (linear and quadratic meshes only). /// \see mfem::ogzstream() for on-the-fly compression of ascii outputs @@ -1081,9 +1082,9 @@ public: Vector *Vh = NULL, Vector *Vk = NULL); void PrintCharacteristics(Vector *Vh = NULL, Vector *Vk = NULL, - std::ostream &out = std::cout); + std::ostream &out = mfem::out); - virtual void PrintInfo(std::ostream &out = std::cout) + virtual void PrintInfo(std::ostream &out = mfem::out) { PrintCharacteristics(NULL, NULL, out); } diff --git a/mesh/mesh_readers.cpp b/mesh/mesh_readers.cpp index 7e42380b65..56f0e80128 100644 --- a/mesh/mesh_readers.cpp +++ b/mesh/mesh_readers.cpp @@ -1765,8 +1765,8 @@ void Mesh::ReadCubit(const char *filename, int &curved, int &read_gf) // int nTotDofs = fes->GetNDofs(); // int nTotVDofs = fes->GetVSize(); - // cout << endl << "nTotDofs = " << nTotDofs << " nTotVDofs " - // << nTotVDofs << endl << endl; + // mfem::out << endl << "nTotDofs = " << nTotDofs << " nTotVDofs " + // << nTotVDofs << endl << endl; for (int i = 0; i < NumOfElements; i++) { diff --git a/mesh/mesquite.cpp b/mesh/mesquite.cpp index 12553840d3..cfc57a0198 100644 --- a/mesh/mesquite.cpp +++ b/mesh/mesquite.cpp @@ -715,7 +715,7 @@ void MesquiteMesh::elements_get_topologies(const ElementHandle MesquiteMesh::~MesquiteMesh() { - MsqPrintError err(cerr); + MsqPrintError err(mfem::err.GetStream()); delete myTags; delete dof_elem; @@ -847,7 +847,7 @@ static void BoundaryPreservingOptimization(mfem::MesquiteMesh &mesh) { MsqDebug::enable(1); - MsqPrintError err(cerr); + MsqPrintError err(mfem::err.GetStream()); int pOrder = 2; int mNumInterfaceSmoothIters = 5; @@ -858,14 +858,14 @@ static void BoundaryPreservingOptimization(mfem::MesquiteMesh &mesh) // get all vertices std::vector vertices; mesh.get_all_vertices(vertices, err); - if (MSQ_CHKERR(err)) {std::cout << err << std::endl; exit(EXIT_FAILURE);} + if (MSQ_CHKERR(err)) {mfem::out << err << std::endl; exit(EXIT_FAILURE);} int num_vertices = vertices.size(); // get application fixed vertices std::vector app_fixed(num_vertices); mesh.vertices_get_fixed_flag(&(vertices[0]), app_fixed, num_vertices, err); - if (MSQ_CHKERR(err)) {std::cout << err << std::endl; exit(EXIT_FAILURE);} + if (MSQ_CHKERR(err)) {mfem::out << err << std::endl; exit(EXIT_FAILURE);} int num_app_fixed = 0; for (int i = 0; i < num_vertices; i++) @@ -873,7 +873,7 @@ static void BoundaryPreservingOptimization(mfem::MesquiteMesh &mesh) if (app_fixed[i]) { num_app_fixed++; } } - std::cout << "mesh has " << num_vertices << " vertices and " << num_app_fixed << + mfem::out << "mesh has " << num_vertices << " vertices and " << num_app_fixed << " are app fixed. "; // create planar domain for interior and assessor queues @@ -910,7 +910,7 @@ static void BoundaryPreservingOptimization(mfem::MesquiteMesh &mesh) if (app_fixed_boundary[i]) { num_app_fixed_boundary++; } } - std::cout << "mesh has " << num_boundary_vertices << " boundary vertices and " + mfem::out << "mesh has " << num_boundary_vertices << " boundary vertices and " << num_app_fixed_boundary << " are app fixed" << std::endl; @@ -964,7 +964,7 @@ static void BoundaryPreservingOptimization(mfem::MesquiteMesh &mesh) Mesquite::LPtoPTemplate* obj_func = new Mesquite::LPtoPTemplate(&metric, pOrder, err); - if (MSQ_CHKERR(err)) {std::cout << err << std::endl; exit(EXIT_FAILURE);} + if (MSQ_CHKERR(err)) {mfem::out << err << std::endl; exit(EXIT_FAILURE);} Mesquite::QuasiNewton* boundary_alg = new Mesquite::QuasiNewton( obj_func); boundary_alg->use_element_on_vertex_patch(); @@ -1026,13 +1026,13 @@ static void BoundaryPreservingOptimization(mfem::MesquiteMesh &mesh) // boundary_queue.add_quality_assessor( &boundary_assessor, err ); boundary_queue.set_master_quality_improver(boundary_alg, err); // boundary_queue.add_quality_assessor( &boundary_assessor, err ); - if (MSQ_CHKERR(err)) {std::cout << err << std::endl; exit(EXIT_FAILURE);} + if (MSQ_CHKERR(err)) {mfem::out << err << std::endl; exit(EXIT_FAILURE);} // set the interior instruction queue // interior_queue.add_quality_assessor( &interior_assessor, err ); interior_queue.set_master_quality_improver(interior_alg, err); // interior_queue.add_quality_assessor( &interior_assessor, err ); - if (MSQ_CHKERR(err)) {std::cout << err << std::endl; exit(EXIT_FAILURE);} + if (MSQ_CHKERR(err)) {mfem::out << err << std::endl; exit(EXIT_FAILURE);} err.clear(); @@ -1041,29 +1041,29 @@ static void BoundaryPreservingOptimization(mfem::MesquiteMesh &mesh) for (int j=0; jget_iteration_count() + if (MSQ_CHKERR(err)) {mfem::out << err << std::endl; exit(EXIT_FAILURE);} + mfem::out<<" boundary smooth completed in "<get_iteration_count() <<" outer and "<get_iteration_count() <<" inner iterations."<get_iteration_count() + if (MSQ_CHKERR(err)) {mfem::out << err << std::endl; exit(EXIT_FAILURE);} + mfem::out<<" interior smooth completed in "<get_iteration_count() <<" outer and "<get_iteration_count() <<" inner iterations."<& refinements) Update: what about a FIFO instead of ref_stack? */ #if defined(MFEM_DEBUG) && !defined(MFEM_USE_MPI) - std::cout << "Refined " << refinements.Size() << " + " << nforced + mfem::out << "Refined " << refinements.Size() << " + " << nforced << " elements" << std::endl; #endif ref_stack.DeleteAll(); @@ -3371,10 +3371,10 @@ long NCMesh::MemoryUsage() const int NCMesh::PrintMemoryDetail() const { - nodes.PrintMemoryDetail(); std::cout << " nodes\n"; - faces.PrintMemoryDetail(); std::cout << " faces\n"; + nodes.PrintMemoryDetail(); mfem::out << " nodes\n"; + faces.PrintMemoryDetail(); mfem::out << " faces\n"; - std::cout << elements.MemoryUsage() << " elements\n" + mfem::out << elements.MemoryUsage() << " elements\n" << free_element_ids.MemoryUsage() << " free_element_ids\n" << top_vertex_pos.MemoryUsage() << " top_vertex_pos\n" << leaf_elements.MemoryUsage() << " leaf_elements\n" @@ -3460,9 +3460,9 @@ void NCMesh::DebugLeafOrder() const count++; } } - std::cout << sum / count << " "; + mfem::out << sum / count << " "; } - std::cout << "\n"; + mfem::out << "\n"; } } #endif diff --git a/mesh/ncmesh.hpp b/mesh/ncmesh.hpp index 67dc53cc42..17cf8bc710 100644 --- a/mesh/ncmesh.hpp +++ b/mesh/ncmesh.hpp @@ -14,6 +14,7 @@ #include "../config/config.hpp" #include "../general/hash.hpp" +#include "../general/globalostream.hpp" #include "../linalg/densemat.hpp" #include "element.hpp" #include "vertex.hpp" @@ -256,7 +257,7 @@ public: int PrintMemoryDetail() const; - void PrintStats(std::ostream &out = std::cout) const; + void PrintStats(std::ostream &out = mfem::out) const; protected: // interface for Mesh to be able to construct itself from NCMesh diff --git a/mesh/nurbs.cpp b/mesh/nurbs.cpp index 17b38f933d..b061274e5d 100644 --- a/mesh/nurbs.cpp +++ b/mesh/nurbs.cpp @@ -486,7 +486,7 @@ int NURBSPatch::SetLoopDirection(int dir) } else { - cerr << "NURBSPatch::SetLoopDirection :\n" + mfem::err << "NURBSPatch::SetLoopDirection :\n" " Direction error in 2D patch, dir = " << dir << '\n'; mfem_error(); } @@ -516,7 +516,7 @@ int NURBSPatch::SetLoopDirection(int dir) } else { - cerr << "NURBSPatch::SetLoopDirection :\n" + mfem::err << "NURBSPatch::SetLoopDirection :\n" " Direction error in 3D patch, dir = " << dir << '\n'; mfem_error(); } @@ -1448,7 +1448,7 @@ void NURBSExtension::PrintCharacteristics(std::ostream &out) out << ' ' << i + 1 << ") "; knotVectors[i]->Print(out); } - cout << endl; + out << endl; } void NURBSExtension::GenerateActiveVertices() @@ -1618,7 +1618,7 @@ void NURBSExtension::CheckPatches() edges[8] != edges[9] || edges[8] != edges[10] || edges[8] != edges[11]))) { - cerr << "NURBSExtension::CheckPatch (patch = " << p + mfem::err << "NURBSExtension::CheckPatch (patch = " << p << ")\n Inconsistent edge-to-knot mapping!\n"; mfem_error(); } @@ -1629,7 +1629,7 @@ void NURBSExtension::CheckPatches() (Dimension() == 3 && (edges[0] < 0 || edges[3] < 0 || edges[8] < 0))) { - cerr << "NURBSExtension::CheckPatch (patch = " << p + mfem::err << "NURBSExtension::CheckPatch (patch = " << p << ") : Bad orientation!\n"; mfem_error(); } @@ -1657,7 +1657,7 @@ void NURBSExtension::CheckBdrPatches() if ((Dimension() == 2 && (edges[0] < 0)) || (Dimension() == 3 && (edges[0] < 0 || edges[1] < 0))) { - cerr << "NURBSExtension::CheckBdrPatch (boundary patch = " + mfem::err << "NURBSExtension::CheckBdrPatch (boundary patch = " << p << ") : Bad orientation!\n"; mfem_error(); } diff --git a/mesh/pmesh.cpp b/mesh/pmesh.cpp index d76b1c543c..91d42bfebc 100644 --- a/mesh/pmesh.cpp +++ b/mesh/pmesh.cpp @@ -18,6 +18,7 @@ #include "../general/sets.hpp" #include "../general/sort_pairs.hpp" #include "../general/text.hpp" +#include "../general/globalostream.hpp" #include using namespace std; @@ -357,8 +358,8 @@ ParMesh::ParMesh(MPI_Comm comm, Mesh &mesh, int *partitioning_, #ifdef MFEM_DEBUG if (Dim < 3 && mesh.GetNFaces() != 0) { - cerr << "ParMesh::ParMesh (proc " << MyRank << ") : " - "(Dim < 3 && mesh.GetNFaces() != 0) is true!" << endl; + mfem::err << "ParMesh::ParMesh (proc " << MyRank << ") : " + "(Dim < 3 && mesh.GetNFaces() != 0) is true!" << endl; mfem_error(); } #endif @@ -607,8 +608,8 @@ ParMesh::ParMesh(MPI_Comm comm, Mesh &mesh, int *partitioning_, v_to_v(vert_global_local[vert[0]], vert_global_local[vert[1]])) < 0) { - cerr << "\n\n\n" << MyRank << ": ParMesh::ParMesh: " - << "ERROR in v_to_v\n\n" << endl; + mfem::err << "\n\n\n" << MyRank << ": ParMesh::ParMesh: " + << "ERROR in v_to_v\n\n" << endl; mfem_error(); } @@ -763,8 +764,8 @@ ParMesh::ParMesh(MPI_Comm comm, istream &input) input >> ident >> g; // group if (g != gr) { - cerr << "ParMesh::ParMesh : expecting group " << gr - << ", read group " << g << endl; + mfem::err << "ParMesh::ParMesh : expecting group " << gr + << ", read group " << g << endl; mfem_error(); } @@ -1133,7 +1134,7 @@ void ParMesh::MarkTetMeshForRefinement(DSTable &v_to_v) #if 0 // Debug message from every MPI rank. - cout << "proc. " << MyRank << '/' << NRanks << ": d_max = " << d_max + mfem::out << "proc. " << MyRank << '/' << NRanks << ": d_max = " << d_max << endl; #else // Debug message just from rank 0. @@ -1141,7 +1142,7 @@ void ParMesh::MarkTetMeshForRefinement(DSTable &v_to_v) MPI_Reduce(&d_max, &glob_d_max, 1, MPI_DOUBLE, MPI_MAX, 0, MyComm); if (MyRank == 0) { - cout << "glob_d_max = " << glob_d_max << endl; + mfem::out << "glob_d_max = " << glob_d_max << endl; } #endif } @@ -2282,7 +2283,7 @@ void ParMesh::LocalRefinement(const Array &marked_el, int type) MPI_Reduce(&i, &ref_loops_all, 1, MPI_INT, MPI_MAX, 0, MyComm); if (MyRank == 0) { - cout << "\n\nParMesh::LocalRefinement : max. ref_loops_all = " + mfem::out << "\n\nParMesh::LocalRefinement : max. ref_loops_all = " << ref_loops_all << ", ref_loops_par = " << ref_loops_par << '\n' << endl; } @@ -2517,7 +2518,7 @@ void ParMesh::LocalRefinement(const Array &marked_el, int type) MPI_Reduce(&i, &ref_loops_all, 1, MPI_INT, MPI_MAX, 0, MyComm); if (MyRank == 0) { - cout << "\n\nParMesh::LocalRefinement : max. ref_loops_all = " + mfem::out << "\n\nParMesh::LocalRefinement : max. ref_loops_all = " << ref_loops_all << ", ref_loops_par = " << ref_loops_par << '\n' << endl; } @@ -3181,7 +3182,7 @@ void ParMesh::NURBSUniformRefinement() { if (MyRank == 0) { - cout << "\nParMesh::NURBSUniformRefinement : Not supported yet!\n"; + mfem::out << "\nParMesh::NURBSUniformRefinement : Not supported yet!\n"; } } diff --git a/mesh/pmesh.hpp b/mesh/pmesh.hpp index 0418d7839f..c34e724b99 100644 --- a/mesh/pmesh.hpp +++ b/mesh/pmesh.hpp @@ -17,6 +17,7 @@ #ifdef MFEM_USE_MPI #include "../general/communication.hpp" +#include "../general/globalostream.hpp" #include "mesh.hpp" #include "pncmesh.hpp" #include @@ -185,20 +186,20 @@ public: /** Print the part of the mesh in the calling processor adding the interface as boundary (for visualization purposes) using the mfem v1.0 format. */ - virtual void Print(std::ostream &out = std::cout) const; + virtual void Print(std::ostream &out = mfem::out) const; /** Print the part of the mesh in the calling processor adding the interface as boundary (for visualization purposes) using Netgen/Truegrid format .*/ - virtual void PrintXG(std::ostream &out = std::cout) const; + virtual void PrintXG(std::ostream &out = mfem::out) const; /** Write the mesh to the stream 'out' on Process 0 in a form suitable for visualization: the mesh is written as a disjoint mesh and the shared boundary is added to the actual boundary; both the element and boundary attributes are set to the processor number. */ - void PrintAsOne(std::ostream &out = std::cout); + void PrintAsOne(std::ostream &out = mfem::out); /// Old mesh format (Netgen/Truegrid) version of 'PrintAsOne' - void PrintAsOneXG(std::ostream &out = std::cout); + void PrintAsOneXG(std::ostream &out = mfem::out); /// Returns the minimum and maximum corners of the mesh bounding box. For /// high-order meshes, the geometry is refined first "ref" times. @@ -208,7 +209,7 @@ public: double &kappa_min, double &kappa_max); /// Print various parallel mesh stats - virtual void PrintInfo(std::ostream &out = std::cout); + virtual void PrintInfo(std::ostream &out = mfem::out); /// Save the mesh in a parallel mesh format. void ParPrint(std::ostream &out) const;