source: src/solver/solver_regular.cpp@ 759a6a

Last change on this file since 759a6a was ac6d04, checked in by Julian Iseringhausen <isering@…>, 14 years ago

Merge recent changes of the vmg library into ScaFaCos.

Includes a fix for the communication problems on Jugene.

git-svn-id: https://svn.version.fz-juelich.de/scafacos/trunk@1666 5161e1c8-67bf-11de-9fd5-51895aff932f

  • Property mode set to 100644
File size: 3.1 KB
RevLine 
[dfed1c]1/**
2 * @file solver_regular.cpp
3 * @author Julian Iseringhausen <isering@ins.uni-bonn.de>
4 * @date Mon Apr 18 13:11:32 2011
5 *
6 * @brief VMG::SolverRegular
7 *
8 */
9
10#ifdef HAVE_CONFIG_H
11#include <config.h>
12#endif
13
14#include <iostream>
15
16#include "base/discretization.hpp"
17#include "base/stencil.hpp"
18#include "grid/multigrid.hpp"
19#include "solver/solver_regular.hpp"
20#include "mg.hpp"
21
22using namespace VMG;
23
24// TODO: Implement global communication here
25// TODO: Implement this more efficiently
26// TODO: This has to be reviewed for parallelization
27
28void SolverRegular::AssembleMatrix(const Grid& rhs)
29{
30 Grid::iterator grid_iter;
31 Stencil::iterator stencil_iter;
32 int mat_index, mat_index2;
33 vmg_float prefactor_inv = 1.0 / MG::GetDiscretization()->OperatorPrefactor(rhs);
34 const Stencil& A = MG::GetDiscretization()->GetStencil();
35
36#ifdef DEBUG_MATRIX_CHECKS
37 rhs.IsConsistent();
38#endif
39
[ac6d04]40 this->Realloc(rhs.Global().GlobalSize().Product());
[dfed1c]41
42 for (grid_iter = rhs.Iterators().Local().Begin(); grid_iter != rhs.Iterators().Local().End(); ++grid_iter) {
43
[ac6d04]44 mat_index = rhs.GlobalLinearIndex(*grid_iter + rhs.Global().LocalBegin());
[dfed1c]45
46 assert(mat_index >= 0 && mat_index<this->Size());
47
48 this->Sol(mat_index) = 0.0;
49 this->Rhs(mat_index) = prefactor_inv * rhs.GetVal(*grid_iter);
50
51 for (int l=0; l<this->Size(); l++)
52 this->Mat(mat_index, l) = 0.0;
53
54 this->Mat(mat_index, mat_index) = A.GetDiag();
55
56 for (stencil_iter = A.begin(); stencil_iter != A.end(); ++stencil_iter) {
57
[ac6d04]58 mat_index2 = rhs.GlobalLinearIndex(*grid_iter + rhs.Global().LocalBegin() + stencil_iter->Disp());
[dfed1c]59
60 assert(mat_index2 >= 0 && mat_index2<this->Size());
61
62 this->Mat(mat_index, mat_index2) += stencil_iter->Val();
63
64 }
65 }
66
67 for (int i=0; i<3; ++i) {
68
69 for (grid_iter = rhs.Iterators().Boundary1()[i].Begin(); grid_iter != rhs.Iterators().Boundary1()[i].End(); ++grid_iter) {
70
[ac6d04]71 mat_index = rhs.GlobalLinearIndex(*grid_iter + rhs.Global().LocalBegin());
[dfed1c]72
73 assert(mat_index >= 0 && mat_index<this->Size());
74
75 this->Sol(mat_index) = this->Rhs(mat_index) = rhs.GetVal(*grid_iter);
76
77 for (int l=0; l<this->Size(); l++)
78 this->Mat(mat_index, l) = 0.0;
79
80 this->Mat(mat_index, mat_index) = 1.0;
81
82 }
83
84 for (grid_iter = rhs.Iterators().Boundary2()[i].Begin(); grid_iter != rhs.Iterators().Boundary2()[i].End(); ++grid_iter) {
85
[ac6d04]86 mat_index = rhs.GlobalLinearIndex(*grid_iter + rhs.Global().LocalBegin());
[dfed1c]87
88 assert(mat_index >= 0 && mat_index<this->Size());
89
90 this->Sol(mat_index) = this->Rhs(mat_index) = rhs.GetVal(*grid_iter);
91
92 for (int l=0; l<this->Size(); l++)
93 this->Mat(mat_index, l) = 0.0;
94
95 this->Mat(mat_index, mat_index) = 1.0;
96
97 }
98
99 }
100
101}
102
103void SolverRegular::ExportSol(Grid& sol, Grid& rhs)
104{
105 int index;
106 Index offset;
107
108 for (int i=0; i<3; ++i)
109 offset[i] = (sol.Local().HaloEnd1()[i] > 0 ? 1 : 0);
110
111 for (Grid::iterator iter = sol.Iterators().CompleteGrid().Begin(); iter != sol.Iterators().CompleteGrid().End(); ++iter) {
[ac6d04]112 index = sol.GlobalLinearIndex(sol.Global().LocalBegin() + *iter - offset);
[dfed1c]113 sol(*iter) = this->Sol(index);
114 }
115
116#ifdef DEBUG_MATRIX_CHECKS
117 sol.IsConsistent();
118#endif
119}
Note: See TracBrowser for help on using the repository browser.