WarpX
Loading...
Searching...
No Matches
LinearFunction.H
Go to the documentation of this file.
1/* Copyright 2025 Debojyoti Ghosh
2 *
3 * This file is part of WarpX.
4 *
5 * License: BSD-3-Clause-LBNL
6 */
7#ifndef LinearFunction_H_
8#define LinearFunction_H_
9
10#include "Preconditioner.H"
11
12#include <string>
13
18
19template <class T, class Ops>
21{
22 public:
23
24 using RT = typename T::value_type;
25
27 LinearFunction() = default;
29 virtual ~LinearFunction() = default;
30
31 // Default move and copy operations
32 LinearFunction(const LinearFunction&) = default;
34 LinearFunction(LinearFunction&&) noexcept = default;
35 LinearFunction& operator=(LinearFunction&&) noexcept = default;
36
38 virtual void apply ( T& a_dF, const T& a_dU ) = 0;
39
41 virtual void precond ( T& a_U, const T& a_X ) = 0;
42
44 virtual void updatePreCondMat ( const T& a_X ) = 0;
45
47 inline void create ( T& a_Z, const T& a_U )
48 {
49 a_Z.define(a_U);
50 }
51
53 virtual T makeVecLHS () const = 0;
54
56 virtual T makeVecRHS () const = 0;
57
59 inline void assign( T& a_Z, const T& a_U ) {
60 a_Z.Copy(a_U);
61 }
62
64 inline void increment( T& a_Z, const T& a_U, RT a_scale )
65 {
66 a_Z.increment(a_U,a_scale);
67 }
68
70 inline void scale ( T& a_U, RT a_scale )
71 {
72 a_U.scale(a_scale);
73 }
74
76 inline void linComb ( T& a_U, RT a, const T& X, RT b, const T& Y )
77 {
78 a_U.linComb( a, X, b, Y );
79 }
80
82 inline void setToZero ( T& a_U )
83 {
84 a_U.zero();
85 }
86
88 inline void setVal ( T& a_U, RT a_val )
89 {
90 a_U.setVal(a_val);
91 }
92
94 inline RT dotProduct( const T& a_X, const T& a_Y )
95 {
96 return( a_X.dotProduct(a_Y) );
97 }
98
100 inline RT norm2( const T& a_U )
101 {
102 return ( a_U.norm2() );
103 }
104
106 virtual void define( const T&, Ops*, const PreconditionerType& ) = 0;
107
109 virtual PreconditionerType pcType () const = 0;
110
111 protected:
112
113 private:
114
115};
116
117#endif
PreconditionerType
Types for preconditioners for field solvers.
Definition Preconditioner.H:20
virtual ~LinearFunction()=default
default destructore
typename T::value_type RT
Definition LinearFunction.H:24
virtual T makeVecRHS() const =0
make RHS vector
void setToZero(T &a_U)
set vector to zero
Definition LinearFunction.H:82
void assign(T &a_Z, const T &a_U)
vector copy operation
Definition LinearFunction.H:59
void create(T &a_Z, const T &a_U)
create a new vector given a defined vector
Definition LinearFunction.H:47
virtual T makeVecLHS() const =0
make LHS vector
virtual void apply(T &a_dF, const T &a_dU)=0
apply the linear function on a given vector of type T
LinearFunction(const LinearFunction &)=default
LinearFunction(LinearFunction &&) noexcept=default
void increment(T &a_Z, const T &a_U, RT a_scale)
vector scaled-increment operation
Definition LinearFunction.H:64
RT dotProduct(const T &a_X, const T &a_Y)
compute dot product of two vectors
Definition LinearFunction.H:94
virtual void precond(T &a_U, const T &a_X)=0
apply the preconditioner on a given vector of type T
RT norm2(const T &a_U)
compute 2-norm of a vector
Definition LinearFunction.H:100
virtual void updatePreCondMat(const T &a_X)=0
update preconditioner
LinearFunction()=default
default constructor
virtual PreconditionerType pcType() const =0
returns the preconditioner type
void scale(T &a_U, RT a_scale)
vector scaled operation
Definition LinearFunction.H:70
virtual void define(const T &, Ops *, const PreconditionerType &)=0
define the linear function object
void linComb(T &a_U, RT a, const T &X, RT b, const T &Y)
compute linear combination
Definition LinearFunction.H:76
LinearFunction & operator=(const LinearFunction &)=default
void setVal(T &a_U, RT a_val)
set vector to a scalar value
Definition LinearFunction.H:88