00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #include "NOX_Common.H"
00043 #include "NOX_Utils.H"
00044 #include "Teuchos_ParameterList.hpp"
00045
00046 #ifdef HAVE_MPI
00047 #include <mpi.h>
00048 #endif
00049
00050 NOX::Utils::Utils(int outputInformation, int MyPID, int outputProcess,
00051 int outputPrecision,
00052 const Teuchos::RCP<std::ostream>& outputStream,
00053 const Teuchos::RCP<std::ostream>& errStream) :
00054 precision(outputPrecision),
00055 myPID(MyPID),
00056 printTest(outputInformation),
00057 printProc(outputProcess),
00058 blackholeStream(Teuchos::rcp(new Teuchos::oblackholestream)),
00059 printStream(outputStream),
00060 myStream(),
00061 errorStream(errStream)
00062 {
00063 if (printStream == Teuchos::null)
00064 printStream = Teuchos::rcp(&(std::cout), false);
00065 if (errorStream == Teuchos::null)
00066 errorStream = Teuchos::rcp(&(std::cerr), false);
00067 if (myPID == printProc)
00068 myStream = printStream;
00069 else
00070 myStream = blackholeStream;
00071 }
00072
00073 NOX::Utils::Utils(Teuchos::ParameterList& p)
00074 {
00075 this->reset(p);
00076 }
00077
00078 NOX::Utils::Utils(const NOX::Utils& source)
00079 {
00080 *this = source;
00081 }
00082
00083 NOX::Utils::~Utils()
00084 {
00085 }
00086
00087 NOX::Utils& NOX::Utils::operator=(const NOX::Utils& source)
00088 {
00089 printTest = source.printTest;
00090 myPID = source.myPID;
00091 printProc = source.printProc;
00092 precision = source.precision;
00093 blackholeStream = source.blackholeStream;
00094 printStream = source.printStream;
00095 myStream = source.myStream;
00096 errorStream = source.errorStream;
00097
00098 return *this;
00099 }
00100
00101 void NOX::Utils::reset(Teuchos::ParameterList& p)
00102 {
00103 using namespace Teuchos;
00104
00105
00106
00107 if (p.isSublist("Output Information")) {
00108
00109 ParameterList& printList = p.sublist("Output Information");
00110 typedef std::map<std::string, NOX::Utils::MsgType> OptionMap;
00111 OptionMap output_options;
00112 output_options["Error"] = NOX::Utils::Error;
00113 output_options["Warning"] = NOX::Utils::Warning;
00114 output_options["Outer Iteration"] = NOX::Utils::OuterIteration;
00115 output_options["Inner Iteration"] = NOX::Utils::InnerIteration;
00116 output_options["Parameters"] = NOX::Utils::Parameters;
00117 output_options["Details"] = NOX::Utils::Details;
00118 output_options["Outer Iteration StatusTest"] = NOX::Utils::OuterIterationStatusTest;
00119 output_options["Linear Solver Details"] = NOX::Utils::LinearSolverDetails;
00120 output_options["Test Details"] = NOX::Utils::TestDetails;
00121 output_options["Stepper Iteration"] = NOX::Utils::StepperIteration;
00122 output_options["Stepper Details"] = NOX::Utils::StepperDetails;
00123 output_options["Stepper Parameters"] = NOX::Utils::StepperParameters;
00124 output_options["Debug"] = NOX::Utils::Debug;
00125
00126 bool add_test = false;
00127 OptionMap::const_iterator start = output_options.begin();
00128 OptionMap::const_iterator stop = output_options.end();
00129 for (OptionMap::const_iterator i = start; i != stop; ++i) {
00130 add_test = printList.get(i->first, false);
00131 if (add_test)
00132 printTest += i->second;
00133 }
00134 }
00135 else if (isParameterType<NOX::Utils::MsgType>(p, "Output Information"))
00136 printTest = get<NOX::Utils::MsgType>(p, "Output Information");
00137 else
00138 printTest = p.get("Output Information", 0xf);
00139
00140 #ifdef HAVE_MPI
00141 if (p.isParameter("MyPID"))
00142 myPID = p.get("MyPID", 0);
00143 else {
00144
00145
00146 int mpiIsRunning = 0;
00147 MPI_Initialized(&mpiIsRunning);
00148 if (mpiIsRunning)
00149 {
00150 MPI_Comm_rank(MPI_COMM_WORLD, &myPID);
00151 }
00152 else
00153 {
00154 myPID=0;
00155 }
00156
00157 p.get("MyPID", myPID);
00158 }
00159 #else
00160 myPID = p.get("MyPID", 0);
00161 #endif
00162 printProc = p.get("Output Processor", 0);
00163 precision = p.get("Output Precision", 3);
00164
00165
00166 blackholeStream = Teuchos::rcp(new Teuchos::oblackholestream);
00167
00168 if (p.INVALID_TEMPLATE_QUALIFIER
00169 isType< Teuchos::RCP<std::ostream> >("Output Stream"))
00170 printStream =
00171 (p).INVALID_TEMPLATE_QUALIFIER
00172 get< Teuchos::RCP<std::ostream> >("Output Stream");
00173 else
00174 printStream = Teuchos::rcp(&(std::cout), false);
00175 myStream = (myPID == printProc) ? printStream : blackholeStream;
00176
00177 if (p.INVALID_TEMPLATE_QUALIFIER
00178 isType< Teuchos::RCP<std::ostream> >("Error Stream"))
00179 errorStream =
00180 (p).INVALID_TEMPLATE_QUALIFIER
00181 get< Teuchos::RCP<std::ostream> >("Error Stream");
00182 else
00183 errorStream = Teuchos::rcp(&(std::cerr), false);
00184 }
00185
00186
00187 NOX::Utils::Fill NOX::Utils::fill(int filln, char fillc)
00188 {
00189 return NOX::Utils::Fill(filln, fillc);
00190 }
00191
00192 ostream& operator<<(ostream& os, const NOX::Utils::Fill& f)
00193 {
00194 for (int i = 0; i < f.n; i ++)
00195 os << f.c;
00196 return os;
00197 }
00198
00199 NOX::Utils::Sci NOX::Utils::sciformat(double dval) const
00200 {
00201 return NOX::Utils::Sci(dval, precision);
00202 }
00203
00204 NOX::Utils::Sci NOX::Utils::sciformat(double dval, int p)
00205 {
00206 return NOX::Utils::Sci(dval, p);
00207 }
00208
00209 ostream& operator<<(ostream& os, const NOX::Utils::Sci& s)
00210 {
00211 os.setf(ios::scientific);
00212 os.precision(s.p);
00213 os << setw(s.p + 6) << s.d;
00214 os.unsetf(ios::scientific);
00215 return os;
00216 }
00217
00218 bool NOX::Utils::isPrintType(MsgType type) const
00219 {
00220 return ((type == NOX::Utils::Error) || ((printTest & type) != 0));
00221 }
00222
00223
00224 std::ostream& NOX::Utils::out() const
00225 {
00226 return *myStream;
00227 }
00228
00229 std::ostream& NOX::Utils::out(NOX::Utils::MsgType type) const
00230 {
00231 if (isPrintType(type))
00232 return *myStream;
00233
00234 return *blackholeStream;
00235 }
00236
00237 std::ostream& NOX::Utils::pout() const
00238 {
00239 return *printStream;
00240 }
00241
00242 std::ostream& NOX::Utils::pout(NOX::Utils::MsgType type) const
00243 {
00244 if (isPrintType(type))
00245 return *printStream;
00246
00247 return *blackholeStream;
00248 }
00249
00250 std::ostream& NOX::Utils::err() const
00251 {
00252 return (myPID == printProc) ? *errorStream : *blackholeStream;
00253 }
00254
00255 std::ostream& NOX::Utils::perr() const
00256 {
00257 return *errorStream;
00258 }
00259
00260 void NOX::Utils::print(ostream& os) const
00261 {
00262 os << "NOX::Utils Printing Object" << endl;
00263 os << "Output Information Level = " << printTest << endl;
00264 os << "My PID = " << myPID << endl;
00265 os << "Print Processor = " << printProc << endl;
00266 os << "Precision = " << precision << endl;
00267 }
00268
00269 ostream& operator<<(ostream& os, const NOX::Utils& utils)
00270 {
00271 utils.print(os);
00272 return os;
00273 }