Multiscale Universal Interface  2.0
A Concurrent Framework for Coupling Heterogeneous Solvers
preconditioner_ssor.h
Go to the documentation of this file.
1 /*****************************************************************************
2 * Multiscale Universal Interface Code Coupling Library *
3 * *
4 * Copyright (C) 2023 W. Liu *
5 * *
6 * This software is jointly licensed under the Apache License, Version 2.0 *
7 * and the GNU General Public License version 3, you may use it according *
8 * to either. *
9 * *
10 * ** Apache License, version 2.0 ** *
11 * *
12 * Licensed under the Apache License, Version 2.0 (the "License"); *
13 * you may not use this file except in compliance with the License. *
14 * You may obtain a copy of the License at *
15 * *
16 * http://www.apache.org/licenses/LICENSE-2.0 *
17 * *
18 * Unless required by applicable law or agreed to in writing, software *
19 * distributed under the License is distributed on an "AS IS" BASIS, *
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
21 * See the License for the specific language governing permissions and *
22 * limitations under the License. *
23 * *
24 * ** GNU General Public License, version 3 ** *
25 * *
26 * This program is free software: you can redistribute it and/or modify *
27 * it under the terms of the GNU General Public License as published by *
28 * the Free Software Foundation, either version 3 of the License, or *
29 * (at your option) any later version. *
30 * *
31 * This program is distributed in the hope that it will be useful, *
32 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
33 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
34 * GNU General Public License for more details. *
35 * *
36 * You should have received a copy of the GNU General Public License *
37 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
38 *****************************************************************************/
39 
47 #ifndef MUI_PRECONDITIONER_SSOR_H_
48 #define MUI_PRECONDITIONER_SSOR_H_
49 
50 #include <math.h>
51 #include <limits>
52 
53 namespace mui {
54 namespace linalg {
55 
56 // Constructor
57 template<typename ITYPE, typename VTYPE>
59  : A_(A), omega_(omega) {}
60 
61 // Destructor
62 template<typename ITYPE, typename VTYPE>
64  // Deallocate the memory for the coefficient matrix
65  A_.set_zero();
66  // Set the relaxation parameter to null
67  omega_ = 0;
68 }
69 
70 // Member function on preconditioner apply
71 template<typename ITYPE, typename VTYPE>
73  assert((x.get_cols()==1) &&
74  "MUI Error [preconditioner_ssor.h]: apply only works for column vectors");
77 
78  // Forward substitution
79  for (ITYPE i = 0; i < A_.get_rows(); ++i) {
80  VTYPE sum = 0;
81  for (ITYPE j = 0; j < A_.get_cols(); ++j) {
82  if (i < j) {
83  sum += A_.get_value(i,j) * y.get_value(j,0);
84  } else if (i == j) {
85  assert(std::abs(omega_ * A_.get_value(i,j)) >= std::numeric_limits<VTYPE>::min() &&
86  "MUI Error [preconditioner_ssor.h]: Divide by zero assert for omega_ * A_.get_value(i,j)");
87  y.set_value(i, 0, ((x.get_value(i,0) - sum) / (omega_ * A_.get_value(i,j))));
88  }
89  }
90  }
91 
92  // Back substitution
93  for (ITYPE i = A_.get_rows() - 1; i >= 0; i--) {
94  VTYPE sum = 0;
95  for (ITYPE j = 0; j < A_.get_cols(); ++j) {
96  if (i > j) {
97  sum += A_.get_value(i,j) * z.get_value(j,0);
98  } else if (i == j) {
99  assert(std::abs(A_.get_value(i,j)) >= std::numeric_limits<VTYPE>::min() &&
100  "MUI Error [preconditioner_ssor.h]: Divide by zero assert for A_.get_value(i,j)");
101  z.set_value(i, 0, (omega_ * (y.get_value(i,0) - sum) / A_.get_value(i,j)));
102  }
103  }
104  }
105  return z;
106 }
107 
108 } // linalg
109 } // mui
110 
111 #endif /* MUI_PRECONDITIONER_SSOR_H_ */
Definition: matrix.h:61
ITYPE get_rows() const
Definition: matrix_io_info.h:579
void set_value(ITYPE, ITYPE, VTYPE, bool=true)
Definition: matrix_manipulation.h:292
VTYPE get_value(ITYPE, ITYPE) const
Definition: matrix_io_info.h:523
ITYPE get_cols() const
Definition: matrix_io_info.h:585
sparse_matrix< ITYPE, VTYPE > apply(const sparse_matrix< ITYPE, VTYPE > &)
Definition: preconditioner_ssor.h:72
~symmetric_successive_over_relaxation_preconditioner()
Definition: preconditioner_ssor.h:63
symmetric_successive_over_relaxation_preconditioner(const sparse_matrix< ITYPE, VTYPE > &, VTYPE=1.0)
Definition: preconditioner_ssor.h:58
u u u u u u min
Definition: dim.h:289
Definition: comm.h:54
SCALAR sum(vexpr< E, SCALAR, D > const &u)
Definition: point.h:362