OpenFCST: The open-source Fuel Cell Simulation Toolbox
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
fcst_utilities.h
Go to the documentation of this file.
1 //---------------------------------------------------------------------------
2 //
3 // FCST: Fuel Cell Simulation Toolbox
4 //
5 // Copyright (C) 2013 by Energy Systems Design Laboratory, University of Alberta
6 //
7 // This software is distributed under the MIT License.
8 // For more information, see the README file in /doc/LICENSE
9 //
10 // - Class: fcst_utilities.h
11 // - Description: Namespace carrying a lot of utility functions
12 // - Developers: Madhur Bhaiya, Valentin N. Zingan, Marc Secanell, Phil Wardlaw
13 //
14 //---------------------------------------------------------------------------
15 
16 #ifndef _FUELCELLSHOP__FCST_UTILITIES_H
17 #define _FUELCELLSHOP__FCST_UTILITIES_H
18 
19 //Include STL and boost libraries
20 #include <cmath>
21 #include <iostream>
22 #include <string>
23 #include <vector>
24 #include <map>
25 #include <cctype>
26 #include <boost/lexical_cast.hpp>
27 #include <fstream>
28 #include <algorithm>
29 #include <boost/tokenizer.hpp>
30 #include <stdlib.h>
31 
32 
33 //Include deal.ii classes
34 #include <deal.II/base/utilities.h>
35 #include <deal.II/base/exceptions.h>
36 
38 
39 //Posix access function
40 #include <unistd.h>
41 
42 using namespace dealii;
43 
44 namespace FcstUtilities
45 {
49  DeclException1 (ExcWrongString,
50  std::string,
51  << "Can't convert the string " << arg1
52  << " to the desired Number type");
53 
63  template <typename NumType>
64  NumType string_to_number(const std::string&);
65 
74  template <typename NumType>
75  std::vector<NumType> string_to_number(const std::vector<std::string>&);
76 
80  template <>
81  unsigned char string_to_number<unsigned char>(const std::string& str);
82 
95  template <typename KeyType, typename ValueType>
96  std::map< KeyType, ValueType > string_to_map(const std::vector<std::string>&);
97 
103  template< typename KeyType, typename ValueType >
104  std::map< KeyType, ValueType > string_to_map(const std::string& name);
105 
116  int cellId_to_index(std::string& cell_id);
117 
125  bool is_number(const std::string& s);
126 
133  template< typename KeyType, typename ValueType >
134  std::map< KeyType, std::vector<ValueType> > split_mapvalue_list(const std::map< KeyType, std::string >&, const char delimiter = ';');
140  void print_parameter_file_PRM(ParameterHandler& param, std::string path = "default.prm");
141 
147  void print_parameter_file_XML(ParameterHandler& param, std::string path = "default.xml");
148 
153  std::string find_fcst_root();
154 
155 
160  void run_python(std::string script_name,std::string arg);
161 
178  template <typename ValType>
179  void modify_parameter_file(const std::string name_design_var,
180  const ValType value_design_var,
181  ParameterHandler& param);
182 
183  template <typename ValType>
184  void modify_parameter_file(const std::vector<std::string> name_design_var,
185  const std::vector<ValType> value_design_var,
186  ParameterHandler& param);
187 
191  template <typename NumType>
192  std::string number_to_string(const NumType &num);
193 
198  void read_parameter_files(ParameterHandler& param,
199  const std::string& filename);
200 
208  bool file_exists(const std::string &file_name);
209 
210 } //FcstUtilities
211 #endif //_FUELCELLSHOP__FCST_UTILITIES_H
void run_python(std::string script_name, std::string arg)
This function runs external python scripts.
void print_parameter_file_PRM(ParameterHandler &param, std::string path="default.prm")
This function prepares an PRM file with ALL your data inside.
std::string number_to_string(const NumType &num)
Function for casting from double to string.
bool file_exists(const std::string &file_name)
Check if a file exists.
void modify_parameter_file(const std::string name_design_var, const ValType value_design_var, ParameterHandler &param)
This routine is used to parse the input parameter.
void read_parameter_files(ParameterHandler &param, const std::string &filename)
This function reads parameter files written in both prm and xml formats.
NumType string_to_number(const std::string &)
Function to convert a std::string into Number template.
int cellId_to_index(std::string &cell_id)
This function determines whether a string is a &quot;valid&quot; representation of a number.
bool is_number(const std::string &s)
This function extracts to parent cell index from the dealii CellID.
void print_parameter_file_XML(ParameterHandler &param, std::string path="default.xml")
This function prepares an XML file with ALL your data inside.
unsigned char string_to_number< unsigned char >(const std::string &str)
Function to convert a std::string into an unsigned char such as types::material_id and types::boundar...
DeclException1(ExcWrongString, std::string,<< "Can't convert the string "<< arg1<< " to the desired Number type")
Exception shown when a particular string can&#39;t be converted to Number type.
std::string find_fcst_root()
This function returns the address of the fcst root directory.
std::map< KeyType, ValueType > string_to_map(const std::vector< std::string > &)
Function to convert a std::vector&lt; std::string &gt; into std::map&lt; KeyType, ValueType &gt;...
std::map< KeyType, std::vector< ValueType > > split_mapvalue_list(const std::map< KeyType, std::string > &, const char delimiter= ';')
This function takes a std::map&lt;KeyType, std::string&gt;, and std::string contains text separated by a de...