Microflow 3D  v1.0
ConfigData.h
Go to the documentation of this file.
1 // ==============================================================================================
2 // Microflow 3D, http://www.microflow.pwr.edu.pl/
3 // Created by Roman Szafran on 14.04.19.
4 // Copyright (c) 2019 Wroclaw University of Science and Technology.
5 // Distributed under the Apache License, Version 2.0. You may obtain a copy of the License at
6 // http://www.apache.org/licenses/LICENSE-2.0 or see accompanying file license.txt.
7 // Redistributions of source code must retain the above copyright and license notice.
8 // ==============================================================================================
9 
10 # pragma once
11 
12 #include <cstring>
13 #include <config4cpp/Configuration.h>
14 #include <boost/shared_ptr.hpp>
15 #include <memory>
16 
17 #include "Parsers/TextParser.h"
18 
19 namespace MF {
20  namespace Database {
23  class ConfigData {
24  public:
25  ConfigData(const char *pPathToProgramConfigFile, const char *pPathToCaseFolder, const char *pScope, bool verbose);
26  ~ConfigData();
27 
28  static std::shared_ptr<MF::Database::ConfigData> New(const char *pPathToProgramConfigFile, const char *pPathToCaseFolder, const char *pScope, bool verbose) {
29  auto ConfigData_Ptr = std::make_shared<MF::Database::ConfigData>(pPathToProgramConfigFile, pPathToCaseFolder, pScope, verbose);
30  return ConfigData_Ptr;
31  };
32 
33  //ACCESORS
34  std::shared_ptr<MF::Parser::TextParser> getTextParser_Ptr() { return m_pTextParser_Ptr; };
35  config4cpp::Configuration *getProgramParametres_Ptr() { return m_pProgramParams; };
36  config4cpp::Configuration *getCaseParametres_Ptr() { return m_pCaseParams; };
37  config4cpp::Configuration *getThreadParametres_Ptr() { return m_pThreadParams; }
38 
39  //CASE PARAMETERS
40  inline int getCaseParamLength(const char *parameterName) {m_pCaseParams->listLocallyScopedNames(m_pScope, "", config4cpp::Configuration::CFG_SCOPE_AND_VARS, false, parameterName, m_namesVec); return m_namesVec.length(); };
41  inline float getCaseFloatParam(const char *parameterName) { return m_pCaseParams->lookupFloat(m_pScope, parameterName); };
42  inline int getCaseIntParam(const char *parameterName) { return m_pCaseParams->lookupInt(m_pScope, parameterName); };
43  inline bool getCaseBooleanParam(const char *parameterName) { return m_pCaseParams->lookupBoolean(m_pScope, parameterName); };
44  inline std::string getCaseStringParam(const char *parameterName) { return m_pCaseParams->lookupString(m_pScope, parameterName); };
45  // float vector
46  inline float getCaseFloatVectorParam(const int component, const char *parameterName) {m_pCaseParams->lookupList(m_pScope, parameterName, m_valueVector); return m_pCaseParams->stringToFloat(m_pScope, parameterName, m_valueVector[component]);};
47  // int vector
48  inline int getCaseIntVectorParam(const int component, const char *parameterName) {m_pCaseParams->lookupList(m_pScope, parameterName, m_valueVector); return m_pCaseParams->stringToInt(m_pScope, parameterName, m_valueVector[component]);};
49 
50  // enum predefined
51  inline int getGeometryDefinition() {return m_pCaseParams->lookupEnum(m_pScope, "BasicParams.GeometryDefinition", "GeometryDefinitionClass", GeometryDefinition, 1);};
52  inline int getFlowType() {return m_pCaseParams->lookupEnum(m_pScope, "BasicParams.FluidFlowModel_MT", "FlowTypeClass", FlowType, 2);};
53  inline int getModelType() {return m_pCaseParams->lookupEnum(m_pScope, "BasicParams.CollisionModel_KT", "ModelTypeClass", ModelType, 4);};
54  inline int getLatticeType() {return m_pCaseParams->lookupEnum(m_pScope, "BasicParams.LatticeType_La", "LatticeTypeClass", LatticeType, 1);};
55 
56  //PROGRAM PARAMETERS
57  inline int getProgramParamLength(const char *parameterName) {m_pProgramParams->listLocallyScopedNames(m_pScope, "", config4cpp::Configuration::CFG_SCOPE_AND_VARS, false, parameterName, m_namesVec); return m_namesVec.length(); };
58  inline float getProgramFloatParam(const char *parameterName) { return m_pProgramParams->lookupFloat(m_pScope, parameterName); };
59  inline int getProgramIntParam(const char *parameterName) { return m_pProgramParams->lookupInt(m_pScope, parameterName); };
60  inline bool getProgramBooleanParam(const char *parameterName) { return m_pProgramParams->lookupBoolean(m_pScope, parameterName); };
61  inline std::string getProgramStringParam(const char *parameterName) { return m_pProgramParams->lookupString(m_pScope, parameterName); };
62  // float vector
63  inline float getProgramFloatVectorParam(const int component, const char *parameterName) {m_pProgramParams->lookupList(m_pScope, parameterName, m_valueVector); return m_pProgramParams->stringToFloat(m_pScope, parameterName, m_valueVector[component]);};
64  // int vector
65  inline int getProgramIntVectorParam(const int component, const char *parameterName) {m_pProgramParams->lookupList(m_pScope, parameterName, m_valueVector); return m_pProgramParams->stringToInt(m_pScope, parameterName, m_valueVector[component]);};
66 
67  //THREAD PARAMETERS
68  inline int getThreadsNumber() {m_pThreadParams->listLocallyScopedNames(m_pScope, "", config4cpp::Configuration::CFG_SCOPE, false, "uid-Thread", m_namesVec); return m_namesVec.length();};
69  inline int getThreadParamLength(const int ThreadNr, const char *parameterName) {getThreadsNumber(); m_pThreadParams->listLocallyScopedNames(m_pScope, m_namesVec[ThreadNr], config4cpp::Configuration::CFG_SCOPE_AND_VARS, false, parameterName, m_namesVec2); return m_namesVec2.length(); };
70 
71  inline float getThreadFloatParam(const int ThreadNr, const char *parameterName) {getThreadsNumber(); m_strBuffer = m_pScope; m_strBuffer.append("."); m_strBuffer.append(m_namesVec[ThreadNr]); return m_pThreadParams->lookupFloat(m_strBuffer.c_str(), parameterName, 0); };
72  inline int getThreadIntParam(const int ThreadNr, const char *parameterName) {getThreadsNumber(); m_strBuffer = m_pScope; m_strBuffer.append("."); m_strBuffer.append(m_namesVec[ThreadNr]); return m_pThreadParams->lookupInt(m_strBuffer.c_str(), parameterName, 0); };
73  inline bool getThreadBooleanParam(const int ThreadNr, const char *parameterName) {getThreadsNumber(); m_strBuffer = m_pScope; m_strBuffer.append("."); m_strBuffer.append(m_namesVec[ThreadNr]); return m_pThreadParams->lookupBoolean(m_strBuffer.c_str(), parameterName, 0); };
74  inline std::string getThreadStringParam(const int ThreadNr, const char *parameterName) {getThreadsNumber(); m_strBuffer = m_pScope; m_strBuffer.append("."); m_strBuffer.append(m_namesVec[ThreadNr]); return m_pThreadParams->lookupString(m_strBuffer.c_str(), parameterName, ""); };
75 
76  // float vector
77  inline float getThreadFloatVectorParam(const int component, const int ThreadNr, const char *parameterName) {getThreadsNumber(); m_strBuffer = m_pScope; m_strBuffer.append("."); m_strBuffer.append(m_namesVec[ThreadNr]); m_pThreadParams->lookupList(m_strBuffer.c_str(), parameterName, m_valueVector, {}); if (m_valueVector.length() > 0) return m_pThreadParams->stringToFloat(m_strBuffer.c_str(), parameterName, m_valueVector[component]); return 0; };
78  // int vector
79  inline int getThreadIntVectorParam(const int component, const int ThreadNr, const char *parameterName) {getThreadsNumber(); m_strBuffer = m_pScope; m_strBuffer.append("."); m_strBuffer.append(m_namesVec[ThreadNr]); m_pThreadParams->lookupList(m_strBuffer.c_str(), parameterName, m_valueVector, {}); if (m_valueVector.length() > 0) return m_pThreadParams->stringToInt(m_strBuffer.c_str(), parameterName, m_valueVector[component]); return 0; };
80  // string vector
81  inline std::string getThreadStringVectorParam(const int component, const int ThreadNr, const char *parameterName) {getThreadsNumber(); m_strBuffer = m_pScope; m_strBuffer.append("."); m_strBuffer.append(m_namesVec[ThreadNr]); m_pThreadParams->lookupList(m_strBuffer.c_str(), parameterName, m_valueVector, {}); if (m_valueVector.length() > 0) return m_valueVector[component]; return ""; };
82 
83  // Thread data parameters
84  inline int getThreadDataVectorParamLength (const int ThreadNr, const int DataNr, const char *dataName, const char *parameterName){getThreadParamLength(ThreadNr,dataName); m_strBuffer = m_pScope; m_strBuffer.append("."); m_strBuffer.append(m_namesVec[ThreadNr]); m_pThreadParams->listLocallyScopedNames(m_strBuffer.c_str(), m_namesVec2[DataNr], config4cpp::Configuration::CFG_SCOPE_AND_VARS, false, parameterName, m_namesVec3); return m_namesVec3.length(); };
85  // float vector
86  inline float getThreadDataFloatVectorParam(const int component, const int ThreadNr, const int DataNr, const char *dataName, const char *parameterName) {getThreadParamLength(ThreadNr,dataName); m_strBuffer = m_pScope; m_strBuffer.append("."); m_strBuffer.append(m_namesVec[ThreadNr]); m_strBuffer.append("."); m_strBuffer.append(m_namesVec2[DataNr]); m_pThreadParams->lookupList(m_strBuffer.c_str(), parameterName, m_valueVector, {}); if (m_valueVector.length() > 0) return m_pThreadParams->stringToFloat(m_strBuffer.c_str(), parameterName, m_valueVector[component]); return 0; };
87  // int vector
88  inline int getThreadDataIntVectorParam(const int component, const int ThreadNr, const int DataNr, const char *dataName, const char *parameterName) {getThreadParamLength(ThreadNr,dataName); m_strBuffer = m_pScope; m_strBuffer.append("."); m_strBuffer.append(m_namesVec[ThreadNr]); m_strBuffer.append("."); m_strBuffer.append(m_namesVec2[DataNr]); m_pThreadParams->lookupList(m_strBuffer.c_str(), parameterName, m_valueVector, {}); if (m_valueVector.length() > 0) return m_pThreadParams->stringToInt(m_strBuffer.c_str(), parameterName, m_valueVector[component]); return 0; };
89 
90  private:
91  std::shared_ptr<MF::Parser::TextParser> m_pTextParser_Ptr;
92  config4cpp::Configuration *m_pProgramParams;
93  config4cpp::Configuration *m_pCaseParams;
94  config4cpp::Configuration *m_pThreadParams;
95  config4cpp::StringVector m_valueVector;
96  const char *m_pScope;
97  config4cpp::StringVector m_namesVec;
98  config4cpp::StringVector m_namesVec2;
99  config4cpp::StringVector m_namesVec3;
100  config4cpp::StringBuffer m_strBuffer;
101 
102  const config4cpp::EnumNameAndValue GeometryDefinition[1] = {{"FromSTL", 0},};
103  const config4cpp::EnumNameAndValue FlowType[2] = {{"QuasiCompressible", 0},{"Incompressible", 1},};
104  const config4cpp::EnumNameAndValue ModelType[4] = {{"BGK", 0},{"MRT", 1},{"FBGK", 2}, {"MRT2", 3},};
105  const config4cpp::EnumNameAndValue LatticeType[1] = {{"D3Q19", 0},};
106 
107  public:
108  std::string CaseFolder;
109  std::string ProgramConfigFile;
110  std::string CaseFile;
111  std::string ThreadFile;
112  std::string GeometryFile;
113 
114  };
115  } /* namespace Database */
116 } /* namespace MF */
117 
config4cpp::Configuration * getProgramParametres_Ptr()
Returns pointer to text parser object.
Definition: ConfigData.h:35
int getProgramParamLength(const char *parameterName)
Returns the LatticeType parameter of enum type: 0 - D3Q19.
Definition: ConfigData.h:57
std::string GeometryFile
Full path to geometry file (relative to program folder).
Definition: ConfigData.h:112
float getThreadFloatParam(const int ThreadNr, const char *parameterName)
Returns thread parameter number of name "parameterName" > 0 if parameter exists.
Definition: ConfigData.h:71
std::string getProgramStringParam(const char *parameterName)
Returns program parameter of boolean type.
Definition: ConfigData.h:61
bool getCaseBooleanParam(const char *parameterName)
Returns case parameter of int type.
Definition: ConfigData.h:43
std::string CaseFile
Full path to case config file (relative to program folder).
Definition: ConfigData.h:110
int getCaseIntVectorParam(const int component, const char *parameterName)
Returns case parameter of vector component of float type.
Definition: ConfigData.h:48
float getProgramFloatParam(const char *parameterName)
Returns number of program parameter of name "parameterName" > 0 if parameter exists.
Definition: ConfigData.h:58
int getThreadsNumber()
Returns program parameter of vector component of int type.
Definition: ConfigData.h:68
float getCaseFloatVectorParam(const int component, const char *parameterName)
Returns case parameter of string type.
Definition: ConfigData.h:46
The ConfigData class provides accessors for text parser objects: case parameters, program parameters ...
Definition: ConfigData.h:23
int getThreadIntVectorParam(const int component, const int ThreadNr, const char *parameterName)
Returns thread parameter of vector component of float type.
Definition: ConfigData.h:79
std::string getThreadStringParam(const int ThreadNr, const char *parameterName)
Returns thread parameter of boolean type.
Definition: ConfigData.h:74
std::string getThreadStringVectorParam(const int component, const int ThreadNr, const char *parameterName)
Returns thread parameter of vector component of int type.
Definition: ConfigData.h:81
config4cpp::Configuration * getThreadParametres_Ptr()
Returns pointer to case parameters parser object.
Definition: ConfigData.h:37
int getFlowType()
Returns the way of GeometryDefinition of enum type: 0 - FromSTL.
Definition: ConfigData.h:52
bool getThreadBooleanParam(const int ThreadNr, const char *parameterName)
Returns thread parameter of int type.
Definition: ConfigData.h:73
int getThreadDataIntVectorParam(const int component, const int ThreadNr, const int DataNr, const char *dataName, const char *parameterName)
Returns thread parameter of vector component of float type.
Definition: ConfigData.h:88
int getCaseParamLength(const char *parameterName)
Definition: ConfigData.h:40
bool getProgramBooleanParam(const char *parameterName)
Returns program parameter of int type.
Definition: ConfigData.h:60
ConfigData(const char *pPathToProgramConfigFile, const char *pPathToCaseFolder, const char *pScope, bool verbose)
Definition: ConfigData.cpp:21
int getProgramIntVectorParam(const int component, const char *parameterName)
Returns program parameter of vector component of float type.
Definition: ConfigData.h:65
static std::shared_ptr< MF::Database::ConfigData > New(const char *pPathToProgramConfigFile, const char *pPathToCaseFolder, const char *pScope, bool verbose)
Definition: ConfigData.h:28
int getThreadDataVectorParamLength(const int ThreadNr, const int DataNr, const char *dataName, const char *parameterName)
Returns thread parameter of string component of int type.
Definition: ConfigData.h:84
std::string ThreadFile
Full path to thread file (relative to program folder).
Definition: ConfigData.h:111
float getProgramFloatVectorParam(const int component, const char *parameterName)
Returns program parameter of string type.
Definition: ConfigData.h:63
float getCaseFloatParam(const char *parameterName)
Returns number of case parameter of name "parameterName" > 0 if parameter exists. ...
Definition: ConfigData.h:41
int getGeometryDefinition()
Returns case parameter of vector X component of int type.
Definition: ConfigData.h:51
std::string getCaseStringParam(const char *parameterName)
Returns case parameter of boolean type.
Definition: ConfigData.h:44
int getThreadParamLength(const int ThreadNr, const char *parameterName)
Returns number of threads.
Definition: ConfigData.h:69
config4cpp::Configuration * getCaseParametres_Ptr()
Returns pointer to program parameters parser object.
Definition: ConfigData.h:36
int getModelType()
Returns the FlowType parameter of enum type: 0 - quasi compressible, 1 - incompressible Zou et al...
Definition: ConfigData.h:53
int getThreadIntParam(const int ThreadNr, const char *parameterName)
Returns thread parameter of float type.
Definition: ConfigData.h:72
int getCaseIntParam(const char *parameterName)
Returns case parameter of float type.
Definition: ConfigData.h:42
float getThreadDataFloatVectorParam(const int component, const int ThreadNr, const int DataNr, const char *dataName, const char *parameterName)
Returns thread data parameter length > 0 if parameter exists.
Definition: ConfigData.h:86
std::shared_ptr< MF::Parser::TextParser > getTextParser_Ptr()
Definition: ConfigData.h:34
std::string CaseFolder
Path to case folder (relative to program folder).
Definition: ConfigData.h:108
std::string ProgramConfigFile
Full path to program config file (relative to program folder).
Definition: ConfigData.h:109
int getProgramIntParam(const char *parameterName)
Returns program parameter of float type.
Definition: ConfigData.h:59
float getThreadFloatVectorParam(const int component, const int ThreadNr, const char *parameterName)
Returns thread parameter of string type.
Definition: ConfigData.h:77
int getLatticeType()
Returns the ModelType parameter of enum type: 0 - BGK, 1 - MRT, 2 - FBGK, 3- MRT2.
Definition: ConfigData.h:54