Xpetra_Parameters.hpp
Go to the documentation of this file.
1 // @HEADER
2 //
3 // ***********************************************************************
4 //
5 // Xpetra: A linear algebra interface package
6 // Copyright 2012 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact
39 // Jonathan Hu (jhu@sandia.gov)
40 // Andrey Prokopenko (aprokop@sandia.gov)
41 // Ray Tuminaro (rstumin@sandia.gov)
42 //
43 // ***********************************************************************
44 //
45 // @HEADER
46 #ifndef XPETRA_PARAMETERS_HPP
47 #define XPETRA_PARAMETERS_HPP
48 
49 #include <Teuchos_Describable.hpp>
50 #include <Teuchos_VerboseObject.hpp>
52 
53 #include <Xpetra_Map.hpp> // for UnderlyingLib definition
54 #include <Xpetra_Utils.hpp> // for toString(lib_)
55 
56 namespace Xpetra {
57 
58  class Parameters
59  : public Teuchos::VerboseObject<Parameters>, public Teuchos::Describable
60  {
61 
62  public:
63 
65  setCLP(clp);
66  }
67 
69  int nOptions=0; // Gives the number of possible option values to select
70  const int maxOptions=2; // No ore than 2 libraries are supported right now
71  Xpetra::UnderlyingLib optionValues[maxOptions]; // Array that gives the numeric values for each option.
72  const char* optionNames [maxOptions]; // Array that gives the name used in the commandline for each option.
73 
74  std::stringstream documentation; // documentation for the option
75  documentation << "linear algebra library (Epetra, Tpetra)";
76 
77  // Default is Tpetra if available. If not, default is Epetra
78 #if defined(HAVE_XPETRA_EPETRA)
79  lib_ = Xpetra::UseEpetra; // set default (if Tpetra support is missing)
80  optionValues[nOptions] = Xpetra::UseEpetra;
81  //optionValues[nOptions] = "epetra"; //TODO: do not break compatibility right now
82  optionNames[nOptions] = "Epetra";
83  nOptions++;
84 #endif
85 #if defined(HAVE_XPETRA_TPETRA)
86  lib_ = Xpetra::UseTpetra; // set default
87  optionValues[nOptions] = Xpetra::UseTpetra;
88  //optionsValues[nOptions] = "tpetra"; //TODO: do not break compatibility right now
89  optionNames[nOptions] = "Tpetra";
90  nOptions++;
91 #endif
92 
93  clp.setOption<Xpetra::UnderlyingLib>("linAlgebra", &lib_, nOptions, optionValues, optionNames, documentation.str().c_str());
94 
95  }
96 
97  void check() const {
98  //TODO with ifdef...
99  }
100 
102  check();
103  return lib_;
104  }
105 
107 
108 
110  std::string description() const {
111  std::ostringstream out;
113  out << "{lib = " << toString(lib_) << "} ";
114  return out.str();
115  }
116 
119  using std::endl;
120  int vl = (verbLevel == Teuchos::VERB_DEFAULT) ? Teuchos::VERB_LOW : verbLevel;
121  if (vl == Teuchos::VERB_NONE) return;
122 
123  if (vl == Teuchos::VERB_LOW) { out << description() << endl; } else { out << Teuchos::Describable::description() << endl; }
124 
125  if (vl == Teuchos::VERB_MEDIUM || vl == Teuchos::VERB_HIGH || vl == Teuchos::VERB_EXTREME) {
126  Teuchos::OSTab tab1(out);
127  out << "Linear algebra library: " << toString(lib_) << endl;
128  }
129  }
130 
132 
133  private:
135  };
136 
137 }
138 
139 #endif
std::string toString(Xpetra::UnderlyingLib lib)
Convert a Xpetra::UnderlyingLib to a std::string.
void setCLP(Teuchos::CommandLineProcessor &clp)
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=verbLevel_default) const
Print the object with some verbosity level to an FancyOStream object.
std::string description() const
Return a simple one-line description of this object.
Xpetra namespace
Xpetra::UnderlyingLib lib_
void setOption(const char option_true[], const char option_false[], bool *option_val, const char documentation[]=NULL)
virtual std::string description() const
Xpetra::UnderlyingLib GetLib() const
static const EVerbosityLevel verbLevel_default
Parameters(Teuchos::CommandLineProcessor &clp)