58 void MergeParameterList(
const Teuchos::ParameterList &source, Teuchos::ParameterList &dest,
bool overWrite){
59 for(Teuchos::ParameterList::ConstIterator param=source.begin(); param!=source.end(); ++param)
60 if (dest.isParameter(source.name(param)) ==
false || overWrite)
61 dest.setEntry(source.name(param),source.entry(param));
64 void CreateSublists(
const Teuchos::ParameterList &List, Teuchos::ParameterList &newList)
66 using Teuchos::ParameterList;
69 newList.setName(List.name());
75 for (ParameterList::ConstIterator param=List.begin(); param!=List.end(); ++param)
77 const string & pname=List.name(param);
79 if ((pname.find(
" (level",0) == string::npos || pname.find(
"smoother: list (level",0) == 0 || pname.find(
"aggregation: list (level",0) == 0) &&
80 (pname.find(
"coarse: ",0) == string::npos))
82 newList.setEntry(pname,List.entry(param));
87 if (List.isSublist(
"coarse: list")) {
88 const ParameterList &coarseList = List.sublist(
"coarse: list");
89 ParameterList &newCoarseList = newList.sublist(
"coarse: list");
90 for (ParameterList::ConstIterator param=coarseList.begin(); param!=coarseList.end() ; ++param) {
91 const string & pname=coarseList.name(param);
93 if (pname.find(
"coarse:",0) == 0) {
95 newCoarseList.setEntry(
"smoother: "+pname.substr(8),coarseList.entry(param));
97 newCoarseList.setEntry(pname,coarseList.entry(param));
103 for (ParameterList::ConstIterator param=List.begin(); param!=List.end(); ++param)
105 const string & pname=List.name(param);
106 if (pname.find(
" (level",0) != string::npos && pname.find(
"smoother: list (level",0) != 0 && pname.find(
"aggregation: list (level",0) != 0)
114 typedef Teuchos::ArrayRCP<char>::size_type size_type;
115 Teuchos::Array<char> ctype (size_type(pname.size()+1));
116 Teuchos::Array<char> coption(size_type(pname.size()+1));
118 int matched = sscanf(pname.c_str(),
"%s %[^(](level %d)", ctype.getRawPtr(), coption.getRawPtr(), &levelID);
119 type = string(ctype.getRawPtr());
120 option = string(coption.getRawPtr()); option.resize(option.size () - 1);
122 if (matched != 3 || (type !=
"smoother:" && type !=
"aggregation:")) {
124 <<
"Error in creating level-specific sublists" << std::endl
125 <<
"Offending parameter: " << pname << std::endl);
130 ParameterList &newSubList = newList.sublist(type +
" list (level " +
Teuchos::toString(levelID) +
")");
132 newSubList.setEntry(type +
" " + option,List.entry(param));
134 }
else if (pname.find(
"coarse:",0) == 0 && pname !=
"coarse: list") {
136 ParameterList &newCoarseList = newList.sublist(
"coarse: list");
137 newCoarseList.setEntry(
"smoother: "+pname.substr(8),List.entry(param));
145 const Teuchos::ParameterList &
GetMLSubList(
const Teuchos::ParameterList & paramList,
const std::string & type,
int levelID) {
146 static const Teuchos::ParameterList emptyParamList;
149 sprintf(levelChar,
"(level %d)", levelID);
150 std::string levelStr(levelChar);
152 if (paramList.isSublist(type +
": list " + levelStr)) {
153 return paramList.sublist(type +
": list " + levelStr);
155 return emptyParamList;
160 Teuchos::RCP<Teuchos::ParameterList>
ExtractSetOfParameters(
const Teuchos::ParameterList & paramList,
const std::string & str) {
161 Teuchos::RCP<Teuchos::ParameterList> subList = rcp(
new Teuchos::ParameterList());
163 for (Teuchos::ParameterList::ConstIterator param = paramList.begin(); param != paramList.end(); ++param) {
164 const Teuchos::ParameterEntry & entry = paramList.entry(param);
165 const std::string & pname = paramList.name(param);
166 if (pname.find(str+
":",0) == 0 && !entry.isList()) {
167 subList->setEntry(pname,entry);
175 void replaceAll(std::string& str,
const std::string& from,
const std::string& to) {
178 size_t start_pos = 0;
179 while((start_pos = str.find(from, start_pos)) != std::string::npos) {
180 str.replace(start_pos, from.length(), to);
181 start_pos += to.length();
void MergeParameterList(const Teuchos::ParameterList &source, Teuchos::ParameterList &dest, bool overWrite)
: merge two parameter lists
std::string toString(const T &what)
Little helper function to convert non-string types to strings.
Namespace for MueLu classes and methods.
const Teuchos::ParameterList & GetMLSubList(const Teuchos::ParameterList ¶mList, const std::string &type, int levelID)
void CreateSublists(const ParameterList &List, ParameterList &newList)
Teuchos::RCP< Teuchos::ParameterList > ExtractSetOfParameters(const Teuchos::ParameterList ¶mList, const std::string &str)
Exception throws to report errors in the internal logical of the program.
void replaceAll(std::string &str, const std::string &from, const std::string &to)