PRISMS-PF  v2.1
variableValueContainer.h
Go to the documentation of this file.
1 // This class permits the access of a subset of indexed fields and gives an error if any non-allowed fields are requested
2 #ifndef VARIBLEVALUECONTAINER_H
3 #define VARIBLEVALUECONTAINER_H
4 
6 {
7 public:
9 
10  void set(unsigned int global_variable_index, double variable_value){
11  var_index.push_back(global_variable_index);
12  value.push_back(variable_value);
13  num_entries++;
14  };
15  double operator()(unsigned int global_variable_index){
16  for (unsigned int i=0; i < num_entries; i++){
17  if (global_variable_index == var_index[i]){
18  return value[i];
19  }
20  }
21 
22  // If this point is reached, the index isn't allowed so an error should be thrown
23  std::cerr << "PRISMS-PF Error: Attempted access of a variable value that was not marked as needed in 'parameters.in'. Double-check the indices in user functions where a variable value is requested." << std::endl;
24  abort();
25  };
26 private:
27  std::vector<unsigned int> var_index;
28  std::vector<double> value;
29  unsigned int num_entries;
30 };
31 
32 // void variableValueContainer::set(unsigned int global_variable_index, double variable_value){
33 // var_index.push_back(global_variable_index);
34 // value.push_back(variable_value);
35 // num_entries++;
36 // }
37 //
38 // double variableValueContainer::operator()(unsigned int global_variable_index){
39 // for (unsigned int i=0; i < num_entries; i++){
40 // if (global_variable_index == var_index[i]){
41 // return value[i];
42 // }
43 // }
44 //
45 // // If this point is reached, the index isn't allowed so an error should be thrown
46 // std::cerr << "PRISMS-PF Error: Attempted access of a variable value that was not marked as needed in 'parameters.in'. Double-check the indices in user functions where a variable value is requested." << std::endl;
47 // abort();
48 // }
49 
50 #endif
std::vector< unsigned int > var_index
double operator()(unsigned int global_variable_index)
std::vector< double > value