openCARP
Doxygen code documentation for the open cardiac electrophysiology simulator openCARP
test_ginkgo.cpp
Go to the documentation of this file.
1 
2 
3 #include <stdio.h>
4 #include <iostream>
5 #include <random>
6 #include <string>
7 #include <mpi.h>
8 #include <ginkgo/ginkgo.hpp>
9 
10 #include "../fem/slimfem/src/SF_base.h"
11 #include "electrics.cc"
12 
13 //relative path to electric.cc we may have to change the place of the tests in
14 //order to avoid using relatives pathes
15 #include "../../physics/electric.cc"
16 #include <math.h>
17 #include <tuple>
18 //#include "petsc_utils.h"
19 //using namespace opencarp;
20 
21 class TestGinkgo {
22 
23  private:
24 
25  int n_l = 4;
26  int n_g = 4;
27 
28 
29  protected:
30 
31  public:
32 
34  {
35  mat1.init(n_g, n_g, n_l, n_l, 0, n_l);
36  mat2.init(n_g, n_g, n_l, n_l, 0, n_l);
37 
38 
39  mat_rows = SF::vector<int>(n_g);
40  mat_cols = SF::vector<int>(n_g);
41  mat_vals = SF::vector<double>(n_g);
42 
43  for (size_t r = 0; r < n_g; r++) {
44  for (size_t c = 0; c < n_g; c++) {
45  mat_rows[c] = r;
46  mat_cols[c] = c;
47  mat_vals[c] = rand();
48  }
49  //if set value doesnt work on ginkgo mat use set_values
50  mat1.set_value(mat_rows, mat_cols, mat_vals, false);
51  mat2.set_value(mat_rows, mat_cols, mat_vals, false);
52  }
53  //std::tuple<auto, auto> {mat1,mat2}
54  }
55 
56  std::tuple<auto, auto> generate_random_petsc_ginkgo_matrices()
57  {
58  mat_g = new SF::ginkgo_matrix<int, double>();
59  mat_p = new SF::petsc_matrix<int, double>();
60 
61  vec_p = new SF::petsc_vector<int, double>();
62  vec_g = new SF::ginkgo_matrix<int, double>();
63 
64  fill_matrices_same_random(mat_g,mat_p)
65  fill_matrices_same_random(vec_g,vec_p)
66 
67  return {{mat_g, mat_p},{vec_g, vec_p}};
68  }
69 
70  // virtual void test_solver_elliptic_electrics()
71  // {
72  // std::tuple<auto,auto> T = generate_random_petsc_ginkgo_matrices();
73  // auto A_p = T[0][1];
74  // auto A_g = T[0][0];
75  // auto b_p = T[1][1];
76  // auto b_g = T[1][0];
77  //
78  // intervalle = 0.0000000001
79  //
80  // ginkgo_solution = elliptic_solver::solve("METTRE ARGUMENTS / creer solve du solver")
81  // petsc_solution = elliptic_solver::solve("arguments missing")
82  //
83  // delta_sq_sqrt = pow(pow(ginkgo_solution-petsc_solution,2),0.5)
84  //
85  // assertTrue( delta_sq_sqrt <= pow(pow(intervalle,2),0.5), "solver elliptic elec OK");
86  // }
87 
88  void assertTrue(bool cond_bool, std::string str)
89  {
90  if (cond_bool)
91  {
92  std::cout << "\033[32m[SUCCESS]\033[0m " << str << std::endl;
93  }
94  else
95  {
96  std::cout << "\033[31m[FAILURE]\033[0m " << str << std::endl;
97  }
98  }
99  }
100 
101 int main(int argc, char** argv)
102 {
103  // init MPI
104  MPI_Init(&argc, &argv);
105  MPI_Comm comm = SF_COMM;
106  int rank, size;
107  MPI_Comm_size(comm, &size); MPI_Comm_rank(comm, &rank);
108 
109  // init PETSc
110  PetscInitialize( &argc, &argv, (char *)0, "" );
111 
112  // start testing
113  auto test = TestGinkgo();
114  //test.test_solver_elliptic_electrics()
115 
116  // end MPI
117  MPI_Finalize();
118 }
virtual void init(T iNRows, T iNCols, T ilrows, T ilcols, T loc_offset, T mxent)
void fill_matrices_same_random(SF::abstract_matrix< int, double > &mat1, SF::abstract_matrix< int, double > &mat2)
Definition: test_ginkgo.cpp:33
#define SF_COMM
the default SlimFem MPI communicator
Definition: SF_globals.h:27
class TestGinkgo main(int argc, char **argv)
void assertTrue(bool cond_bool, std::string str)
Definition: test_ginkgo.cpp:88
virtual void set_value(T row_idx, T col_idx, S val, bool add)=0
Tissue level electrics, main Electrics physics class.
std::tuple< auto, auto > generate_random_petsc_ginkgo_matrices()
Definition: test_ginkgo.cpp:56