CArl
Code Arlequin / C++ implementation
common_functions.h
Go to the documentation of this file.
1 /*
2  * common_functions.h
3  *
4  * Created on: Jan 26, 2016
5  * Author: Thiago Milanetto Schlittler
6  */
7 
8 #ifndef COMMON_COMMON_FUNCTIONS_H_
9 #define COMMON_COMMON_FUNCTIONS_H_
10 
11 #include "common_header_libmesh.h"
12 #include "common_header.h"
13 #include "common_enums.h"
14 
15 int kronecker_delta(unsigned int i,
16  unsigned int j);
17 
18 void clear_line();
19 
20 namespace carl
21 {
24 std::string ExtSolverType_to_string(ExtSolverType input);
25 
26 std::string exec_command(const std::string& cmd);
27 
29  const std::unordered_map<int,int>& input_map,
30  std::unordered_map<int,int>& output_map);
31 
32 template<typename T>
33 void jump_lines(T& filestream, unsigned int numberOfLines = 1)
34 {
35  std::string dummy;
36  for(unsigned int iii = 0; iii < numberOfLines; ++iii)
37  std::getline(filestream,dummy);
38 };
39 
40 int voigt_index_converter(int aaa, int bbb);
41 
43 {
45  int AMeshIdx;
46  int BMeshIdx;
48 };
49 
50 // Point hash function
51 struct PointHash_3D {
52  std::size_t operator()(const std::vector<long>& k) const
53  {
54  long prime0 = 73856093;
55  long prime1 = 19349669;
56  long prime2 = 83492791;
57  long primeN = 2038074743;
58 
59  return ( ( k[0] * prime0 ) ^ ( k[1] * prime1 ) ^ ( k[2] * prime2 ) ) % primeN;
60  }
61 };
62 
64  bool operator()(const std::vector<long>& lhs, const std::vector<long>& rhs) const
65  {
66  return lhs[0] == rhs[0] && lhs[1] == rhs[1] && lhs[2] == rhs[2];
67  }
68 };
69 
70 void print_stats_to_file(std::vector<double>& vec_data, const std::string filename);
71 
72 // Do libMesh's system initialization without the matrix and vector memory allocations
73 template<typename Sys>
74 void reduced_system_init(Sys& system_input)
75 {
76  libMesh::DofMap& system_dof_map = system_input.get_dof_map();
77  libMesh::MeshBase& system_mesh = system_input.get_mesh();
78 
79  unsigned int nb_of_variable_groups = system_input.n_variable_groups();
80  for (unsigned int vg=0; vg<nb_of_variable_groups; vg++)
81  {
82  system_dof_map.add_variable_group(system_input.variable_group(vg));
83  }
84 
85  system_dof_map.distribute_dofs(system_mesh);
86  system_input.reinit_constraints();
87  system_dof_map.prepare_send_list();
88  system_dof_map.compute_sparsity(system_mesh);
89 };
90 }
91 
92 #endif /* COMMON_COMMON_FUNCTIONS_H_ */
int voigt_index_converter(int aaa, int bbb)
void clear_line()
std::string exec_command(const std::string &cmd)
void reduced_system_init(Sys &system_input)
std::size_t operator()(const std::vector< long > &k) const
void print_stats_to_file(std::vector< double > &vec_data, const std::string filename)
ClusterSchedulerType
Definition: common_enums.h:14
void invert_index_unordered_map(const std::unordered_map< int, int > &input_map, std::unordered_map< int, int > &output_map)
std::string ClusterSchedulerType_to_string(ClusterSchedulerType input)
int kronecker_delta(unsigned int i, unsigned int j)
bool operator()(const std::vector< long > &lhs, const std::vector< long > &rhs) const
BaseCGPrecondType
Definition: common_enums.h:35
ExtSolverType
Definition: common_enums.h:22
std::string ExtSolverType_to_string(ExtSolverType input)
void jump_lines(T &filestream, unsigned int numberOfLines=1)
std::string BaseCGPrecondType_to_string(BaseCGPrecondType input)