VertexCFD  0.0-dev
VertexCFD_SolverTester.hpp
1 #include <VertexCFD_EvaluatorTestHarness.hpp>
2 
3 #include <Teuchos_DefaultMpiComm.hpp>
4 #include <Tpetra_CrsMatrix.hpp>
5 #include <Tpetra_Map.hpp>
6 
7 //---------------------------------------------------------------------------//
8 // TESTS
9 //---------------------------------------------------------------------------//
10 namespace VertexCFD
11 {
12 namespace Test
13 {
14 //---------------------------------------------------------------------------//
15 class SolverTester : public ::testing::Test
16 {
17  protected:
18  void SetUp()
19  {
20  using GO = Tpetra::Details::DefaultTypes::global_ordinal_type;
21  using LO = Tpetra::Details::DefaultTypes::local_ordinal_type;
22 
23  auto comm = Teuchos::rcp(new Teuchos::MpiComm<int>(MPI_COMM_WORLD));
24  LO nx = 10;
25  LO ny = 10;
26  GO num_global_entries = nx * ny;
27  LO index_base = 0;
28  _map = Teuchos::rcp(
29  new Tpetra::Map<>(num_global_entries, index_base, comm));
30 
31  LO entries_per_row = 5;
32  _matrix = Teuchos::rcp(new Tpetra::CrsMatrix<>(_map, entries_per_row));
33 
34  // Build 2D Laplacian with Dirichlet BCs
35  Teuchos::ArrayRCP<GO> row_inds(entries_per_row);
36  Teuchos::ArrayRCP<double> row_vals(entries_per_row);
37  LO num_local_rows = _map->getLocalNumElements();
38  for (LO local_row = 0; local_row < num_local_rows; ++local_row)
39  {
40  GO global_row = _map->getGlobalElement(local_row);
41  GO ix = global_row % nx;
42  GO iy = global_row / nx;
43 
44  // Diagonal entry
45  row_inds[0] = global_row;
46  row_vals[0] = 4.0;
47  int num_entries = 1;
48 
49  if (ix > 0)
50  {
51  row_inds[num_entries] = ix - 1 + iy * nx;
52  row_vals[num_entries] = -1.0;
53  num_entries++;
54  }
55  if (ix < (nx - 1))
56  {
57  row_inds[num_entries] = ix + 1 + iy * nx;
58  row_vals[num_entries] = -1.0;
59  num_entries++;
60  }
61  if (iy > 0)
62  {
63  row_inds[num_entries] = ix + (iy - 1) * nx;
64  row_vals[num_entries] = -1.0;
65  num_entries++;
66  }
67  if (iy < (ny - 1))
68  {
69  row_inds[num_entries] = ix + (iy + 1) * nx;
70  row_vals[num_entries] = -1.0;
71  num_entries++;
72  }
73 
74  _matrix->insertGlobalValues(global_row,
75  row_inds.view(0, num_entries),
76  row_vals.view(0, num_entries));
77  }
78  _matrix->fillComplete();
79 
80  // Build RHS and solution vector
81  _x = Teuchos::rcp(new Tpetra::MultiVector<>(_map, 1));
82  _x->putScalar(1.0);
83  _y = Teuchos::rcp(new Tpetra::MultiVector<>(_map, 1));
84  _y->putScalar(0.0);
85 
86  // Store reference solution -- this is result of solving a linear
87  // system with above matrix with a right hand side of all ones.
88  // Solution computed using numpy
89  _ref_soln
90  = {1.342423770482685, 2.18484754096537, 2.723654789583171,
91  3.0479959507414374, 3.201077948227338, 3.201077948227339,
92  3.047995950741439, 2.723654789583172, 2.1848475409653703,
93  1.3424237704826851, 2.1848475409653694, 3.6733116037956237,
94  4.6617756666258785, 5.267251065155242, 5.5552378939405775,
95  5.555237893940578, 5.267251065155244, 4.661775666625878,
96  3.6733116037956237, 2.1848475409653707, 2.723654789583172,
97  4.661775666625879, 5.982885207969479, 6.803994749313078,
98  7.19738466843915, 7.197384668439149, 6.803994749313074,
99  5.982885207969476, 4.6617756666258785, 2.7236547895831706,
100  3.0479959507414387, 5.267251065155243, 6.803994749313077,
101  7.768458055688435, 8.232921362063793, 8.232921362063792,
102  7.76845805568843, 6.803994749313073, 5.26725106515524,
103  3.047995950741437, 3.2010779482273386, 5.555237893940577,
104  7.19738466843915, 8.232921362063792, 8.732921362063793,
105  8.732921362063792, 8.232921362063788, 7.197384668439146,
106  5.555237893940573, 3.2010779482273364, 3.201077948227339,
107  5.555237893940577, 7.197384668439149, 8.23292136206379,
108  8.73292136206379, 8.732921362063788, 8.232921362063786,
109  7.197384668439144, 5.555237893940571, 3.201077948227336,
110  3.0479959507414396, 5.267251065155243, 6.803994749313074,
111  7.76845805568843, 8.232921362063788, 8.232921362063786,
112  7.768458055688429, 6.80399474931307, 5.267251065155238,
113  3.0479959507414365, 2.723654789583173, 4.661775666625879,
114  5.982885207969477, 6.803994749313072, 7.1973846684391445,
115  7.197384668439141, 6.8039947493130715, 5.982885207969472,
116  4.661775666625878, 2.72365478958317, 2.1848475409653707,
117  3.6733116037956255, 4.661775666625879, 5.267251065155241,
118  5.555237893940573, 5.555237893940573, 5.267251065155241,
119  4.661775666625878, 3.673311603795623, 2.18484754096537,
120  1.3424237704826854, 2.1848475409653703, 2.7236547895831715,
121  3.047995950741438, 3.201077948227337, 3.2010779482273364,
122  3.0479959507414374, 2.7236547895831706, 2.1848475409653694,
123  1.342423770482685};
124  }
125 
126  void TearDown() {}
127 
128  void solve() {}
129 
130  protected:
131  Teuchos::RCP<Tpetra::Map<>> _map;
132  Teuchos::RCP<Tpetra::CrsMatrix<>> _matrix;
133  Teuchos::RCP<Tpetra::MultiVector<>> _x;
134  Teuchos::RCP<Tpetra::MultiVector<>> _y;
135  std::vector<double> _ref_soln;
136 };
137 
138 //---------------------------------------------------------------------------//
139 
140 } // end namespace Test
141 } // end namespace VertexCFD
VertexCFD
Definition: tstMethodManufacturedSolutionBC.cpp:23
VertexCFD::Test::SolverTester
Definition: VertexCFD_SolverTester.hpp:16