preconditioner_array.h
Go to the documentation of this file.
1 // LIC// ====================================================================
2 // LIC// This file forms part of oomph-lib, the object-oriented,
3 // LIC// multi-physics finite-element library, available
4 // LIC// at http://www.oomph-lib.org.
5 // LIC//
6 // LIC// Copyright (C) 2006-2022 Matthias Heil and Andrew Hazel
7 // LIC//
8 // LIC// This library is free software; you can redistribute it and/or
9 // LIC// modify it under the terms of the GNU Lesser General Public
10 // LIC// License as published by the Free Software Foundation; either
11 // LIC// version 2.1 of the License, or (at your option) any later version.
12 // LIC//
13 // LIC// This library is distributed in the hope that it will be useful,
14 // LIC// but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // LIC// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // LIC// Lesser General Public License for more details.
17 // LIC//
18 // LIC// You should have received a copy of the GNU Lesser General Public
19 // LIC// License along with this library; if not, write to the Free Software
20 // LIC// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 // LIC// 02110-1301 USA.
22 // LIC//
23 // LIC// The authors may be contacted at oomph-lib@maths.man.ac.uk.
24 // LIC//
25 // LIC//====================================================================
26 // Include guards
27 #ifndef OOMPH_PRECONDITION_ARRAY_HEADER
28 #define OOMPH_PRECONDITION_ARRAY_HEADER
29 
30 // Config header generated by autoconfig
31 #ifdef HAVE_CONFIG_H
32 #include <oomph-lib-config.h>
33 #endif
34 
35 // oomph-lib includes
36 #include "Vector.h"
37 #include "double_vector.h"
38 #include "matrices.h"
39 #include "preconditioner.h"
40 
41 
42 // Preconditioner array is only really possible and useful if we have MPI
43 // (and it uses a lot of MPI functions in the .cc file so changing that
44 // would be hard). So if we don't have MPI just define a dummy
45 // implementation that throws an error if you try to use it.
46 #ifndef OOMPH_HAS_MPI
47 namespace oomph
48 {
50  {
51  public:
54  const OomphCommunicator* comm_pt)
55  {
56  throw OomphLibError("PreconditionerArray requires MPI",
59  }
60 
63  {
64  throw OomphLibError("PreconditionerArray requires MPI",
67  }
68  };
69 } // namespace oomph
70 
71 // Otherwise (if we have MPI do the real implementation)
72 #else
73 
74 #include "mpi.h"
75 
76 
77 namespace oomph
78 {
79  //=============================================================================
100  //=============================================================================
101  class PreconditionerArray
102  {
103  public:
105  PreconditionerArray()
106  : Preconditioner_pt(0),
107  Global_communicator_pt(0),
108  Local_communicator_pt(0)
109  {
110  Method = 0;
111  Nprec = 0;
112  };
113 
115  PreconditionerArray(const PreconditionerArray&) = delete;
116 
118  void operator=(const PreconditionerArray&) = delete;
119 
121  ~PreconditionerArray()
122  {
123  this->clean_up_memory();
124  }
125 
131  void setup_preconditioners(Vector<CRDoubleMatrix*> matrix_pt,
132  Vector<Preconditioner*> prec_pt,
133  const OomphCommunicator* comm_pt);
134 
137  void solve_preconditioners(const Vector<DoubleVector>& r,
138  Vector<DoubleVector>& z);
139 
141  void clean_up_memory()
142  {
143  // delete the preconditioner pt
144  delete Preconditioner_pt;
145  Preconditioner_pt = 0;
146 
147  // delete the communicators
148  delete Global_communicator_pt;
149  Global_communicator_pt = 0;
150  delete Local_communicator_pt;
151  Local_communicator_pt = 0;
152 
153  // clear vectors
154  First_row_for_proc.clear();
155  Nrow_local_for_proc.clear();
156  First_row_from_proc.clear();
157  Nrow_local_from_proc.clear();
158  First_proc_for_prec.clear();
159  Nproc_for_prec.clear();
160 
161  // zero
162  Color = 0;
163 
164 #ifdef PARANOID
165  // delete PARANOID check distribution pts
166  for (unsigned i = 0; i < Nprec; i++)
167  {
168  delete Distribution_pt[i];
169  }
170  Distribution_pt.resize(0);
171 #endif
172  }
173 
174  // access function to Method
175  unsigned& method()
176  {
177  return Method;
178  }
179 
180  private:
182  int compute_tag(const int& nproc,
183  const int& source,
184  const int& dest,
185  const int& type)
186  {
187  return source + (nproc * dest) + (nproc * nproc * type);
188  }
189 
191  unsigned Nprec;
192 
194  Preconditioner* Preconditioner_pt;
195 
198  Vector<unsigned> First_proc_for_prec;
199 
202  Vector<unsigned> Nproc_for_prec;
203 
206  Vector<Vector<unsigned>> First_row_for_proc;
207 
210  Vector<Vector<unsigned>> Nrow_local_for_proc;
211 
214  Vector<Vector<unsigned>> First_row_from_proc;
215 
218  Vector<Vector<unsigned>> Nrow_local_from_proc;
219 
221  unsigned Color;
222 
224  OomphCommunicator* Global_communicator_pt;
225 
227  OomphCommunicator* Local_communicator_pt;
228 
229 #ifdef PARANOID
230  // Vector of distribution of each preconditioner - for PARANOID checks only
231  Vector<LinearAlgebraDistribution*> Distribution_pt;
232 #endif
233 
237  unsigned Method;
238 
239  }; // PreconditionerArray
240 } // namespace oomph
241 
242 // End of "if we have MPI"
243 #endif
244 
245 // End of include guard
246 #endif
int i
Definition: BiCGSTAB_step_by_step.cpp:9
Definition: communicator.h:54
Definition: oomph_definitions.h:222
Definition: preconditioner_array.h:50
void solve_preconditioners(const Vector< DoubleVector > &r, Vector< DoubleVector > &z)
Definition: preconditioner_array.h:61
void setup_preconditioners(Vector< CRDoubleMatrix * > matrix_pt, Vector< Preconditioner * > prec_pt, const OomphCommunicator *comm_pt)
Definition: preconditioner_array.h:52
Definition: oomph-lib/src/generic/Vector.h:58
Vector4f Color
Definition: gpuhelper.h:19
unsigned Preconditioner
----------------------—Domain Properties------------------------—
Definition: space_time_oscillating_cylinder.cc:725
void source(const Vector< double > &x, Vector< double > &f)
Source function.
Definition: unstructured_two_d_circle.cc:46
r
Definition: UniformPSDSelfTest.py:20
type
Definition: compute_granudrum_aor.py:141
void clean_up_memory()
Definition: oomph_definitions.cc:86
DRAIG: Change all instances of (SPATIAL_DIM) to (DIM-1).
Definition: AnisotropicHookean.h:10
#define OOMPH_EXCEPTION_LOCATION
Definition: oomph_definitions.h:61
#define OOMPH_CURRENT_FUNCTION
Definition: oomph_definitions.h:86