PlasCom2  1.0
XPACC Multi-physics simluation application
ConfigUtil.H
Go to the documentation of this file.
1 #ifndef __CONFIG_UTIL_H__
2 #define __CONFIG_UTIL_H__
3 
4 
5 // Populate state from config - state *must* have been populated
6 template<typename StateType>
8  const std::string &keyRoot,
9  StateType &inState,
10  std::ostream &messageStream)
11 {
12 
13  typename StateType::MetaDataSetType &dataDictionary(inState.Meta());
14  typename StateType::MetaDataSetType::iterator paramDataIt = dataDictionary.begin();
15  while(paramDataIt != dataDictionary.end()){
16 
17  std::string &paramName(paramDataIt->name);
18  messageStream << "Parameter name: " << paramName << std::endl;
19  int numComp = paramDataIt->ncomp;
20  int dataSize = paramDataIt->dsize;
21  paramDataIt++;
22 
23  std::string paramKey(ConfigKey(keyRoot,paramName));
24  messageStream << "Parameter key: " << paramKey << std::endl;
25  if(inConfig.IsSet(paramKey)){
26  if(dataSize == 1){
27  char *paramPtr = inState.template GetFieldBuffer<char>(paramName);
28  if(numComp == 1) {
29  *paramPtr = inConfig.GetValue<char>(paramKey);
30  } else {
31  std::vector<char> paramVec(inConfig.GetValueVector<char>(paramKey));
32  if(paramVec.size() > numComp){
33  messageStream << "ERROR! Parameter " << paramName << " input size mismatch."
34  << std::endl;
35  return(1);
36  }
37  std::vector<char>::iterator pvIt = paramVec.begin();
38  while(pvIt != paramVec.end()){
39  paramPtr[pvIt-paramVec.begin()] = *pvIt;
40  pvIt++;
41  }
42  }
43  } else if(dataSize == 4) {
44  int *paramPtr = inState.template GetFieldBuffer<int>(paramName);
45  if(numComp == 1) {
46  *paramPtr = inConfig.GetValue<int>(paramKey);
47  } else {
48  std::vector<int> paramVec(inConfig.GetValueVector<int>(paramKey));
49  if(paramVec.size() > numComp){
50  messageStream << "ERROR! Parameter " << paramName << " input size mismatch."
51  << std::endl;
52  return(1);
53  }
54  std::vector<int>::iterator pvIt = paramVec.begin();
55  while(pvIt != paramVec.end()){
56  paramPtr[pvIt-paramVec.begin()] = *pvIt;
57  pvIt++;
58  }
59  }
60  } else if(dataSize == 8) {
61  double *paramPtr = inState.template GetFieldBuffer<double>(paramName);
62  if(numComp == 1) {
63  *paramPtr = inConfig.GetValue<double>(paramKey);
64  } else {
65  std::vector<double> paramVec(inConfig.GetValueVector<double>(paramKey));
66  if(paramVec.size() > numComp){
67  messageStream << "ERROR! Parameter " << paramName << " input size mismatch."
68  << std::endl;
69  return(1);
70  }
71  std::vector<double>::iterator pvIt = paramVec.begin();
72  while(pvIt != paramVec.end()){
73  paramPtr[pvIt-paramVec.begin()] = *pvIt;
74  pvIt++;
75  }
76  }
77  }
78  } else {
79  messageStream << "Not found." << std::endl;
80  }
81  }
82  return(0);
83 };
84 #endif
int ConfigStateValues(fixtures::ConfigurationType &inConfig, const std::string &keyRoot, StateType &inState, std::ostream &messageStream)
Definition: ConfigUtil.H:7
std::string GetValue(const std::string &key) const
Definition: Parameters.C:24
std::vector< std::string > GetValueVector(const std::string &key) const
Definition: Parameters.C:36
void const size_t const size_t const size_t const int * numComp
std::string ConfigKey(const std::string &configName, const std::string &keyName)
Definition: PCPPUtil.C:191
bool IsSet(const std::string &Key) const
Definition: Parameters.C:115