MFEM  v4.3.0
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
operator.cpp
Go to the documentation of this file.
1 // Copyright (c) 2010-2021, 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 "vector.hpp"
13 #include "operator.hpp"
14 #include "../general/forall.hpp"
15 
16 #include <iostream>
17 #include <iomanip>
18 
19 namespace mfem
20 {
21 
22 void Operator::InitTVectors(const Operator *Po, const Operator *Ri,
23  const Operator *Pi,
24  Vector &x, Vector &b,
25  Vector &X, Vector &B) const
26 {
27  if (!IsIdentityProlongation(Po))
28  {
29  // Variational restriction with Po
30  B.SetSize(Po->Width(), b);
31  Po->MultTranspose(b, B);
32  }
33  else
34  {
35  // B points to same data as b
36  B.MakeRef(b, 0, b.Size());
37  }
38  if (!IsIdentityProlongation(Pi))
39  {
40  // Variational restriction with Ri
41  X.SetSize(Ri->Height(), x);
42  Ri->Mult(x, X);
43  }
44  else
45  {
46  // X points to same data as x
47  X.MakeRef(x, 0, x.Size());
48  }
49 }
50 
51 void Operator::FormLinearSystem(const Array<int> &ess_tdof_list,
52  Vector &x, Vector &b,
53  Operator* &Aout, Vector &X, Vector &B,
54  int copy_interior)
55 {
56  const Operator *P = this->GetProlongation();
57  const Operator *R = this->GetRestriction();
58  InitTVectors(P, R, P, x, b, X, B);
59 
60  if (!copy_interior) { X.SetSubVectorComplement(ess_tdof_list, 0.0); }
61 
62  ConstrainedOperator *constrainedA;
63  FormConstrainedSystemOperator(ess_tdof_list, constrainedA);
64  constrainedA->EliminateRHS(X, B);
65  Aout = constrainedA;
66 }
67 
69  const Array<int> &trial_tdof_list,
70  const Array<int> &test_tdof_list, Vector &x, Vector &b,
71  Operator* &Aout, Vector &X, Vector &B)
72 {
73  const Operator *Pi = this->GetProlongation();
74  const Operator *Po = this->GetOutputProlongation();
75  const Operator *Ri = this->GetRestriction();
76  InitTVectors(Po, Ri, Pi, x, b, X, B);
77 
78  RectangularConstrainedOperator *constrainedA;
79  FormRectangularConstrainedSystemOperator(trial_tdof_list, test_tdof_list,
80  constrainedA);
81  constrainedA->EliminateRHS(X, B);
82  Aout = constrainedA;
83 }
84 
86 {
87  // Same for Rectangular and Square operators
88  const Operator *P = this->GetProlongation();
89  if (!IsIdentityProlongation(P))
90  {
91  // Apply conforming prolongation
92  x.SetSize(P->Height());
93  P->Mult(X, x);
94  }
95  else
96  {
97  // X and x point to the same data
98 
99  // If the validity flags of X's Memory were changed (e.g. if it was moved
100  // to device memory) then we need to tell x about that.
101  x.SyncMemory(X);
102  }
103 }
104 
106 {
107  Operator *rap;
108  if (!IsIdentityProlongation(Pi))
109  {
110  if (!IsIdentityProlongation(Po))
111  {
112  rap = new RAPOperator(*Po, *this, *Pi);
113  }
114  else
115  {
116  rap = new ProductOperator(this, Pi, false,false);
117  }
118  }
119  else
120  {
121  if (!IsIdentityProlongation(Po))
122  {
123  TransposeOperator * PoT = new TransposeOperator(Po);
124  rap = new ProductOperator(PoT, this, true,false);
125  }
126  else
127  {
128  rap = this;
129  }
130  }
131  return rap;
132 }
133 
135  const Array<int> &ess_tdof_list, ConstrainedOperator* &Aout)
136 {
137  const Operator *P = this->GetProlongation();
138  Operator *rap = SetupRAP(P, P);
139 
140  // Impose the boundary conditions through a ConstrainedOperator, which owns
141  // the rap operator when P and R are non-trivial
142  ConstrainedOperator *A = new ConstrainedOperator(rap, ess_tdof_list,
143  rap != this);
144  Aout = A;
145 }
146 
148  const Array<int> &trial_tdof_list, const Array<int> &test_tdof_list,
150 {
151  const Operator *Pi = this->GetProlongation();
152  const Operator *Po = this->GetOutputProlongation();
153  Operator *rap = SetupRAP(Pi, Po);
154 
155  // Impose the boundary conditions through a RectangularConstrainedOperator,
156  // which owns the rap operator when P and R are non-trivial
159  trial_tdof_list, test_tdof_list,
160  rap != this);
161  Aout = A;
162 }
163 
164 void Operator::FormSystemOperator(const Array<int> &ess_tdof_list,
165  Operator* &Aout)
166 {
168  FormConstrainedSystemOperator(ess_tdof_list, A);
169  Aout = A;
170 }
171 
173  const Array<int> &test_tdof_list,
174  Operator* &Aout)
175 {
177  FormRectangularConstrainedSystemOperator(trial_tdof_list, test_tdof_list, A);
178  Aout = A;
179 }
180 
182 {
183  const Operator *Pin = this->GetProlongation();
184  const Operator *Rout = this->GetOutputRestriction();
185  Aout = new TripleProductOperator(Rout, this, Pin,false, false, false);
186 }
187 
188 void Operator::PrintMatlab(std::ostream & out, int n, int m) const
189 {
190  using namespace std;
191  if (n == 0) { n = width; }
192  if (m == 0) { m = height; }
193 
194  Vector x(n), y(m);
195  x = 0.0;
196 
197  out << setiosflags(ios::scientific | ios::showpos);
198  for (int i = 0; i < n; i++)
199  {
200  x(i) = 1.0;
201  Mult(x, y);
202  for (int j = 0; j < m; j++)
203  {
204  if (y(j))
205  {
206  out << j+1 << " " << i+1 << " " << y(j) << '\n';
207  }
208  }
209  x(i) = 0.0;
210  }
211 }
212 
213 
215 {
216  mfem_error("TimeDependentOperator::ExplicitMult() is not overridden!");
217 }
218 
220  Vector &) const
221 {
222  mfem_error("TimeDependentOperator::ImplicitMult() is not overridden!");
223 }
224 
226 {
227  mfem_error("TimeDependentOperator::Mult() is not overridden!");
228 }
229 
230 void TimeDependentOperator::ImplicitSolve(const double, const Vector &,
231  Vector &)
232 {
233  mfem_error("TimeDependentOperator::ImplicitSolve() is not overridden!");
234 }
235 
237  const Vector &, const Vector &, double) const
238 {
239  mfem_error("TimeDependentOperator::GetImplicitGradient() is "
240  "not overridden!");
241  return const_cast<Operator &>(dynamic_cast<const Operator &>(*this));
242 }
243 
245 {
246  mfem_error("TimeDependentOperator::GetExplicitGradient() is "
247  "not overridden!");
248  return const_cast<Operator &>(dynamic_cast<const Operator &>(*this));
249 }
250 
252  const Vector &,
253  int, int *, double)
254 {
255  mfem_error("TimeDependentOperator::SUNImplicitSetup() is not overridden!");
256  return (-1);
257 }
258 
260 {
261  mfem_error("TimeDependentOperator::SUNImplicitSolve() is not overridden!");
262  return (-1);
263 }
264 
266 {
267  mfem_error("TimeDependentOperator::SUNMassSetup() is not overridden!");
268  return (-1);
269 }
270 
272 {
273  mfem_error("TimeDependentOperator::SUNMassSolve() is not overridden!");
274  return (-1);
275 }
276 
278 {
279  mfem_error("TimeDependentOperator::SUNMassMult() is not overridden!");
280  return (-1);
281 }
282 
283 
285  const Vector &dxdt,
286  Vector &y) const
287 {
288  mfem_error("SecondOrderTimeDependentOperator::Mult() is not overridden!");
289 }
290 
292  const double dt1,
293  const Vector &x,
294  const Vector &dxdt,
295  Vector &k)
296 {
297  mfem_error("SecondOrderTimeDependentOperator::ImplicitSolve() is not overridden!");
298 }
299 
300 
302  bool ownA, bool ownB)
303  : Operator(A->Height(), B->Width()),
304  A(A), B(B), ownA(ownA), ownB(ownB), z(A->Width())
305 {
306  MFEM_VERIFY(A->Width() == B->Height(),
307  "incompatible Operators: A->Width() = " << A->Width()
308  << ", B->Height() = " << B->Height());
309 
310  {
311  const Solver* SolverB = dynamic_cast<const Solver*>(B);
312  if (SolverB)
313  {
314  MFEM_VERIFY(!(SolverB->iterative_mode),
315  "Operator B of a ProductOperator should not be in iterative mode");
316  }
317  }
318 }
319 
321 {
322  if (ownA) { delete A; }
323  if (ownB) { delete B; }
324 }
325 
326 
328  const Operator &P_)
329  : Operator(Rt_.Width(), P_.Width()), Rt(Rt_), A(A_), P(P_)
330 {
331  MFEM_VERIFY(Rt.Height() == A.Height(),
332  "incompatible Operators: Rt.Height() = " << Rt.Height()
333  << ", A.Height() = " << A.Height());
334  MFEM_VERIFY(A.Width() == P.Height(),
335  "incompatible Operators: A.Width() = " << A.Width()
336  << ", P.Height() = " << P.Height());
337 
338  {
339  const Solver* SolverA = dynamic_cast<const Solver*>(&A);
340  if (SolverA)
341  {
342  MFEM_VERIFY(!(SolverA->iterative_mode),
343  "Operator A of an RAPOperator should not be in iterative mode");
344  }
345 
346  const Solver* SolverP = dynamic_cast<const Solver*>(&P);
347  if (SolverP)
348  {
349  MFEM_VERIFY(!(SolverP->iterative_mode),
350  "Operator P of an RAPOperator should not be in iterative mode");
351  }
352  }
353 
354  mem_class = Rt.GetMemoryClass()*P.GetMemoryClass();
355  MemoryType mem_type = GetMemoryType(A.GetMemoryClass()*mem_class);
356  Px.SetSize(P.Height(), mem_type);
357  APx.SetSize(A.Height(), mem_type);
358 }
359 
360 
362  const Operator *A, const Operator *B, const Operator *C,
363  bool ownA, bool ownB, bool ownC)
364  : Operator(A->Height(), C->Width())
365  , A(A), B(B), C(C)
366  , ownA(ownA), ownB(ownB), ownC(ownC)
367 {
368  MFEM_VERIFY(A->Width() == B->Height(),
369  "incompatible Operators: A->Width() = " << A->Width()
370  << ", B->Height() = " << B->Height());
371  MFEM_VERIFY(B->Width() == C->Height(),
372  "incompatible Operators: B->Width() = " << B->Width()
373  << ", C->Height() = " << C->Height());
374 
375  {
376  const Solver* SolverB = dynamic_cast<const Solver*>(B);
377  if (SolverB)
378  {
379  MFEM_VERIFY(!(SolverB->iterative_mode),
380  "Operator B of a TripleProductOperator should not be in iterative mode");
381  }
382 
383  const Solver* SolverC = dynamic_cast<const Solver*>(C);
384  if (SolverC)
385  {
386  MFEM_VERIFY(!(SolverC->iterative_mode),
387  "Operator C of a TripleProductOperator should not be in iterative mode");
388  }
389  }
390 
391  mem_class = A->GetMemoryClass()*C->GetMemoryClass();
392  MemoryType mem_type = GetMemoryType(mem_class*B->GetMemoryClass());
393  t1.SetSize(C->Height(), mem_type);
394  t2.SetSize(B->Height(), mem_type);
395 }
396 
398 {
399  if (ownA) { delete A; }
400  if (ownB) { delete B; }
401  if (ownC) { delete C; }
402 }
403 
404 
406  bool own_A_,
407  DiagonalPolicy diag_policy_)
408  : Operator(A->Height(), A->Width()), A(A), own_A(own_A_),
409  diag_policy(diag_policy_)
410 {
411  // 'mem_class' should work with A->Mult() and MFEM_FORALL():
413  MemoryType mem_type = GetMemoryType(mem_class);
414  list.Read(); // TODO: just ensure 'list' is registered, no need to copy it
415  constraint_list.MakeRef(list);
416  // typically z and w are large vectors, so store them on the device
417  z.SetSize(height, mem_type); z.UseDevice(true);
418  w.SetSize(height, mem_type); w.UseDevice(true);
419 }
420 
422 {
423  A->AssembleDiagonal(diag);
424 
425  if (diag_policy == DIAG_KEEP) { return; }
426 
427  const int csz = constraint_list.Size();
428  auto d_diag = diag.ReadWrite();
429  auto idx = constraint_list.Read();
430  switch (diag_policy)
431  {
432  case DIAG_ONE:
433  MFEM_FORALL(i, csz,
434  {
435  const int id = idx[i];
436  d_diag[id] = 1.0;
437  });
438  break;
439  case DIAG_ZERO:
440  MFEM_FORALL(i, csz,
441  {
442  const int id = idx[i];
443  d_diag[id] = 0.0;
444  });
445  break;
446  default:
447  MFEM_ABORT("unknown diagonal policy");
448  break;
449  }
450 }
451 
453 {
454  w = 0.0;
455  const int csz = constraint_list.Size();
456  auto idx = constraint_list.Read();
457  auto d_x = x.Read();
458  // Use read+write access - we are modifying sub-vector of w
459  auto d_w = w.ReadWrite();
460  MFEM_FORALL(i, csz,
461  {
462  const int id = idx[i];
463  d_w[id] = d_x[id];
464  });
465 
466  // A.AddMult(w, b, -1.0); // if available to all Operators
467  A->Mult(w, z);
468  b -= z;
469 
470  // Use read+write access - we are modifying sub-vector of b
471  auto d_b = b.ReadWrite();
472  MFEM_FORALL(i, csz,
473  {
474  const int id = idx[i];
475  d_b[id] = d_x[id];
476  });
477 }
478 
479 void ConstrainedOperator::Mult(const Vector &x, Vector &y) const
480 {
481  const int csz = constraint_list.Size();
482  if (csz == 0)
483  {
484  A->Mult(x, y);
485  return;
486  }
487 
488  z = x;
489 
490  auto idx = constraint_list.Read();
491  // Use read+write access - we are modifying sub-vector of z
492  auto d_z = z.ReadWrite();
493  MFEM_FORALL(i, csz, d_z[idx[i]] = 0.0;);
494 
495  A->Mult(z, y);
496 
497  auto d_x = x.Read();
498  // Use read+write access - we are modifying sub-vector of y
499  auto d_y = y.ReadWrite();
500  switch (diag_policy)
501  {
502  case DIAG_ONE:
503  MFEM_FORALL(i, csz,
504  {
505  const int id = idx[i];
506  d_y[id] = d_x[id];
507  });
508  break;
509  case DIAG_ZERO:
510  MFEM_FORALL(i, csz,
511  {
512  const int id = idx[i];
513  d_y[id] = 0.0;
514  });
515  break;
516  case DIAG_KEEP:
517  // Needs action of the operator diagonal on vector
518  mfem_error("ConstrainedOperator::Mult #1");
519  break;
520  default:
521  mfem_error("ConstrainedOperator::Mult #2");
522  break;
523  }
524 }
525 
527  Operator *A,
528  const Array<int> &trial_list,
529  const Array<int> &test_list,
530  bool own_A_)
531  : Operator(A->Height(), A->Width()), A(A), own_A(own_A_)
532 {
533  // 'mem_class' should work with A->Mult() and MFEM_FORALL():
535  MemoryType mem_type = GetMemoryType(mem_class);
536  trial_list.Read(); // TODO: just ensure 'list' is registered, no need to copy it
537  test_list.Read(); // TODO: just ensure 'list' is registered, no need to copy it
538  trial_constraints.MakeRef(trial_list);
539  test_constraints.MakeRef(test_list);
540  // typically z and w are large vectors, so store them on the device
541  z.SetSize(height, mem_type); z.UseDevice(true);
542  w.SetSize(width, mem_type); w.UseDevice(true);
543 }
544 
546  Vector &b) const
547 {
548  w = 0.0;
549  const int trial_csz = trial_constraints.Size();
550  auto trial_idx = trial_constraints.Read();
551  auto d_x = x.Read();
552  // Use read+write access - we are modifying sub-vector of w
553  auto d_w = w.ReadWrite();
554  MFEM_FORALL(i, trial_csz,
555  {
556  const int id = trial_idx[i];
557  d_w[id] = d_x[id];
558  });
559 
560  // A.AddMult(w, b, -1.0); // if available to all Operators
561  A->Mult(w, z);
562  b -= z;
563 
564  const int test_csz = test_constraints.Size();
565  auto test_idx = test_constraints.Read();
566  auto d_b = b.ReadWrite();
567  MFEM_FORALL(i, test_csz, d_b[test_idx[i]] = 0.0;);
568 }
569 
571 {
572  const int trial_csz = trial_constraints.Size();
573  const int test_csz = test_constraints.Size();
574  if (trial_csz == 0)
575  {
576  A->Mult(x, y);
577  }
578  else
579  {
580  w = x;
581 
582  auto idx = trial_constraints.Read();
583  // Use read+write access - we are modifying sub-vector of w
584  auto d_w = w.ReadWrite();
585  MFEM_FORALL(i, trial_csz, d_w[idx[i]] = 0.0;);
586 
587  A->Mult(w, y);
588  }
589 
590  if (test_csz != 0)
591  {
592  auto idx = test_constraints.Read();
593  auto d_y = y.ReadWrite();
594  MFEM_FORALL(i, test_csz, d_y[idx[i]] = 0.0;);
595  }
596 }
597 
599  Vector &y) const
600 {
601  const int trial_csz = trial_constraints.Size();
602  const int test_csz = test_constraints.Size();
603  if (test_csz == 0)
604  {
605  A->MultTranspose(x, y);
606  }
607  else
608  {
609  z = x;
610 
611  auto idx = test_constraints.Read();
612  // Use read+write access - we are modifying sub-vector of z
613  auto d_z = z.ReadWrite();
614  MFEM_FORALL(i, test_csz, d_z[idx[i]] = 0.0;);
615 
616  A->MultTranspose(z, y);
617  }
618 
619  if (trial_csz != 0)
620  {
621  auto idx = trial_constraints.Read();
622  auto d_y = y.ReadWrite();
623  MFEM_FORALL(i, trial_csz, d_y[idx[i]] = 0.0;);
624  }
625 }
626 
628  int numSteps, double tolerance, int seed)
629 {
630  v1.SetSize(v0.Size());
631  if (seed != 0)
632  {
633  v0.Randomize(seed);
634  }
635 
636  double eigenvalue = 1.0;
637 
638  for (int iter = 0; iter < numSteps; ++iter)
639  {
640  double normV0;
641 
642 #ifdef MFEM_USE_MPI
643  if (comm != MPI_COMM_NULL)
644  {
645  normV0 = InnerProduct(comm, v0, v0);
646  }
647  else
648  {
649  normV0 = InnerProduct(v0, v0);
650  }
651 #else
652  normV0 = InnerProduct(v0, v0);
653 #endif
654 
655  v0 /= sqrt(normV0);
656  opr.Mult(v0, v1);
657 
658  double eigenvalueNew;
659 #ifdef MFEM_USE_MPI
660  if (comm != MPI_COMM_NULL)
661  {
662  eigenvalueNew = InnerProduct(comm, v0, v1);
663  }
664  else
665  {
666  eigenvalueNew = InnerProduct(v0, v1);
667  }
668 #else
669  eigenvalueNew = InnerProduct(v0, v1);
670 #endif
671  double diff = std::abs((eigenvalueNew - eigenvalue) / eigenvalue);
672 
673  eigenvalue = eigenvalueNew;
674  std::swap(v0, v1);
675 
676  if (diff < tolerance)
677  {
678  break;
679  }
680  }
681 
682  return eigenvalue;
683 }
684 
685 }
static MemoryClass GetMemoryClass()
(DEPRECATED) Equivalent to GetDeviceMemoryClass().
Definition: device.hpp:285
virtual void Mult(const Vector &x, const Vector &dxdt, Vector &y) const
Perform the action of the operator: y = k = f(x,@ dxdt, t), where k solves the algebraic equation F(x...
Definition: operator.cpp:284
int Size() const
Return the logical size of the array.
Definition: array.hpp:134
void FormRectangularSystemOperator(const Array< int > &trial_tdof_list, const Array< int > &test_tdof_list, Operator *&A)
Return in A a parallel (on truedofs) version of this rectangular operator (including constraints)...
Definition: operator.cpp:172
ConstrainedOperator(Operator *A, const Array< int > &list, bool own_A=false, DiagonalPolicy diag_policy=DIAG_ONE)
Constructor from a general Operator and a list of essential indices/dofs.
Definition: operator.cpp:405
virtual ~ProductOperator()
Definition: operator.cpp:320
virtual void AssembleDiagonal(Vector &diag) const
Diagonal of A, modified according to the used DiagonalPolicy.
Definition: operator.cpp:421
Array< int > constraint_list
List of constrained indices/dofs.
Definition: operator.hpp:837
virtual void ImplicitSolve(const double fac0, const double fac1, const Vector &x, const Vector &dxdt, Vector &k)
Solve the equation: k = f(x + fac0 k, dxdt + fac1 k, t), for the unknown k at the current time t...
Definition: operator.cpp:291
void SetSize(int s)
Resize the vector to size s.
Definition: vector.hpp:513
virtual void ImplicitSolve(const double dt, const Vector &x, Vector &k)
Solve the equation: k = f(x + dt k, t), for the unknown k at the current time t.
Definition: operator.cpp:230
int Width() const
Get the width (size of input) of the Operator. Synonym with NumCols().
Definition: operator.hpp:72
virtual void Mult(const Vector &x, Vector &y) const
Constrained operator action.
Definition: operator.cpp:479
virtual Operator & GetExplicitGradient(const Vector &x) const
Return an Operator representing dG/dx at the given point x and the currently set time.
Definition: operator.cpp:244
int Size() const
Returns the size of the vector.
Definition: vector.hpp:190
virtual const Operator * GetOutputProlongation() const
Prolongation operator from linear algebra (linear system) vectors, to output vectors for the operator...
Definition: operator.hpp:121
void EliminateRHS(const Vector &x, Vector &b) const
Eliminate columns corresponding to &quot;essential boundary condition&quot; values specified in x from the give...
Definition: operator.cpp:545
void FormDiscreteOperator(Operator *&A)
Return in A a parallel (on truedofs) version of this rectangular operator.
Definition: operator.cpp:181
ProductOperator(const Operator *A, const Operator *B, bool ownA, bool ownB)
Definition: operator.cpp:301
virtual void Mult(const Vector &x, Vector &y) const =0
Operator application: y=A(x).
bool iterative_mode
If true, use the second argument of Mult() as an initial guess.
Definition: operator.hpp:652
void Randomize(int seed=0)
Set random values in the vector.
Definition: vector.cpp:763
virtual void UseDevice(bool use_dev) const
Enable execution of Vector operations using the mfem::Device.
Definition: vector.hpp:108
virtual void MultTranspose(const Vector &x, Vector &y) const
Action of the transpose operator: y=A^t(x). The default behavior in class Operator is to generate an ...
Definition: operator.hpp:93
void FormRectangularConstrainedSystemOperator(const Array< int > &trial_tdof_list, const Array< int > &test_tdof_list, RectangularConstrainedOperator *&Aout)
see FormRectangularSystemOperator()
Definition: operator.cpp:147
virtual int SUNImplicitSolve(const Vector &b, Vector &x, double tol)
Solve the ODE linear system as setup by the method SUNImplicitSetup().
Definition: operator.cpp:259
virtual void ExplicitMult(const Vector &x, Vector &y) const
Perform the action of the explicit part of the operator, G: y = G(x, t) where t is the current time...
Definition: operator.cpp:214
void FormRectangularLinearSystem(const Array< int > &trial_tdof_list, const Array< int > &test_tdof_list, Vector &x, Vector &b, Operator *&A, Vector &X, Vector &B)
Form a column-constrained linear system using a matrix-free approach.
Definition: operator.cpp:68
virtual const Operator * GetProlongation() const
Prolongation operator from linear algebra (linear system) vectors, to input vectors for the operator...
Definition: operator.hpp:115
General product operator: x -&gt; (A*B)(x) = A(B(x)).
Definition: operator.hpp:736
virtual MemoryClass GetMemoryClass() const
Return the MemoryClass preferred by the Operator.
Definition: operator.hpp:86
int Height() const
Get the height (size of output) of the Operator. Synonym with NumRows().
Definition: operator.hpp:66
static MemoryClass GetDeviceMemoryClass()
Get the current Device MemoryClass. This is the MemoryClass used by most MFEM device kernels to acces...
Definition: device.hpp:281
void mfem_error(const char *msg)
Function called when an error is encountered. Used by the macros MFEM_ABORT, MFEM_ASSERT, MFEM_VERIFY.
Definition: error.cpp:153
void FormConstrainedSystemOperator(const Array< int > &ess_tdof_list, ConstrainedOperator *&Aout)
see FormSystemOperator()
Definition: operator.cpp:134
double b
Definition: lissajous.cpp:42
virtual int SUNMassSetup()
Setup the mass matrix in the ODE system .
Definition: operator.cpp:265
const T * Read(bool on_dev=true) const
Shortcut for mfem::Read(a.GetMemory(), a.Size(), on_dev).
Definition: array.hpp:300
The operator x -&gt; R*A*P*x constructed through the actions of R^T, A and P.
Definition: operator.hpp:756
virtual void MultTranspose(const Vector &x, Vector &y) const
Action of the transpose operator: y=A^t(x). The default behavior in class Operator is to generate an ...
Definition: operator.cpp:598
virtual void Mult(const Vector &x, Vector &y) const
Rectangular-constrained operator action.
Definition: operator.cpp:570
Set the diagonal value to one.
Definition: operator.hpp:49
RAPOperator(const Operator &Rt_, const Operator &A_, const Operator &P_)
Construct the RAP operator given R^T, A and P.
Definition: operator.cpp:327
virtual const Operator * GetRestriction() const
Restriction operator from input vectors for the operator to linear algebra (linear system) vectors...
Definition: operator.hpp:118
void SyncMemory(const Vector &v) const
Update the memory location of the vector to match v.
Definition: vector.hpp:232
void SetSubVectorComplement(const Array< int > &dofs, const double val)
Set all vector entries NOT in the dofs Array to the given val.
Definition: vector.cpp:686
bool IsIdentityProlongation(const Operator *P)
Definition: operator.hpp:686
virtual int SUNMassSolve(const Vector &b, Vector &x, double tol)
Solve the mass matrix linear system as setup by the method SUNMassSetup().
Definition: operator.cpp:271
Vector w
Auxiliary vectors.
Definition: operator.hpp:840
MemoryType
Memory types supported by MFEM.
Definition: mem_manager.hpp:31
void InitTVectors(const Operator *Po, const Operator *Ri, const Operator *Pi, Vector &x, Vector &b, Vector &X, Vector &B) const
Initializes memory for true vectors of linear system.
Definition: operator.cpp:22
virtual Operator & GetImplicitGradient(const Vector &x, const Vector &k, double shift) const
Return an Operator representing (dF/dk shift + dF/dx) at the given x, k, and the currently set time...
Definition: operator.cpp:236
void FormLinearSystem(const Array< int > &ess_tdof_list, Vector &x, Vector &b, Operator *&A, Vector &X, Vector &B, int copy_interior=0)
Form a constrained linear system using a matrix-free approach.
Definition: operator.cpp:51
The transpose of a given operator. Switches the roles of the methods Mult() and MultTranspose().
Definition: operator.hpp:711
virtual void RecoverFEMSolution(const Vector &X, const Vector &b, Vector &x)
Reconstruct a solution vector x (e.g. a GridFunction) from the solution X of a constrained linear sys...
Definition: operator.cpp:85
int height
Dimension of the output / number of rows in the matrix.
Definition: operator.hpp:27
virtual void ImplicitMult(const Vector &x, const Vector &k, Vector &y) const
Perform the action of the implicit part of the operator, F: y = F(x, k, t) where t is the current tim...
Definition: operator.cpp:219
double InnerProduct(HypreParVector *x, HypreParVector *y)
Definition: hypre.cpp:316
virtual double * ReadWrite(bool on_dev=true)
Shortcut for mfem::ReadWrite(vec.GetMemory(), vec.Size(), on_dev).
Definition: vector.hpp:442
Rectangular Operator for imposing essential boundary conditions on the input space using only the act...
Definition: operator.hpp:898
virtual void AssembleDiagonal(Vector &diag) const
Computes the diagonal entries into diag. Typically, this operation only makes sense for linear Operat...
Definition: operator.hpp:107
void EliminateRHS(const Vector &x, Vector &b) const
Eliminate &quot;essential boundary condition&quot; values specified in x from the given right-hand side b...
Definition: operator.cpp:452
void PrintMatlab(std::ostream &out, int n=0, int m=0) const
Prints operator with input size n and output size m in Matlab format.
Definition: operator.cpp:188
Keep the diagonal value.
Definition: operator.hpp:50
void FormSystemOperator(const Array< int > &ess_tdof_list, Operator *&A)
Return in A a parallel (on truedofs) version of this square operator.
Definition: operator.cpp:164
DiagonalPolicy
Defines operator diagonal policy upon elimination of rows and/or columns.
Definition: operator.hpp:46
General triple product operator x -&gt; A*B*C*x, with ownership of the factors.
Definition: operator.hpp:800
MemoryType GetMemoryType(MemoryClass mc)
Return a suitable MemoryType for a given MemoryClass.
Definition: mem_manager.cpp:54
virtual int SUNImplicitSetup(const Vector &x, const Vector &fx, int jok, int *jcur, double gamma)
Setup the ODE linear system or , where .
Definition: operator.cpp:251
virtual void Mult(const Vector &x, Vector &y) const
Perform the action of the operator: y = k = f(x, t), where k solves the algebraic equation F(x...
Definition: operator.cpp:225
TripleProductOperator(const Operator *A, const Operator *B, const Operator *C, bool ownA, bool ownB, bool ownC)
Definition: operator.cpp:361
virtual int SUNMassMult(const Vector &x, Vector &v)
Compute the mass matrix-vector product .
Definition: operator.cpp:277
Operator * SetupRAP(const Operator *Pi, const Operator *Po)
Returns RAP Operator of this, using input/output Prolongation matrices Pi corresponds to &quot;P&quot;...
Definition: operator.cpp:105
void MakeRef(T *, int)
Make this Array a reference to a pointer.
Definition: array.hpp:859
Vector data type.
Definition: vector.hpp:60
void MakeRef(Vector &base, int offset, int size)
Reset the Vector to be a reference to a sub-vector of base.
Definition: vector.hpp:577
DiagonalPolicy diag_policy
Diagonal policy for constrained dofs.
Definition: operator.hpp:842
Base class for solvers.
Definition: operator.hpp:648
Operator * A
The unconstrained Operator.
Definition: operator.hpp:838
Square Operator for imposing essential boundary conditions using only the action, Mult()...
Definition: operator.hpp:834
OutStream out(std::cout)
Global stream used by the library for standard output. Initially it uses the same std::streambuf as s...
Definition: globals.hpp:66
double EstimateLargestEigenvalue(Operator &opr, Vector &v0, int numSteps=10, double tolerance=1e-8, int seed=12345)
Returns an estimate of the largest eigenvalue of the operator opr using the iterative power method...
Definition: operator.cpp:627
Abstract operator.
Definition: operator.hpp:24
virtual const double * Read(bool on_dev=true) const
Shortcut for mfem::Read(vec.GetMemory(), vec.Size(), on_dev).
Definition: vector.hpp:426
Set the diagonal value to zero.
Definition: operator.hpp:48
int width
Dimension of the input / number of columns in the matrix.
Definition: operator.hpp:28
RectangularConstrainedOperator(Operator *A, const Array< int > &trial_list, const Array< int > &test_list, bool own_A=false)
Constructor from a general Operator and a list of essential indices/dofs.
Definition: operator.cpp:526
virtual const Operator * GetOutputRestriction() const
Restriction operator from output vectors for the operator to linear algebra (linear system) vectors...
Definition: operator.hpp:132