22 :
Vector(2*(
f->GetVSize())), fes(
f), fec_owned(NULL)
37 :
Vector(), fes(NULL), fec_owned(NULL)
47 if (buff !=
"ComplexGridFunction")
49 MFEM_ABORT(
"unrecognized file header: " << buff);
56 istream::int_type next_char = input.peek();
61 if (buff ==
"NURBS_patches")
63 MFEM_ABORT(
"NURBS not yet supported with ComplexGridFunction objects");
67 MFEM_ABORT(
"unknown section: " << buff);
79 MFEM_ABORT(
"LegacyNCReorder not supported for "
80 "ComplexGridFunction objects");
95 delete gfr;
delete gfi;
143 gfi->
MakeRef(*
this, vsize, vsize);
155 gfi->
MakeRef(*
this, vsize, vsize);
257 for (
int i = 0; i <
fes->
GetNE(); i++)
259 if (elems != NULL && (*elems)[i] == 0) {
continue; }
268 int intorder = 2*fe->
GetOrder() + 3;
279 real_t diffr = valsr(j) - exsolr.
Eval(*T, ip);
280 real_t diffi = valsi(j) - exsoli.
Eval(*T, ip);
281 real_t diff = hypot(diffr, diffi);
287 diff *=
weight->Eval(*T, ip);
295 diff *=
weight->Eval(*T, ip);
297 error = std::max(error, diff);
303 error += fabs(elem_error);
309 error = pow(error, 1./
p);
317 os <<
"ComplexGridFunction\n";
334 ofs.precision(precision);
347 :
Vector(2*(fes->GetVSize())),
363 :
Vector(2*(fes->GetVSize())),
474bool SesquilinearForm::RealInteg()
481bool SesquilinearForm::ImagInteg()
505 diag_policy = dpolicy;
611 ComplexOperator * A_op =
612 new ComplexOperator(A_r.
Ptr(),
617 A.
Reset<ComplexOperator>(A_op,
true);
640 MFEM_ASSERT(x.
Size() == 2 * vsize,
"Input GridFunction of incorrect size!");
645 MFEM_ASSERT(
b.Size() == 2 * vsize,
"Input LinearForm of incorrect size!");
676 X_r = X_0; B_r = B_0;
680 X_i = X_0; B_i = B_0;
695 else if (ImagInteg())
701 X_r = X_0; B_i = B_0;
703 b_0 = b_r; b_0 *= -1.0;
705 X_i = X_0; B_r = B_0; B_r *= -1.0;
709 MFEM_ABORT(
"Real and Imaginary part of the Sesquilinear form are empty");
712 if (RealInteg() && ImagInteg())
719 auto d_B_r = B_r.
Write();
720 auto d_B_i = B_i.
Write();
721 auto d_X_r = X_r.
Read();
722 auto d_X_i = X_i.
Read();
726 const int j = d_idx[i];
751 BuildComplexOperator(A_r, A_i, A);
772 if (!RealInteg() && !ImagInteg())
774 MFEM_ABORT(
"Both Real and Imaginary part of the Sesquilinear form are empty");
777 if (RealInteg() && ImagInteg())
788 BuildComplexOperator(A_r, A_i, A);
805 const int tvsize = X.
Size() / 2;
826 if ( blfr ) { blfr->
Update(nfes); }
827 if ( blfi ) { blfi->
Update(nfes); }
831MixedSesquilinearForm::RealInteg()
840MixedSesquilinearForm::ImagInteg()
1037 &mblfr->
SpMat(), &mblfi->
SpMat(),
false,
false, conv);
1042 ess_trial_tdof_list,
1052 const int vsize_trial = fes_trial->
GetVSize();
1053 const int vsize_test = fes_test->
GetVSize();
1062 MFEM_ASSERT(x.
Size() == 2 * vsize_trial,
1063 "Input GridFunction of incorrect size!");
1066 x_r.
MakeRef(x, 0, vsize_trial);
1068 x_i.
MakeRef(x, vsize_trial, vsize_trial);
1070 MFEM_ASSERT(
b.Size() == 2 * vsize_test,
"Input LinearForm of incorrect size!");
1075 b_i.
MakeRef(
b, vsize_test, vsize_test);
1095 X_r.
MakeRef(X, 0, tvsize_trial);
1097 X_i.
MakeRef(X, tvsize_trial, tvsize_trial);
1099 B_r.
MakeRef(B, 0, tvsize_test);
1101 B_i.
MakeRef(B, tvsize_test, tvsize_test);
1109 ess_trial_tdof_list, ess_test_tdof_list, x_r, b_0, A_r, X_0, B_0);
1115 ess_trial_tdof_list, ess_test_tdof_list, x_i, b_0, A_r, X_0, B_0);
1123 ess_trial_tdof_list, ess_test_tdof_list, x_i, b_0, A_i, X_0, B_0);
1128 ess_trial_tdof_list, ess_test_tdof_list, x_r, b_0, A_i, X_0, B_0);
1132 else if (ImagInteg())
1136 ess_trial_tdof_list, ess_test_tdof_list, x_r, b_0, A_i, X_0, B_0);
1143 ess_trial_tdof_list, ess_test_tdof_list, x_i, b_0, A_i, X_0, B_0);
1150 MFEM_ABORT(
"Real and Imaginary part of the Mixed Sesquilinear form are empty");
1197 ess_trial_tdof_list,
1212 if (!RealInteg() && !ImagInteg())
1214 MFEM_ABORT(
"Both Real and Imaginary part of the Mixed Sesquilinear form are empty");
1254 :
Vector(2*(pf->GetVSize())), pfes(pf), fec_owned(NULL)
1269 :
Vector(), pfes(NULL), fec_owned(NULL)
1277 getline(input, buff);
1279 if (buff !=
"ParComplexGridFunction")
1281 MFEM_ABORT(
"unrecognized file header: " << buff);
1293 istream::int_type next_char = input.peek();
1294 if (next_char ==
'N')
1296 getline(input, buff);
1298 if (buff ==
"NURBS_patches")
1300 MFEM_ABORT(
"NURBS not yet supported with ComplexGridFunction objects");
1304 MFEM_ABORT(
"unknown section: " << buff);
1322 MFEM_ABORT(
"LegacyNCReorder not supported for "
1323 "ComplexGridFunction objects");
1338 delete pgfr;
delete pgfi;
1383 pgfr->
MakeRef(*
this, 0, vsize);
1384 pgfi->
MakeRef(*
this, vsize, vsize);
1395 pgfr->
MakeRef(*
this, 0, vsize);
1396 pgfi->
MakeRef(*
this, vsize, vsize);
1522 os <<
"ParComplexGridFunction\n";
1554 ostringstream fname_with_suffix;
1555 fname_with_suffix << fname <<
"." << setfill(
'0') << setw(6) << rank;
1556 ofstream ofs(fname_with_suffix.str().c_str());
1557 ofs.precision(precision);
1571 :
Vector(2*(pfes->GetVSize())),
1585 int n = (HYPRE_AssumedPartitionCheck()) ? 2 : pfes->
GetNRanks();
1588 for (
int i = 0; i <= n; i++)
1600 :
Vector(2*(pfes->GetVSize())),
1614 int n = (HYPRE_AssumedPartitionCheck()) ? 2 : pfes->
GetNRanks();
1617 for (
int i = 0; i <= n; i++)
1764bool ParSesquilinearForm::RealInteg()
1771bool ParSesquilinearForm::ImagInteg()
1900 ComplexOperator * A_op =
1901 new ComplexOperator(A_r.
As<Operator>(),
1906 A.
Reset<ComplexOperator>(A_op,
true);
1914struct ZeroDiagonalHypreKernel
1920 void MFEM_HOST_DEVICE operator()(
int k)
const
1929ParSesquilinearForm::SetImaginaryEssentialDiagonalToZero(
1937 hypre_ParCSRMatrix *Aih = *Ah;
1938 Ah->HypreReadWrite();
1939 const int *d_ess_tdof_list =
1941 HYPRE_Int *d_diag_i = Aih->diag->i;
1942 real_t *d_diag_data = Aih->diag->data;
1945 d_ess_tdof_list, d_diag_i, d_diag_data
1950 A.As<ConstrainedOperator>()->SetDiagonalPolicy
1963 const int vsize = pfes->
GetVSize();
1972 MFEM_ASSERT(x.
Size() == 2 * vsize,
"Input GridFunction of incorrect size!");
1977 MFEM_ASSERT(
b.Size() == 2 * vsize,
"Input LinearForm of incorrect size!");
2006 X_r = X_0; B_r = B_0;
2010 X_i = X_0; B_i = B_0;
2023 else if (ImagInteg())
2027 X_r = X_0; B_i = B_0;
2029 b_0 = b_r; b_0 *= -1.0;
2031 X_i = X_0; B_r = B_0; B_r *= -1.0;
2035 MFEM_ABORT(
"Real and Imaginary part of the Sesquilinear form are empty");
2038 if (RealInteg() && ImagInteg())
2042 auto d_B_r = B_r.
Write();
2043 auto d_B_i = B_i.
Write();
2044 auto d_X_r = X_r.
Read();
2045 auto d_X_i = X_i.
Read();
2049 const int j = d_idx[i];
2050 d_B_r[j] = d_X_r[j];
2051 d_B_i[j] = d_X_i[j];
2074 BuildComplexOperator(A_r, A_i, A);
2090 if (!RealInteg() && !ImagInteg())
2092 MFEM_ABORT(
"Both Real and Imaginary part of the Sesquilinear form are empty");
2095 if (RealInteg() && ImagInteg())
2102 BuildComplexOperator(A_r, A_i, A);
2113 const int vsize = pfes->
GetVSize();
2114 const int tvsize = X.
Size() / 2;
2135 if ( pblfr ) { pblfr->
Update(nfes); }
2136 if ( pblfi ) { pblfi->
Update(nfes); }
2140ParMixedSesquilinearForm::RealInteg()
2142 int nint = pmblfr->
GetDBFI()->Size() + pmblfr->
GetBBFI()->Size() +
2149ParMixedSesquilinearForm::ImagInteg()
2151 int nint = pmblfi->
GetDBFI()->Size() + pmblfi->
GetBBFI()->Size() +
2357 ess_trial_tdof_list,
2367 const int vsize_trial = pfes_trial->
GetVSize();
2368 const int vsize_test = pfes_test->
GetVSize();
2377 MFEM_ASSERT(x.
Size() == 2 * vsize_trial,
2378 "Input GridFunction of incorrect size!");
2381 x_r.
MakeRef(x, 0, vsize_trial);
2383 x_i.
MakeRef(x, vsize_trial, vsize_trial);
2385 MFEM_ASSERT(
b.Size() == 2 * vsize_test,
"Input LinearForm of incorrect size!");
2390 b_i.
MakeRef(
b, vsize_test, vsize_test);
2410 X_r.
MakeRef(X, 0, tvsize_trial);
2412 X_i.
MakeRef(X, tvsize_trial, tvsize_trial);
2414 B_r.
MakeRef(B, 0, tvsize_test);
2416 B_i.
MakeRef(B, tvsize_test, tvsize_test);
2424 ess_trial_tdof_list, ess_test_tdof_list, x_r, b_0, A_r, X_0, B_0);
2430 ess_trial_tdof_list, ess_test_tdof_list, x_i, b_0, A_r, X_0, B_0);
2438 ess_trial_tdof_list, ess_test_tdof_list, x_i, b_0, A_i, X_0, B_0);
2443 ess_trial_tdof_list, ess_test_tdof_list, x_r, b_0, A_i, X_0, B_0);
2447 else if (ImagInteg())
2451 ess_trial_tdof_list, ess_test_tdof_list, x_r, b_0, A_i, X_0, B_0);
2458 ess_trial_tdof_list, ess_test_tdof_list, x_i, b_0, A_i, X_0, B_0);
2465 MFEM_ABORT(
"Real and Imaginary part of the Mixed Sesquilinear form are empty");
2512 ess_trial_tdof_list,
2527 if (!RealInteg() && !ImagInteg())
2529 MFEM_ABORT(
"Both Real and Imaginary part of the Mixed Sesquilinear form are empty");
Base class Coefficients that optionally depend on space and time. These are used by the BilinearFormI...
virtual real_t Eval(ElementTransformation &T, const IntegrationPoint &ip)=0
Evaluate the coefficient in the element described by T at the point ip.
virtual void ProjectBdrCoefficientTangent(VectorCoefficient &real_coeff, VectorCoefficient &imag_coeff, Array< int > &attr)
virtual void ProjectBdrCoefficient(Coefficient &real_coeff, Coefficient &imag_coeff, Array< int > &attr)
virtual void ProjectCoefficient(Coefficient &real_coeff, Coefficient &imag_coeff)
FiniteElementCollection * fec_owned
Used when the grid function is read from a file. It can also be set explicitly, see MakeOwner().
virtual real_t ComputeLpError(const real_t p, Coefficient &exsolr, Coefficient &exsoli, Coefficient *weight=NULL, const IntegrationRule *irs[]=NULL, const Array< int > *elems=NULL) const
Returns ||u_ex - u_h||_Lp for complex-valued H1 or L2 elements.
virtual void ProjectBdrCoefficientNormal(VectorCoefficient &real_coeff, VectorCoefficient &imag_coeff, Array< int > &attr)
ComplexGridFunction(FiniteElementSpace *f)
Construct a ComplexGridFunction associated with the FiniteElementSpace *f.
virtual void Save(std::ostream &out) const
Save the ComplexGridFunction to an output stream.
Specialization of the ComplexOperator built from a pair of HypreParMatrices.
Mimic the action of a complex operator using two real operators.
@ HERMITIAN
Native convention for Hermitian operators.
@ BLOCK_SYMMETRIC
Alternate convention for damping operators.
Specialization of the ComplexOperator built from a pair of Sparse Matrices.
Square Operator for imposing essential boundary conditions using only the action, Mult(),...
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
void Save(std::ostream &out) const
Save finite element space to output stream out.
virtual int GetTrueVSize() const
Return the number of vector true (conforming) dofs.
ElementTransformation * GetElementTransformation(int i) const
bool Nonconforming() const
FiniteElementCollection * Load(Mesh *m, std::istream &input)
Read a FiniteElementSpace from a stream. The returned FiniteElementCollection is owned by the caller.
virtual const FiniteElement * GetFE(int i) const
Returns pointer to the FiniteElement in the FiniteElementCollection associated with i'th element in t...
Ordering::Type GetOrdering() const
Return the ordering method.
int GetNE() const
Returns number of elements in the mesh.
const SparseMatrix * GetConformingProlongation() const
Mesh * GetMesh() const
Returns the mesh.
int GetVSize() const
Return the number of vector dofs, i.e. GetNDofs() x GetVDim().
int GetVDim() const
Returns the vector dimension of the finite element space.
const FiniteElement * GetTypicalFE() const
Return GetFE(0) if the local mesh is not empty; otherwise return a typical FE based on the Geometry t...
const Operator * GetUpdateOperator()
Get the GridFunction update operator.
Abstract class for all finite elements.
int GetRangeDim() const
Returns the vector dimension for vector-valued finite elements, which is also the dimension of the in...
int GetOrder() const
Returns the order of the finite element. In the case of anisotropic orders, returns the maximum order...
int GetRangeType() const
Returns the FiniteElement::RangeType of the element, one of {SCALAR, VECTOR}.
Geometry::Type GetGeomType() const
Returns the Geometry::Type of the reference element.
Class for grid function - Vector with associated FE space.
void GetValues(int i, const IntegrationRule &ir, Vector &vals, int vdim=1) const
virtual void Update()
Transform by the Space UpdateMatrix (e.g., on Mesh change).
virtual void MakeRef(FiniteElementSpace *f, real_t *v)
Make the GridFunction reference external data on a new FiniteElementSpace.
virtual void ProjectBdrCoefficientTangent(VectorCoefficient &vcoeff, const Array< int > &bdr_attr)
Project the tangential components of the given VectorCoefficient on the boundary.
void ProjectBdrCoefficientNormal(Coefficient *coeff, VectorCoefficient *vcoeff, const Array< int > &attr)
virtual void ProjectCoefficient(Coefficient &coeff, ProjectType type=ProjectType::DEFAULT)
Project coeff Coefficient to this GridFunction. The projection computation depends on the choice of t...
void ProjectBdrCoefficient(Coefficient &coeff, const Array< int > &attr)
Project a Coefficient on the GridFunction, modifying only DOFs on the boundary associated with the bo...
Wrapper for hypre's ParCSR matrix class.
Wrapper for hypre's parallel vector class.
Class for integration point with weight.
Class for an integration rule - an Array of IntegrationPoint.
int GetNPoints() const
Returns the number of the points in the integration rule.
IntegrationPoint & IntPoint(int i)
Returns a reference to the i-th integration point.
const IntegrationRule & Get(int GeomType, int Order)
Returns an integration rule for given GeomType and Order.
int SpaceDimension() const
Dimension of the physical space containing the mesh.
NCMesh * ncmesh
Optional nonconforming mesh extension.
bool IsLegacyLoaded() const
I/O: Return true if the mesh was loaded from the legacy v1.1 format.
Pointer to an Operator of a specified type.
OpType * As() const
Return the Operator pointer statically cast to a specified OpType. Similar to the method Get().
bool OwnsOperator() const
Return true if the OperatorHandle owns the held Operator.
void SetOperatorOwner(bool own=true)
Set the ownership flag for the held Operator.
Operator * Ptr() const
Access the underlying Operator pointer.
void Clear()
Clear the OperatorHandle, deleting the held Operator (if owned), while leaving the type id unchanged.
void Reset(OpType *A, bool own_A=true)
Reset the OperatorHandle to the given OpType pointer, A.
OpType * Is() const
Return the Operator pointer dynamically cast to a specified OpType.
Operator::Type Type() const
Get the currently set operator type id.
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_ZERO
Set the diagonal value to zero.
@ MFEM_SPARSEMAT
ID for class SparseMatrix.
@ Hypre_ParCSR
ID for class HypreParMatrix.
virtual void ProjectBdrCoefficient(Coefficient &real_coeff, Coefficient &imag_coeff, Array< int > &attr)
FiniteElementCollection * fec_owned
Used when the grid function is read from a file. It can also be set explicitly, see MakeOwner().
void ParallelProject(Vector &tv) const
Returns the vector restricted to the true dofs.
ParComplexGridFunction(ParFiniteElementSpace *pf)
Construct a ParComplexGridFunction associated with the ParFiniteElementSpace *pf.
virtual void ProjectBdrCoefficientNormal(VectorCoefficient &real_coeff, VectorCoefficient &imag_coeff, Array< int > &attr)
ParFiniteElementSpace * pfes
void Distribute(const Vector *tv)
virtual void ProjectBdrCoefficientTangent(VectorCoefficient &real_coeff, VectorCoefficient &imag_coeff, Array< int > &attr)
virtual void ProjectCoefficient(Coefficient &real_coeff, Coefficient &imag_coeff)
void Save(std::ostream &out) const
Save the local portion of the ParComplexGridFunction.
Abstract parallel finite element space.
HYPRE_BigInt * GetTrueDofOffsets() const
HYPRE_BigInt GlobalTrueVSize() const
int GetTrueVSize() const override
Return the number of local vector true dofs.
bool Nonconforming() const
const Operator * GetProlongationMatrix() const override
void ApplyDofSigns(real_t *h_data) const
Apply the DOF signs to the given host data h_data which must be of size GetVSize() if HaveDofSigns() ...
Class for parallel grid function.
void ProjectCoefficient(Coefficient &coeff, ProjectType type=ProjectType::DEFAULT) override
Project coeff Coefficient to this GridFunction. The projection computation depends on the choice of t...
void ProjectBdrCoefficient(Coefficient *coeff[], VectorCoefficient *vcoeff, const Array< int > &attr)
void MakeRef(FiniteElementSpace *f, real_t *v) override
Make the ParGridFunction reference external data on a new FiniteElementSpace.
void ParallelProject(Vector &tv) const
Returns the vector restricted to the true dofs.
void Update() override
Transform by the Space UpdateMatrix (e.g., on Mesh change).
void Distribute(const Vector *tv)
void ProjectBdrCoefficientTangent(VectorCoefficient &vcoeff, const Array< int > &bdr_attr) override
Project the tangential components of the given VectorCoefficient on the boundary.
Class for parallel meshes.
void Mult(const Vector &x, Vector &y) const override
Matrix vector multiplication.
Base class for vector Coefficients that optionally depend on time and space.
virtual const real_t * HostRead() const
Shortcut for mfem::Read(vec.GetMemory(), vec.Size(), false).
virtual const real_t * Read(bool on_dev=true) const
Shortcut for mfem::Read(vec.GetMemory(), vec.Size(), on_dev).
void Print(std::ostream &out=mfem::out, int width=8) const
Prints vector to stream out.
void SyncAliasMemory(const Vector &v) const
Update the alias memory location of the vector to match v.
void SyncMemory(const Vector &v) const
Update the memory location of the vector to match v.
void Load(std::istream **in, int np, int *dim)
Reads a vector from multiple files.
virtual bool UseDevice() const
Return the device flag of the Memory object used by the Vector.
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.
Vector & operator=(const real_t *v)
Copy Size() entries from v.
virtual real_t * HostReadWrite()
Shortcut for mfem::ReadWrite(vec.GetMemory(), vec.Size(), false).
virtual real_t * Write(bool on_dev=true)
Shortcut for mfem::Write(vec.GetMemory(), vec.Size(), on_dev).
void MakeRef(Vector &base, int offset, int size)
Reset the Vector to be a reference to a sub-vector of base.
const int * ess_tdof_list
real_t weight(const Vector &x)
std::ostream & operator<<(std::ostream &os, SparseMatrix const &mat)
MemoryClass GetHypreForallMemoryClass()
void filter_dos(std::string &line)
Check for, and remove, a trailing '\r' from and std::string.
void hypre_forall(int N, lambda &&body)
std::function< real_t(const Vector &)> f(real_t mass_coeff)
void forall(int N, lambda &&body)
void skip_comment_lines(std::istream &is, const char comment_char)
Check if the stream starts with comment_char. If so skip it.
constexpr real_t infinity()
Define a shortcut for std::numeric_limits<double>::infinity()
IntegrationRules IntRules(0, Quadrature1D::GaussLegendre)
A global object with all integration rules (defined in intrules.cpp)
real_t p(const Vector &x, real_t t)
real_t sol(const Vector &x)