MFEM  v4.2.0
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
ortho_solver.cpp
Go to the documentation of this file.
1 // Copyright (c) 2010-2020, Lawrence Livermore National Security, LLC. Produced
2 // at the Lawrence Livermore National Laboratory. All Rights reserved. See files
3 // LICENSE and NOTICE for details. LLNL-CODE-806117.
4 //
5 // This file is part of the MFEM library. For more information and source code
6 // availability visit https://mfem.org.
7 //
8 // MFEM is free software; you can redistribute it and/or modify it under the
9 // terms of the BSD-3 license. We welcome feedback and contributions, see file
10 // CONTRIBUTING.md for details.
11 
12 #include "ortho_solver.hpp"
13 
14 using namespace mfem;
15 using namespace navier;
16 
18 
20 {
21  oper = &op;
22 }
23 
24 void OrthoSolver::Mult(const Vector &b, Vector &x) const
25 {
26  // Orthogonalize input
27  Orthogonalize(b, b_ortho);
28 
29  // Apply operator
30  oper->Mult(b_ortho, x);
31 
32  // Orthogonalize output
33  Orthogonalize(x, x);
34 }
35 
36 void OrthoSolver::Orthogonalize(const Vector &v, Vector &v_ortho) const
37 {
38  double loc_sum = v.Sum();
39  double global_sum = 0.0;
40  int loc_size = v.Size();
41  int global_size = 0;
42 
43  MPI_Allreduce(&loc_sum, &global_sum, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
44  MPI_Allreduce(&loc_size, &global_size, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
45 
46  double ratio = global_sum / static_cast<double>(global_size);
47  v_ortho.SetSize(v.Size());
48  for (int i = 0; i < v_ortho.Size(); ++i)
49  {
50  v_ortho(i) = v(i) - ratio;
51  }
52 }
void SetSize(int s)
Resize the vector to size s.
Definition: vector.hpp:459
int Size() const
Returns the size of the vector.
Definition: vector.hpp:160
virtual void Mult(const Vector &x, Vector &y) const =0
Operator application: y=A(x).
virtual void SetOperator(const Operator &op)
Set/update the solver for the given operator.
double b
Definition: lissajous.cpp:42
void Mult(const Vector &b, Vector &x) const
Operator application: y=A(x).
Vector data type.
Definition: vector.hpp:51
Base class for solvers.
Definition: operator.hpp:634
Abstract operator.
Definition: operator.hpp:24
double Sum() const
Return the sum of the vector entries.
Definition: vector.cpp:849