70 "Number of columns mismatch in Operator::Mult!");
71 for (
int i = 0; i < X.
Size(); i++)
73 MFEM_ASSERT(X[i] && Y[i],
"Missing Vector in Operator::Mult!");
82 "Number of columns mismatch in Operator::MultTranspose!");
83 for (
int i = 0; i < X.
Size(); i++)
85 MFEM_ASSERT(X[i] && Y[i],
"Missing Vector in Operator::MultTranspose!");
94 "Number of columns mismatch in Operator::AddMult!");
95 for (
int i = 0; i < X.
Size(); i++)
97 MFEM_ASSERT(X[i] && Y[i],
"Missing Vector in Operator::AddMult!");
106 "Number of columns mismatch in Operator::AddMultTranspose!");
107 for (
int i = 0; i < X.
Size(); i++)
109 MFEM_ASSERT(X[i] && Y[i],
"Missing Vector in Operator::AddMultTranspose!");
222 trial_tdof_list, test_tdof_list,
254 if (n == 0) { n =
width; }
255 if (m == 0) { m =
height; }
260 os << setiosflags(ios::scientific | ios::showpos);
261 for (
int i = 0; i < n; i++)
265 for (
int j = 0; j < m; j++)
269 os << j+1 <<
" " << i+1 <<
" " << y(j) <<
'\n';
284 mfem_error(
"TimeDependentOperator::ExplicitMult() is not overridden!");
290 mfem_error(
"TimeDependentOperator::ImplicitMult() is not overridden!");
295 mfem_error(
"TimeDependentOperator::Mult() is not overridden!");
301 mfem_error(
"TimeDependentOperator::ImplicitSolve() is not overridden!");
307 mfem_error(
"TimeDependentOperator::GetImplicitGradient() is "
314 mfem_error(
"TimeDependentOperator::GetExplicitGradient() is "
323 mfem_error(
"TimeDependentOperator::SUNImplicitSetup() is not overridden!");
329 mfem_error(
"TimeDependentOperator::SUNImplicitSolve() is not overridden!");
335 mfem_error(
"TimeDependentOperator::SUNMassSetup() is not overridden!");
341 mfem_error(
"TimeDependentOperator::SUNMassSolve() is not overridden!");
347 mfem_error(
"TimeDependentOperator::SUNMassMult() is not overridden!");
356 mfem_error(
"SecondOrderTimeDependentOperator::Mult() is not overridden!");
365 mfem_error(
"SecondOrderTimeDependentOperator::ImplicitSolve() is not overridden!");
370 bool ownA,
bool ownB)
371 :
Operator(A->Height(), A->Width()),
376 "incompatible Operators: different widths\n"
377 <<
"A->Width() = " << A->
Width()
378 <<
", B->Width() = " << B->
Width() );
380 "incompatible Operators: different heights\n"
381 <<
"A->Height() = " << A->
Height()
382 <<
", B->Height() = " << B->
Height() );
390 "Operator A of a SumOperator should not be in iterative mode");
395 "Operator B of a SumOperator should not be in iterative mode");
403 if (ownA) {
delete A; }
404 if (ownB) {
delete B; }
408 bool ownA,
bool ownB)
409 :
Operator(A->Height(), B->Width()),
410 A(A), B(B), ownA(ownA), ownB(ownB), z(A->Width())
413 "incompatible Operators: A->Width() = " << A->
Width()
414 <<
", B->Height() = " << B->
Height());
421 "Operator B of a ProductOperator should not be in iterative mode");
428 if (ownA) {
delete A; }
429 if (ownB) {
delete B; }
435 :
Operator(Rt_.Width(), P_.Width()), Rt(Rt_), A(A_), P(P_)
438 "incompatible Operators: Rt.Height() = " << Rt.
Height()
439 <<
", A.Height() = " << A.
Height());
441 "incompatible Operators: A.Width() = " << A.
Width()
442 <<
", P.Height() = " << P.
Height());
445 const Solver* SolverA =
dynamic_cast<const Solver*
>(&A);
449 "Operator A of an RAPOperator should not be in iterative mode");
452 const Solver* SolverP =
dynamic_cast<const Solver*
>(&P);
456 "Operator P of an RAPOperator should not be in iterative mode");
469 bool ownA,
bool ownB,
bool ownC)
472 , ownA(ownA), ownB(ownB), ownC(ownC)
475 "incompatible Operators: A->Width() = " << A->
Width()
476 <<
", B->Height() = " << B->
Height());
478 "incompatible Operators: B->Width() = " << B->
Width()
479 <<
", C->Height() = " << C->
Height());
486 "Operator B of a TripleProductOperator should not be in iterative mode");
493 "Operator C of a TripleProductOperator should not be in iterative mode");
505 if (ownA) {
delete A; }
506 if (ownB) {
delete B; }
507 if (ownC) {
delete C; }
514 :
Operator(A->Height(), A->Width()), A(A), own_A(own_A_),
515 diag_policy(diag_policy_)
542 const int id = idx[i];
549 const int id = idx[i];
554 MFEM_ABORT(
"unknown diagonal policy");
569 const int id = idx[i];
581 const int id = idx[i];
587 const bool transpose)
const
608 mfem::forall(csz, [=] MFEM_HOST_DEVICE (
int i) { d_z[idx[i]] = 0.0; });
627 const int id = idx[i];
634 const int id = idx[i];
650 constexpr bool transpose =
false;
656 constexpr bool transpose =
true;
672 :
Operator(A->Height(), A->Width()), A(A), own_A(own_A_)
697 const int id = trial_idx[i];
705 auto d_b =
b.ReadWrite();
708 d_b[test_idx[i]] = 0.0;
782 int numSteps,
real_t tolerance,
int seed)
792 for (
int iter = 0; iter < numSteps; ++iter)
797 if (comm != MPI_COMM_NULL)
814 if (comm != MPI_COMM_NULL)
825 real_t diff = std::abs((eigenvalueNew - eigenvalue) / eigenvalue);
827 eigenvalue = eigenvalueNew;
830 if (diff < tolerance)
int Size() const
Return the logical size of the array.
void MakeRef(T *data_, int size_, bool own_data=false)
Make this Array a reference to a pointer.
const T * Read(bool on_dev=true) const
Shortcut for mfem::Read(a.GetMemory(), a.Size(), on_dev).
Square Operator for imposing essential boundary conditions using only the action, Mult(),...
Array< int > constraint_list
List of constrained indices/dofs.
void Mult(const Vector &x, Vector &y) const override
Constrained operator action.
Operator * A
The unconstrained Operator.
void EliminateRHS(const Vector &x, Vector &b) const
Eliminate "essential boundary condition" values specified in x from the given right-hand side b.
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.
void AddMult(const Vector &x, Vector &y, const real_t a=1.0) const override
Operator application: y+=A(x) (default) or y+=a*A(x).
void AssembleDiagonal(Vector &diag) const override
Diagonal of A, modified according to the used DiagonalPolicy.
DiagonalPolicy diag_policy
Diagonal policy for constrained dofs.
void ConstrainedMult(const Vector &x, Vector &y, const bool transpose) const
Implementation of Mult or MultTranspose. TODO - Generalize to allow constraining rows and columns dif...
Vector w
Auxiliary vectors.
void MultTranspose(const Vector &x, Vector &y) const override
Action of the transpose operator: y=A^t(x). The default behavior in class Operator is to generate an ...
static MemoryClass GetMemoryClass()
(DEPRECATED) Equivalent to GetDeviceMemoryClass().
static MemoryClass GetDeviceMemoryClass()
Get the current Device MemoryClass. This is the MemoryClass used by most MFEM device kernels to acces...
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.
virtual MemoryClass GetMemoryClass() const
Return the MemoryClass preferred by the Operator.
void FormConstrainedSystemOperator(const Array< int > &ess_tdof_list, ConstrainedOperator *&Aout)
see FormSystemOperator()
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.
int width
Dimension of the input / number of columns in the matrix.
void FormSystemOperator(const Array< int > &ess_tdof_list, Operator *&A)
Return in A a parallel (on truedofs) version of this square operator.
void FormDiscreteOperator(Operator *&A)
Return in A a parallel (on truedofs) version of this rectangular operator.
virtual void ArrayMultTranspose(const Array< const Vector * > &X, Array< Vector * > &Y) const
Action of the transpose operator on a matrix: Y=A^t(X).
int Height() const
Get the height (size of output) of the Operator. Synonym with NumRows().
int height
Dimension of the output / number of rows in the matrix.
virtual void ArrayAddMult(const Array< const Vector * > &X, Array< Vector * > &Y, const real_t a=1.0) const
Operator application on a matrix: Y+=A(X) (default) or Y+=a*A(X).
virtual const Operator * GetRestriction() const
Restriction operator from input vectors for the operator to linear algebra (linear system) vectors....
virtual void Mult(const Vector &x, Vector &y) const =0
Operator application: y=A(x).
DiagonalPolicy
Defines operator diagonal policy upon elimination of rows and/or columns.
@ DIAG_ONE
Set the diagonal value to one.
@ DIAG_KEEP
Keep the diagonal value.
@ DIAG_ZERO
Set the diagonal value to zero.
virtual const Operator * GetOutputRestriction() const
Restriction operator from output vectors for the operator to linear algebra (linear system) vectors....
int Width() const
Get the width (size of input) of the Operator. Synonym with NumCols().
virtual const Operator * GetOutputProlongation() const
Prolongation operator from linear algebra (linear system) vectors, to output vectors for the operator...
virtual void ArrayAddMultTranspose(const Array< const Vector * > &X, Array< Vector * > &Y, const real_t a=1.0) const
Operator transpose application on a matrix: Y+=A^t(X) (default) or Y+=a*A^t(X).
virtual void ArrayMult(const Array< const Vector * > &X, Array< Vector * > &Y) const
Operator application on a matrix: Y=A(X).
virtual const Operator * GetProlongation() const
Prolongation operator from linear algebra (linear system) vectors, to input vectors for the operator....
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).
Operator * SetupRAP(const Operator *Pi, const Operator *Po)
Returns RAP Operator of this, using input/output Prolongation matrices Pi corresponds to "P",...
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...
virtual void AssembleDiagonal(Vector &diag) const
Computes the diagonal entries into diag. Typically, this operation only makes sense for linear Operat...
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.
virtual void AddMultTranspose(const Vector &x, Vector &y, const real_t a=1.0) const
Operator transpose application: y+=A^t(x) (default) or y+=a*A^t(x).
void FormRectangularConstrainedSystemOperator(const Array< int > &trial_tdof_list, const Array< int > &test_tdof_list, RectangularConstrainedOperator *&Aout)
see FormRectangularSystemOperator()
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 ...
void PrintMatlab(std::ostream &out, int n, int m=0) const
Prints operator with input size n and output size m in Matlab format.
virtual void AddMult(const Vector &x, Vector &y, const real_t a=1.0) const
Operator application: y+=A(x) (default) or y+=a*A(x).
real_t EstimateLargestEigenvalue(Operator &opr, Vector &v0, int numSteps=10, real_t tolerance=1e-8, int seed=12345)
Returns an estimate of the largest eigenvalue of the operator opr using the iterative power method.
General product operator: x -> (A*B)(x) = A(B(x)).
ProductOperator(const Operator *A, const Operator *B, bool ownA, bool ownB)
virtual ~ProductOperator()
The operator x -> R*A*P*x constructed through the actions of R^T, A and P.
RAPOperator(const Operator &Rt_, const Operator &A_, const Operator &P_)
Construct the RAP operator given R^T, A and P.
Rectangular Operator for imposing essential boundary conditions on the input space using only the act...
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.
Array< int > test_constraints
Array< int > trial_constraints
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 ...
virtual void Mult(const Vector &x, Vector &y) const
Rectangular-constrained operator action.
void EliminateRHS(const Vector &x, Vector &b) const
Eliminate columns corresponding to "essential boundary condition" values specified in x from the give...
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...
virtual void ImplicitSolve(const real_t fac0, const real_t 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.
bool iterative_mode
If true, use the second argument of Mult() as an initial guess.
SumOperator(const Operator *A, const real_t alpha, const Operator *B, const real_t beta, bool ownA, bool ownB)
virtual Operator & GetExplicitGradient(const Vector &x) const
Return an Operator representing dG/dx at the given point x and the currently set time.
virtual int SUNImplicitSolve(const Vector &b, Vector &x, real_t tol)
Solve the ODE linear system as setup by the method SUNImplicitSetup().
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...
virtual int SUNMassMult(const Vector &x, Vector &v)
Compute the mass matrix-vector product .
virtual int SUNMassSetup()
Setup the mass matrix in the ODE system .
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,...
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.
virtual int SUNMassSolve(const Vector &b, Vector &x, real_t tol)
Solve the mass matrix linear system as setup by the method SUNMassSetup().
virtual void ImplicitSolve(const real_t dt, const Vector &x, Vector &k)
Solve the equation: k = f(x + dt k, t), for the unknown k at the current time t.
virtual int SUNImplicitSetup(const Vector &x, const Vector &fx, int jok, int *jcur, real_t gamma)
Setup the ODE linear system or , where .
virtual Operator & GetImplicitGradient(const Vector &x, const Vector &k, real_t shift) const
Return an Operator representing (dF/dk shift + dF/dx) at the given x, k, and the currently set time.
The transpose of a given operator. Switches the roles of the methods Mult() and MultTranspose().
General triple product operator x -> A*B*C*x, with ownership of the factors.
TripleProductOperator(const Operator *A, const Operator *B, const Operator *C, bool ownA, bool ownB, bool ownC)
virtual ~TripleProductOperator()
void Randomize(int seed=0)
Set random values in the vector.
virtual const real_t * Read(bool on_dev=true) const
Shortcut for mfem::Read(vec.GetMemory(), vec.Size(), on_dev).
virtual real_t * ReadWrite(bool on_dev=true)
Shortcut for mfem::ReadWrite(vec.GetMemory(), vec.Size(), on_dev).
void SyncMemory(const Vector &v) const
Update the memory location of the vector to match v.
int Size() const
Returns the size of the vector.
virtual void UseDevice(bool use_dev) const
Enable execution of Vector operations using the mfem::Device.
void SetSize(int s)
Resize the vector to size s.
void SetSubVectorComplement(const Array< int > &dofs, const real_t val)
Set all vector entries NOT in the dofs Array to the given val.
Vector & Add(const real_t a, const Vector &Va)
(*this) += a * Va
void MakeRef(Vector &base, int offset, int size)
Reset the Vector to be a reference to a sub-vector of base.
void mfem_error(const char *msg)
real_t InnerProduct(HypreParVector *x, HypreParVector *y)
MemoryType GetMemoryType(MemoryClass mc)
Return a suitable MemoryType for a given MemoryClass.
bool IsIdentityProlongation(const Operator *P)
MemoryType
Memory types supported by MFEM.
void forall(int N, lambda &&body)