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 // - $Id: fcst_utilities.h 2605 2014-08-15 03:36:44Z secanell $
14 //
15 //---------------------------------------------------------------------------
16 
17 #ifndef _FUELCELLSHOP__FCST_UTILITIES_H
18 #define _FUELCELLSHOP__FCST_UTILITIES_H
19 
20 //Include STL and boost libraries
21 #include <cmath>
22 #include <iostream>
23 #include <string>
24 #include <vector>
25 #include <map>
26 #include <cctype>
27 #include <boost/lexical_cast.hpp>
28 #include <fstream>
29 #include <algorithm>
30 
31 //Include deal.ii classes
32 #include <base/utilities.h>
33 #include <base/exceptions.h>
34 #include <base/parameter_handler.h>
35 
36 #include "fe_vectors.h"
37 #include "application_data.h"
38 #include "event.h"
39 #include "application_base.h"
40 #include "application_wrapper.h"
41 
42 //Posix access function
43 #include <unistd.h>
44 
45 using namespace dealii;
46 
47 namespace FcstUtilities
48 {
52  DeclException1 (ExcWrongString,
53  std::string,
54  << "Can't convert the string " << arg1
55  << " to the desired Number type");
56 
66  template <typename NumType>
67  NumType string_to_number(const std::string&);
68 
77  template <typename NumType>
78  std::vector<NumType> string_to_number(const std::vector<std::string>&);
79 
83  template <>
84  unsigned char string_to_number<unsigned char>(const std::string& str);
85 
99  template <typename KeyType, typename ValueType>
100  std::map< KeyType, ValueType > string_to_map(const std::vector<std::string>&);
101 
102 
103 
109  template< typename KeyType, typename ValueType >
110  std::map< KeyType, ValueType > string_to_map(const std::string& name);
111 
112 
113 
118  template<>
119  std::map< unsigned int, std::string > string_to_map<>(const std::string& name);
120 
131  bool is_number(const std::string& s);
132 
139  template< typename KeyType, typename ValueType >
140  std::map< KeyType, std::vector<ValueType> > split_mapvalue_list(const std::map< KeyType, std::string >&, const char delimiter = ';');
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);
185  template <typename NumType>
186  std::string number_to_string(const NumType &num);
187 
192  void read_parameter_files(ParameterHandler& param,
193  const std::string& filename);
194 
202  bool file_exists(const std::string &file_name);
203 
204 } //FcstUtilities
205 #endif //_FUELCELLSHOP__FCST_UTILITIES_H
void run_python(std::string script_name, std::string arg)
This function runs external python scripts.
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.
bool is_number(const std::string &s)
This function determines whether a string is a &quot;valid&quot; representation of a number.
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...