Finite Element Domain Decomposition Library
FEDDLib
Loading...
Searching...
No Matches
IO_Utils.hpp
1#ifndef IO_UTILS_hpp
2#define IO_UTILS_hpp
3
4#include <Teuchos_ParameterList.hpp>
5#include <Teuchos_XMLParameterListCoreHelpers.hpp>
6#include <Teuchos_YamlParameterListCoreHelpers.hpp>
7
8namespace FEDD{
9
10 namespace IO {
11
17 Teuchos::RCP<Teuchos::ParameterList> parseParameterList(const std::string &fileName,
18 const std::string &type = "yaml")
19 {
20 Teuchos::RCP<Teuchos::ParameterList> parameterList;
21
22 if (!type.compare("yaml"))
23 {
24 parameterList = Teuchos::getParametersFromYamlFile(fileName);
25 }
26 else if (!type.compare("xml"))
27 {
28 parameterList = Teuchos::getParametersFromXmlFile(fileName);
29 }
30 else
31 {
32 TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,"File type not supported.");
33 }
34
35 return parameterList;
36 };
37
38
46 Teuchos::RCP<Teuchos::ParameterList> parseParameterListFiles(Teuchos::RCP<Teuchos::ParameterList> &parameterList,
47 const std::string &nameName = "ParameterLists File Names",
48 const std::string &pathName = "ParameterLists File Paths",
49 const std::string &typeName = "ParameterLists File Types")
50 {
51 Teuchos::Array<std::string> names(1,""), filePaths(1,""), fileTypes(1,"");
52 if (parameterList->isParameter(pathName))
53 {
54 filePaths = parameterList->get(pathName,filePaths);
55
56 if (parameterList->isParameter(nameName))
57 {
58 names = parameterList->get(nameName,names);
59 TEUCHOS_TEST_FOR_EXCEPTION(names.size()!=filePaths.size(),std::logic_error,"names.size()!=filePaths.size()");
60 } else {
61 TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,"ParameterLists File Names are not specified.");
62 }
63
64 if (parameterList->isParameter(typeName))
65 {
66 fileTypes = parameterList->get(typeName,fileTypes);
67 TEUCHOS_TEST_FOR_EXCEPTION(fileTypes.size()!=filePaths.size(),std::logic_error,"fileTypes.size()!=filePaths.size()");
68 } else {
69 TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,"ParameterLists File Types are not specified.");
70 }
71
72 int i = 0;
73 for (auto it = filePaths.begin(); it != filePaths.end(); it++, i++)
74 {
75 Teuchos::RCP<Teuchos::ParameterList> parameterListTmp = parseParameterList(filePaths[i],fileTypes[i]);
76 parameterList->set(names[i],*parameterListTmp);
77 }
78 }
79 return parameterList;
80 };
81
82 }
83
84}
85
86#endif
Adaptive Mesh Refinement.
Definition AdaptiveMeshRefinement_decl.hpp:36