MFEM v4.9.0
Finite element discretization library
Loading...
Searching...
No Matches
complex_fem.hpp
Go to the documentation of this file.
1// Copyright (c) 2010-2025, 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#ifndef MFEM_COMPLEX_FEM
13#define MFEM_COMPLEX_FEM
14
16#include "gridfunc.hpp"
17#include "linearform.hpp"
18#include "bilinearform.hpp"
19#ifdef MFEM_USE_MPI
20#include "pgridfunc.hpp"
21#include "plinearform.hpp"
22#include "pbilinearform.hpp"
23#endif
24#include <complex>
25
26namespace mfem
27{
28
29/// Class for complex-valued grid function - real + imaginary part Vector with
30/// associated FE space.
32{
33private:
34 GridFunction * gfr;
35 GridFunction * gfi;
36
37protected:
38 /// FE space on which the grid function lives. Owned if #fec_owned
39 /// is not NULL.
41
42 /** @brief Used when the grid function is read from a file. It can also be
43 set explicitly, see MakeOwner().
44
45 If not NULL, this pointer is owned by the ComplexGridFunction. */
47
48 long fes_sequence; // see FiniteElementSpace::sequence, Mesh::sequence
49
50 void Destroy();
51
52public:
53 /** @brief Construct a ComplexGridFunction associated with the
54 FiniteElementSpace @a *f. */
56
57 /** @brief Construct a ComplexGridFunction on the given Mesh, using the data
58 from @a input.
59
60 The content of @a input should be in the format created by the method
61 Save(). The reconstructed FiniteElementSpace and FiniteElementCollection
62 are owned by the ComplexGridFunction. */
63 ComplexGridFunction(Mesh *m, std::istream &input);
64
65 void Update();
66
67 /** Return update counter, similar to Mesh::GetSequence(). Used to
68 check if it is up to date with the space. */
69 long GetSequence() const { return fes_sequence; }
70
71 /// Make the ComplexGridFunction the owner of #fec_owned and #fes.
72 /** If the new FiniteElementCollection, @a fec_, is NULL, ownership
73 of #fec_owned and #fes is taken away. */
75
76 /// Returns a pointer to the FiniteElementCollection used to
77 /// construct this ComplexGridFunction if this class owns that
78 /// object. Otherwise this function will return NULL.
80
81 /// Shortcut for calling FiniteElementSpace::GetVectorDim() on the
82 /// underlying #fes
83 int VectorDim() const;
84
85 /// Assign constant values to the ComplexGridFunction data.
86 ComplexGridFunction &operator=(const std::complex<real_t> & value)
87 { *gfr = value.real(); *gfi = value.imag(); return *this; }
88
89 virtual void ProjectCoefficient(Coefficient &real_coeff,
90 Coefficient &imag_coeff);
91 virtual void ProjectCoefficient(VectorCoefficient &real_vcoeff,
92 VectorCoefficient &imag_vcoeff);
93
94 virtual void ProjectBdrCoefficient(Coefficient &real_coeff,
95 Coefficient &imag_coeff,
96 Array<int> &attr);
97 virtual void ProjectBdrCoefficientNormal(VectorCoefficient &real_coeff,
98 VectorCoefficient &imag_coeff,
99 Array<int> &attr);
100 virtual void ProjectBdrCoefficientTangent(VectorCoefficient &real_coeff,
101 VectorCoefficient &imag_coeff,
102 Array<int> &attr);
103
105 const FiniteElementSpace *FESpace() const { return fes; }
106
107 GridFunction & real() { return *gfr; }
108 GridFunction & imag() { return *gfi; }
109 const GridFunction & real() const { return *gfr; }
110 const GridFunction & imag() const { return *gfi; }
111
112 /// Update the memory location of the real and imaginary GridFunction @a gfr
113 /// and @a gfi to match the ComplexGridFunction.
114 void Sync() { gfr->SyncMemory(*this); gfi->SyncMemory(*this); }
115
116 /// Update the alias memory location of the real and imaginary GridFunction
117 /// @a gfr and @a gfi to match the ComplexGridFunction.
118 void SyncAlias() { gfr->SyncAliasMemory(*this); gfi->SyncAliasMemory(*this); }
119
120 /// @brief Returns ||u_ex - u_h||_L2 for complex-valued scalar fields
121 ///
122 /// @see GridFunction::ComputeL2Error(Coefficient &exsol,
123 /// const IntegrationRule *irs[],
124 /// const Array<int> *elems) const
125 /// for more detailed documentation.
127 const IntegrationRule *irs[] = NULL) const
128 {
129 real_t err_r = gfr->ComputeL2Error(exsolr, irs);
130 real_t err_i = gfi->ComputeL2Error(exsoli, irs);
131 return sqrt(err_r * err_r + err_i * err_i);
132 }
133
134 /// @brief Returns ||u_ex - u_h||_L2 for complex-valued vector fields
135 ///
136 /// @see GridFunction::ComputeL2Error(VectorCoefficient &exsol,
137 /// const IntegrationRule *irs[],
138 /// const Array<int> *elems) const
139 /// for more detailed documentation.
141 VectorCoefficient &exsoli,
142 const IntegrationRule *irs[] = NULL,
143 Array<int> *elems = NULL) const
144 {
145 real_t err_r = gfr->ComputeL2Error(exsolr, irs, elems);
146 real_t err_i = gfi->ComputeL2Error(exsoli, irs, elems);
147 return sqrt(err_r * err_r + err_i * err_i);
148 }
149
150 /// Save the ComplexGridFunction to an output stream.
151 virtual void Save(std::ostream &out) const;
152
153 /// Save the ComplexGridFunction to a file
154 /** The given @a precision will be used for ASCII output. */
155 virtual void Save(const char *fname, int precision=16) const;
156
157 /// Destroys the grid function.
159
160};
161
162/** Overload operator<< for std::ostream and ComplexGridFunction; not valid
163 for the class ParComplexGridFunction */
164std::ostream &operator<<(std::ostream &out, const ComplexGridFunction &sol);
165
166/** Class for a complex-valued linear form
167
168 The @a convention argument in the class's constructor is documented in the
169 mfem::ComplexOperator class found in linalg/complex_operator.hpp.
170
171 When supplying integrators to the ComplexLinearForm either the real or
172 imaginary integrator can be NULL. This indicates that the corresponding
173 portion of the complex-valued field is equal to zero.
174 */
176{
177private:
179
180protected:
183
184public:
187 convention = ComplexOperator::HERMITIAN);
188
189 /** @brief Create a ComplexLinearForm on the FiniteElementSpace @a fes, using
190 the same integrators as the LinearForms @a lf_r (real) and @a lf_i (imag).
191
192 The pointer @a fes is not owned by the newly constructed object.
193
194 The integrators are copied as pointers and they are not owned by the
195 newly constructed ComplexLinearForm. */
198 convention = ComplexOperator::HERMITIAN);
199
200 virtual ~ComplexLinearForm();
201
202 /// Assign constant values to the ComplexLinearForm data.
203 ComplexLinearForm &operator=(const std::complex<real_t> & value)
204 { *lfr = value.real(); *lfi = value.imag(); return *this; }
205
208 convention) { conv = convention; }
209
210 /// Adds new Domain Integrator.
212 LinearFormIntegrator *lfi_imag);
213
214 /// Adds new Domain Integrator, restricted to the given attributes.
216 LinearFormIntegrator *lfi_imag,
217 Array<int> &elem_attr_marker);
218
219 /// Adds new Boundary Integrator.
221 LinearFormIntegrator *lfi_imag);
222
223 /** @brief Add new Boundary Integrator, restricted to the given boundary
224 attributes.
225
226 Assumes ownership of @a lfi_real and @a lfi_imag.
227
228 The array @a bdr_attr_marker is stored internally as a pointer to the
229 given Array<int> object. */
231 LinearFormIntegrator *lfi_imag,
232 Array<int> &bdr_attr_marker);
233
234 /// Adds new Boundary Face Integrator. Assumes ownership of @a lfi.
236 LinearFormIntegrator *lfi_imag);
237
238 /** @brief Add new Boundary Face Integrator, restricted to the given boundary
239 attributes.
240
241 Assumes ownership of @a lfi_real and @a lfi_imag.
242
243 The array @a bdr_attr_marker is stored internally as a pointer to the
244 given Array<int> object. */
246 LinearFormIntegrator *lfi_imag,
247 Array<int> &bdr_attr_marker);
248
249 FiniteElementSpace *FESpace() const { return lfr->FESpace(); }
250
251 LinearForm & real() { return *lfr; }
252 LinearForm & imag() { return *lfi; }
253 const LinearForm & real() const { return *lfr; }
254 const LinearForm & imag() const { return *lfi; }
255
256 /// Update the memory location of the real and imaginary LinearForm @a lfr
257 /// and @a lfi to match the ComplexLinearForm.
258 void Sync() { lfr->SyncMemory(*this); lfi->SyncMemory(*this); }
259
260 /// Update the alias memory location of the real and imaginary LinearForm @a
261 /// lfr and @a lfi to match the ComplexLinearForm.
262 void SyncAlias() { lfr->SyncAliasMemory(*this); lfi->SyncAliasMemory(*this); }
263
264 void Update();
266
267 /// Assembles the linear form i.e. sums over all domain/bdr integrators.
268 void Assemble();
269
270 std::complex<real_t> operator()(const ComplexGridFunction &gf) const;
271};
272
273
274/** Class for sesquilinear form
275
276 A sesquilinear form is a generalization of a bilinear form to complex-valued
277 fields. Sesquilinear forms are linear in the second argument but the first
278 argument involves a complex conjugate in the sense that:
279
280 a(alpha u, beta v) = conj(alpha) beta a(u, v)
281
282 The @a convention argument in the class's constructor is documented in the
283 mfem::ComplexOperator class found in linalg/complex_operator.hpp.
284
285 When supplying integrators to the SesquilinearForm either the real or
286 imaginary integrator can be NULL. This indicates that the corresponding
287 portion of the complex-valued material coefficient is equal to zero.
288*/
290{
291private:
293
294 /** This data member allows one to specify what should be done to the
295 diagonal matrix entries and corresponding RHS values upon elimination of
296 the constrained DoFs. */
298
299 BilinearForm *blfr;
300 BilinearForm *blfi;
301
302 /* These methods check if the real/imag parts of the sesquilinear form are
303 not empty */
304 bool RealInteg();
305 bool ImagInteg();
306
307public:
310 convention = ComplexOperator::HERMITIAN);
311 /** @brief Create a SesquilinearForm on the FiniteElementSpace @a fes, using
312 the same integrators as the BilinearForms @a bfr and @a bfi .
313
314 The pointer @a fes is not owned by the newly constructed object.
315
316 The integrators are copied as pointers and they are not owned by the
317 newly constructed SesquilinearForm. */
320 convention = ComplexOperator::HERMITIAN);
321
324 convention) { conv = convention; }
325
326 /// Set the desired assembly level.
327 /** Valid choices are:
328
329 - AssemblyLevel::LEGACY (default)
330 - AssemblyLevel::FULL
331 - AssemblyLevel::PARTIAL
332 - AssemblyLevel::ELEMENT
333 - AssemblyLevel::NONE
334
335 This method must be called before assembly. */
336 void SetAssemblyLevel(AssemblyLevel assembly_level)
337 {
338 blfr->SetAssemblyLevel(assembly_level);
339 blfi->SetAssemblyLevel(assembly_level);
340 }
341
342 BilinearForm & real() { return *blfr; }
343 BilinearForm & imag() { return *blfi; }
344 const BilinearForm & real() const { return *blfr; }
345 const BilinearForm & imag() const { return *blfi; }
346
347 /// Adds new Domain Integrator.
349 BilinearFormIntegrator *bfi_imag);
350
351 /// Adds new Domain Integrator, restricted to the given attributes.
353 BilinearFormIntegrator *bfi_imag,
354 Array<int> &elem_marker);
355
356 /// Adds new Boundary Integrator.
358 BilinearFormIntegrator *bfi_imag);
359
360 /// Adds new Boundary Integrator, restricted to specific boundary attributes.
362 BilinearFormIntegrator *bfi_imag,
363 Array<int> &bdr_marker);
364
365 /// Adds new interior Face Integrator. Assumes ownership of @a bfi.
367 BilinearFormIntegrator *bfi_imag);
368
369 /// Adds new boundary Face Integrator. Assumes ownership of @a bfi.
371 BilinearFormIntegrator *bfi_imag);
372
373 /** @brief Adds new boundary Face Integrator, restricted to specific boundary
374 attributes.
375
376 Assumes ownership of @a bfi.
377
378 The array @a bdr_marker is stored internally as a pointer to the given
379 Array<int> object. */
381 BilinearFormIntegrator *bfi_imag,
382 Array<int> &bdr_marker);
383
384 /// Assemble the local matrix
385 void Assemble(int skip_zeros = 1);
386
387 /// Finalizes the matrix initialization.
388 void Finalize(int skip_zeros = 1);
389
390 /// Returns the matrix assembled on the true dofs, i.e. P^t A P.
391 /** The returned matrix has to be deleted by the caller. */
393
394 /// Return the parallel FE space associated with the ParBilinearForm.
395 FiniteElementSpace *FESpace() const { return blfr->FESpace(); }
396
397 void FormLinearSystem(const Array<int> &ess_tdof_list, Vector &x, Vector &b,
398 OperatorHandle &A, Vector &X, Vector &B,
399 int copy_interior = 0);
400
401 void FormSystemMatrix(const Array<int> &ess_tdof_list,
402 OperatorHandle &A);
403
404 /** Call this method after solving a linear system constructed using the
405 FormLinearSystem method to recover the solution as a ParGridFunction-size
406 vector in x. Use the same arguments as in the FormLinearSystem call. */
407 virtual void RecoverFEMSolution(const Vector &X, const Vector &b, Vector &x);
408
409 virtual void Update(FiniteElementSpace *nfes = NULL);
410
411 /// Sets diagonal policy used upon construction of the linear system
413
414 /// Returns the diagonal policy of the sesquilinear form
415 Matrix::DiagonalPolicy GetDiagonalPolicy() const {return diag_policy;}
416
417 virtual ~SesquilinearForm();
418};
419
420#ifdef MFEM_USE_MPI
421
422/// Class for parallel complex-valued grid function - real + imaginary part
423/// Vector with associated parallel FE space.
425{
426private:
427 ParGridFunction * pgfr;
428 ParGridFunction * pgfi;
429
430protected:
431 /// FE space on which the grid function lives. Owned if #fec_owned
432 /// is not NULL.
434
435 /** @brief Used when the grid function is read from a file. It can also be
436 set explicitly, see MakeOwner().
437
438 If not NULL, this pointer is owned by the ParComplexGridFunction. */
440
441 long fes_sequence; // see FiniteElementSpace::sequence, Mesh::sequence
442
443 void Destroy();
444
445public:
446
447 /** @brief Construct a ParComplexGridFunction associated with the
448 ParFiniteElementSpace @a *pf. */
450
451 /** @brief Construct a ParComplexGridFunction on a given ParMesh,
452 @a pmesh, reading from an std::istream.
453
454 In the process, a ParFiniteElementSpace and a FiniteElementCollection are
455 constructed. The new ParComplexGridFunction assumes ownership of both. */
456 ParComplexGridFunction(ParMesh *pmesh, std::istream &input);
457
458 void Update();
459
460 /** Return update counter, similar to Mesh::GetSequence(). Used to
461 check if it is up to date with the space. */
462 long GetSequence() const { return fes_sequence; }
463
464 /// Make the ParComplexGridFunction the owner of #fec_owned and #pfes.
465 /** If the new FiniteElementCollection, @a fec_, is NULL, ownership
466 of #fec_owned and #pfes is taken away. */
468
469 /// Returns a pointer to the FiniteElementCollection used to
470 /// construct this ParComplexGridFunction if this class owns that
471 /// object. Otherwise this function will return NULL.
473
474 /// Shortcut for calling FiniteElementSpace::GetVectorDim() on the
475 /// underlying #pfes
476 int VectorDim() const;
477
478 /// Assign constant values to the ParComplexGridFunction data.
479 ParComplexGridFunction &operator=(const std::complex<real_t> & value)
480 { *pgfr = value.real(); *pgfi = value.imag(); return *this; }
481
482 virtual void ProjectCoefficient(Coefficient &real_coeff,
483 Coefficient &imag_coeff);
484 virtual void ProjectCoefficient(VectorCoefficient &real_vcoeff,
485 VectorCoefficient &imag_vcoeff);
486
487 virtual void ProjectBdrCoefficient(Coefficient &real_coeff,
488 Coefficient &imag_coeff,
489 Array<int> &attr);
490 virtual void ProjectBdrCoefficientNormal(VectorCoefficient &real_coeff,
491 VectorCoefficient &imag_coeff,
492 Array<int> &attr);
493 virtual void ProjectBdrCoefficientTangent(VectorCoefficient &real_coeff,
494 VectorCoefficient &imag_coeff,
495 Array<int> &attr);
496
497 void Distribute(const Vector *tv);
498 void Distribute(const Vector &tv) { Distribute(&tv); }
499
500 /// Returns the vector restricted to the true dofs.
501 void ParallelProject(Vector &tv) const;
502
504 const FiniteElementSpace *FESpace() const { return pfes; }
505
507 const ParFiniteElementSpace *ParFESpace() const { return pfes; }
508
509 ParGridFunction & real() { return *pgfr; }
510 ParGridFunction & imag() { return *pgfi; }
511 const ParGridFunction & real() const { return *pgfr; }
512 const ParGridFunction & imag() const { return *pgfi; }
513
514 /// Update the memory location of the real and imaginary ParGridFunction @a
515 /// pgfr and @a pgfi to match the ParComplexGridFunction.
516 void Sync() { pgfr->SyncMemory(*this); pgfi->SyncMemory(*this); }
517
518 /// Update the alias memory location of the real and imaginary
519 /// ParGridFunction @a pgfr and @a pgfi to match the ParComplexGridFunction.
521 { pgfr->SyncAliasMemory(*this); pgfi->SyncAliasMemory(*this); }
522
523 /// @brief Returns ||u_ex - u_h||_L2 in parallel for complex-valued
524 /// scalar fields
525 ///
526 /// @see GridFunction::ComputeL2Error(Coefficient &exsol,
527 /// const IntegrationRule *irs[],
528 /// const Array<int> *elems) const
529 /// for more detailed documentation.
531 const IntegrationRule *irs[] = NULL,
532 Array<int> *elems = NULL) const
533 {
534 real_t err_r = pgfr->ComputeL2Error(exsolr, irs, elems);
535 real_t err_i = pgfi->ComputeL2Error(exsoli, irs, elems);
536 return hypot(err_r, err_i);
537 }
538
539 /// @brief Returns ||u_ex - u_h||_L2 in parallel for complex-valued
540 /// vector fields
541 ///
542 /// @see GridFunction::ComputeL2Error(VectorCoefficient &exsol,
543 /// const IntegrationRule *irs[],
544 /// const Array<int> *elems) const
545 /// for more detailed documentation.
547 VectorCoefficient &exsoli,
548 const IntegrationRule *irs[] = NULL,
549 Array<int> *elems = NULL) const
550 {
551 real_t err_r = pgfr->ComputeL2Error(exsolr, irs, elems);
552 real_t err_i = pgfi->ComputeL2Error(exsoli, irs, elems);
553 return hypot(err_r, err_i);
554 }
555
556 /// Save the local portion of the ParComplexGridFunction
557 /** This differs from the serial ComplexGridFunction::Save in that it
558 takes into account the signs of the local dofs. */
559 void Save(std::ostream &out) const;
560
561 /// Save the ParComplexGridFunction to files
562 /** Saves one file for each MPI rank. The files will be given suffixes
563 according to the MPI rank. The given @a precision will be used for ASCII
564 output. */
565 void Save(const char *fname, int precision=16) const;
566
567 /// Destroys grid function.
569
570};
571
572/** Overload operator<< for std::ostream and ParComplexGridFunction */
573std::ostream &operator<<(std::ostream &out, const ParComplexGridFunction &sol);
574
575/** Class for a complex-valued, parallel linear form
576
577 The @a convention argument in the class's constructor is documented in the
578 mfem::ComplexOperator class found in linalg/complex_operator.hpp.
579
580 When supplying integrators to the ParComplexLinearForm either the real or
581 imaginary integrator can be NULL. This indicates that the corresponding
582 portion of the complex-valued field is equal to zero.
583 */
585{
586private:
588
589protected:
592
594
595public:
596
599 convention = ComplexOperator::HERMITIAN);
600
601 /** @brief Create a ParComplexLinearForm on the ParFiniteElementSpace @a pf,
602 using the same integrators as the LinearForms @a plf_r (real) and
603 @a plf_i (imag).
604
605 The pointer @a fes is not owned by the newly constructed object.
606
607 The integrators are copied as pointers and they are not owned by the newly
608 constructed ParComplexLinearForm. */
610 ParLinearForm *plf_i,
612 convention = ComplexOperator::HERMITIAN);
613
614 virtual ~ParComplexLinearForm();
615
616 /// Assign constant values to the ParComplexLinearForm data.
617 ParComplexLinearForm &operator=(const std::complex<real_t> & value)
618 { *plfr = value.real(); *plfi = value.imag(); return *this; }
619
622 convention) { conv = convention; }
623
624 /// Adds new Domain Integrator.
626 LinearFormIntegrator *lfi_imag);
627
628 /// Adds new Domain Integrator, restricted to specific attributes.
630 LinearFormIntegrator *lfi_imag,
631 Array<int> &elem_attr_marker);
632
633 /// Adds new Boundary Integrator.
635 LinearFormIntegrator *lfi_imag);
636
637 /** @brief Add new Boundary Integrator, restricted to the given boundary
638 attributes.
639
640 Assumes ownership of @a lfi_real and @a lfi_imag.
641
642 The array @a bdr_attr_marker is stored internally as a pointer to the
643 given Array<int> object. */
645 LinearFormIntegrator *lfi_imag,
646 Array<int> &bdr_attr_marker);
647
648 /// Adds new Boundary Face Integrator. Assumes ownership of @a lfi.
650 LinearFormIntegrator *lfi_imag);
651
652 /** @brief Add new Boundary Face Integrator, restricted to the given boundary
653 attributes.
654
655 Assumes ownership of @a lfi_real and @a lfi_imag.
656
657 The array @a bdr_attr_marker is stored internally as a pointer to the
658 given Array<int> object. */
660 LinearFormIntegrator *lfi_imag,
661 Array<int> &bdr_attr_marker);
662
664
665 ParLinearForm & real() { return *plfr; }
666 ParLinearForm & imag() { return *plfi; }
667 const ParLinearForm & real() const { return *plfr; }
668 const ParLinearForm & imag() const { return *plfi; }
669
670 /// Update the memory location of the real and imaginary ParLinearForm @a lfr
671 /// and @a lfi to match the ParComplexLinearForm.
672 void Sync() { plfr->SyncMemory(*this); plfi->SyncMemory(*this); }
673
674 /// Update the alias memory location of the real and imaginary ParLinearForm
675 /// @a plfr and @a plfi to match the ParComplexLinearForm.
676 void SyncAlias() { plfr->SyncAliasMemory(*this); plfi->SyncAliasMemory(*this); }
677
678 void Update(ParFiniteElementSpace *pf = NULL);
679
680 /// Assembles the linear form i.e. sums over all domain/bdr integrators.
681 void Assemble();
682
683 /// Assemble the vector on the true dofs, i.e. P^t v.
684 void ParallelAssemble(Vector &tv);
685
686 /// Returns the vector assembled on the true dofs, i.e. P^t v.
688
689 std::complex<real_t> operator()(const ParComplexGridFunction &gf) const;
690
691};
692
693/** Class for a parallel sesquilinear form
694
695 A sesquilinear form is a generalization of a bilinear form to complex-valued
696 fields. Sesquilinear forms are linear in the second argument but the
697 first argument involves a complex conjugate in the sense that:
698
699 a(alpha u, beta v) = conj(alpha) beta a(u, v)
700
701 The @a convention argument in the class's constructor is documented in the
702 mfem::ComplexOperator class found in linalg/complex_operator.hpp.
703
704 When supplying integrators to the ParSesquilinearForm either the real or
705 imaginary integrator can be NULL. This indicates that the corresponding
706 portion of the complex-valued material coefficient is equal to zero.
707*/
709{
710private:
712
713 ParBilinearForm *pblfr;
714 ParBilinearForm *pblfi;
715
716 /* These methods check if the real/imag parts of the sesqulinear form are not
717 empty */
718 bool RealInteg();
719 bool ImagInteg();
720
721public:
724 convention = ComplexOperator::HERMITIAN);
725
726 /** @brief Create a ParSesquilinearForm on the ParFiniteElementSpace @a pf,
727 using the same integrators as the ParBilinearForms @a pbfr and @a pbfi .
728
729 The pointer @a pf is not owned by the newly constructed object.
730
731 The integrators are copied as pointers and they are not owned by the
732 newly constructed ParSesquilinearForm. */
734 ParBilinearForm *pbfi,
736 convention = ComplexOperator::HERMITIAN);
737
740 convention) { conv = convention; }
741
742 /// Set the desired assembly level.
743 /** Valid choices are:
744
745 - AssemblyLevel::LEGACY (default)
746 - AssemblyLevel::FULL
747 - AssemblyLevel::PARTIAL
748 - AssemblyLevel::ELEMENT
749 - AssemblyLevel::NONE
750
751 This method must be called before assembly. */
752 void SetAssemblyLevel(AssemblyLevel assembly_level)
753 {
754 pblfr->SetAssemblyLevel(assembly_level);
755 pblfi->SetAssemblyLevel(assembly_level);
756 }
757
758 ParBilinearForm & real() { return *pblfr; }
759 ParBilinearForm & imag() { return *pblfi; }
760 const ParBilinearForm & real() const { return *pblfr; }
761 const ParBilinearForm & imag() const { return *pblfi; }
762
763 /// Adds new Domain Integrator.
765 BilinearFormIntegrator *bfi_imag);
766
767 /// Adds new Domain Integrator, restricted to specific attributes.
769 BilinearFormIntegrator *bfi_imag,
770 Array<int> &elem_marker);
771
772 /// Adds new Boundary Integrator.
774 BilinearFormIntegrator *bfi_imag);
775
776 /** @brief Adds new boundary Integrator, restricted to specific boundary
777 attributes.
778
779 Assumes ownership of @a bfi.
780
781 The array @a bdr_marker is stored internally as a pointer to the given
782 Array<int> object. */
784 BilinearFormIntegrator *bfi_imag,
785 Array<int> &bdr_marker);
786
787 /// Adds new interior Face Integrator. Assumes ownership of @a bfi.
789 BilinearFormIntegrator *bfi_imag);
790
791 /// Adds new boundary Face Integrator. Assumes ownership of @a bfi.
793 BilinearFormIntegrator *bfi_imag);
794
795 /** @brief Adds new boundary Face Integrator, restricted to specific boundary
796 attributes.
797
798 Assumes ownership of @a bfi.
799
800 The array @a bdr_marker is stored internally as a pointer to the given
801 Array<int> object. */
803 BilinearFormIntegrator *bfi_imag,
804 Array<int> &bdr_marker);
805
806 /// Assemble the local matrix
807 void Assemble(int skip_zeros = 1);
808
809 /// Finalizes the matrix initialization.
810 void Finalize(int skip_zeros = 1);
811
812 /// Returns the matrix assembled on the true dofs, i.e. P^t A P.
813 /** The returned matrix has to be deleted by the caller. */
815
816 /// Return the parallel FE space associated with the ParBilinearForm.
817 ParFiniteElementSpace *ParFESpace() const { return pblfr->ParFESpace(); }
818
819 void FormLinearSystem(const Array<int> &ess_tdof_list, Vector &x, Vector &b,
820 OperatorHandle &A, Vector &X, Vector &B,
821 int copy_interior = 0);
822
823 void FormSystemMatrix(const Array<int> &ess_tdof_list,
824 OperatorHandle &A);
825
826 /** Call this method after solving a linear system constructed using the
827 FormLinearSystem method to recover the solution as a ParGridFunction-size
828 vector in x. Use the same arguments as in the FormLinearSystem call. */
829 virtual void RecoverFEMSolution(const Vector &X, const Vector &b, Vector &x);
830
831 virtual void Update(FiniteElementSpace *nfes = NULL);
832
833 virtual ~ParSesquilinearForm();
834};
835
836#endif // MFEM_USE_MPI
837
838}
839
840#endif // MFEM_COMPLEX_FEM
Abstract base class BilinearFormIntegrator.
A "square matrix" operator for the associated FE space and BLFIntegrators The sum of all the BLFInteg...
void SetAssemblyLevel(AssemblyLevel assembly_level)
Set the desired assembly level.
FiniteElementSpace * FESpace()
Return the FE space associated with the BilinearForm.
Base class Coefficients that optionally depend on space and time. These are used by the BilinearFormI...
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)
FiniteElementSpace * fes
const GridFunction & imag() const
const FiniteElementSpace * FESpace() const
virtual real_t ComputeL2Error(VectorCoefficient &exsolr, VectorCoefficient &exsoli, const IntegrationRule *irs[]=NULL, Array< int > *elems=NULL) const
Returns ||u_ex - u_h||_L2 for complex-valued vector fields.
FiniteElementCollection * fec_owned
Used when the grid function is read from a file. It can also be set explicitly, see MakeOwner().
void MakeOwner(FiniteElementCollection *fec_)
Make the ComplexGridFunction the owner of fec_owned and fes.
FiniteElementSpace * FESpace()
ComplexGridFunction & operator=(const std::complex< real_t > &value)
Assign constant values to the ComplexGridFunction data.
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.
const GridFunction & real() const
virtual real_t ComputeL2Error(Coefficient &exsolr, Coefficient &exsoli, const IntegrationRule *irs[]=NULL) const
Returns ||u_ex - u_h||_L2 for complex-valued scalar fields.
virtual ~ComplexGridFunction()
Destroys the grid function.
FiniteElementCollection * OwnFEC()
Specialization of the ComplexOperator built from a pair of HypreParMatrices.
const LinearForm & imag() const
ComplexOperator::Convention GetConvention() const
ComplexLinearForm(FiniteElementSpace *fes, ComplexOperator::Convention convention=ComplexOperator::HERMITIAN)
const LinearForm & real() const
void AddBdrFaceIntegrator(LinearFormIntegrator *lfi_real, LinearFormIntegrator *lfi_imag)
Adds new Boundary Face Integrator. Assumes ownership of lfi.
void AddDomainIntegrator(LinearFormIntegrator *lfi_real, LinearFormIntegrator *lfi_imag)
Adds new Domain Integrator.
void SetConvention(const ComplexOperator::Convention &convention)
ComplexLinearForm & operator=(const std::complex< real_t > &value)
Assign constant values to the ComplexLinearForm data.
FiniteElementSpace * FESpace() const
std::complex< real_t > operator()(const ComplexGridFunction &gf) const
void Assemble()
Assembles the linear form i.e. sums over all domain/bdr integrators.
void AddBoundaryIntegrator(LinearFormIntegrator *lfi_real, LinearFormIntegrator *lfi_imag)
Adds new Boundary Integrator.
@ HERMITIAN
Native convention for Hermitian operators.
Specialization of the ComplexOperator built from a pair of Sparse Matrices.
Collection of finite elements from the same family in multiple dimensions. This class is used to matc...
Definition fe_coll.hpp:27
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
Definition fespace.hpp:208
Class for grid function - Vector with associated FE space.
Definition gridfunc.hpp:32
virtual real_t ComputeL2Error(Coefficient *exsol[], const IntegrationRule *irs[]=NULL, const Array< int > *elems=NULL) const
Returns ||exsol - u_h||_L2 for scalar or vector H1 or L2 elements.
Wrapper for hypre's parallel vector class.
Definition hypre.hpp:230
Class for an integration rule - an Array of IntegrationPoint.
Definition intrules.hpp:100
Abstract base class LinearFormIntegrator.
Definition lininteg.hpp:28
Vector with associated FE space and LinearFormIntegrators.
FiniteElementSpace * FESpace()
Read+write access to the associated FiniteElementSpace.
Mesh data type.
Definition mesh.hpp:65
Pointer to an Operator of a specified type.
Definition handle.hpp:34
DiagonalPolicy
Defines operator diagonal policy upon elimination of rows and/or columns.
Definition operator.hpp:48
@ DIAG_ONE
Set the diagonal value to one.
Definition operator.hpp:50
Class for parallel bilinear form.
ParFiniteElementSpace * ParFESpace() const
Return the parallel FE space associated with the ParBilinearForm.
FiniteElementSpace * FESpace()
const ParFiniteElementSpace * ParFESpace() const
const FiniteElementSpace * FESpace() const
void MakeOwner(FiniteElementCollection *fec_)
Make the ParComplexGridFunction the owner of fec_owned and pfes.
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.
ParFiniteElementSpace * ParFESpace()
virtual void ProjectBdrCoefficientNormal(VectorCoefficient &real_coeff, VectorCoefficient &imag_coeff, Array< int > &attr)
ParFiniteElementSpace * pfes
const ParGridFunction & real() const
void Distribute(const Vector *tv)
virtual void ProjectBdrCoefficientTangent(VectorCoefficient &real_coeff, VectorCoefficient &imag_coeff, Array< int > &attr)
virtual real_t ComputeL2Error(Coefficient &exsolr, Coefficient &exsoli, const IntegrationRule *irs[]=NULL, Array< int > *elems=NULL) const
Returns ||u_ex - u_h||_L2 in parallel for complex-valued scalar fields.
virtual ~ParComplexGridFunction()
Destroys grid function.
virtual void ProjectCoefficient(Coefficient &real_coeff, Coefficient &imag_coeff)
ParComplexGridFunction & operator=(const std::complex< real_t > &value)
Assign constant values to the ParComplexGridFunction data.
void Distribute(const Vector &tv)
const ParGridFunction & imag() const
FiniteElementCollection * OwnFEC()
void Save(std::ostream &out) const
Save the local portion of the ParComplexGridFunction.
virtual real_t ComputeL2Error(VectorCoefficient &exsolr, VectorCoefficient &exsoli, const IntegrationRule *irs[]=NULL, Array< int > *elems=NULL) const
Returns ||u_ex - u_h||_L2 in parallel for complex-valued vector fields.
void Update(ParFiniteElementSpace *pf=NULL)
void AddBdrFaceIntegrator(LinearFormIntegrator *lfi_real, LinearFormIntegrator *lfi_imag)
Adds new Boundary Face Integrator. Assumes ownership of lfi.
ParComplexLinearForm & operator=(const std::complex< real_t > &value)
Assign constant values to the ParComplexLinearForm data.
std::complex< real_t > operator()(const ParComplexGridFunction &gf) const
void AddBoundaryIntegrator(LinearFormIntegrator *lfi_real, LinearFormIntegrator *lfi_imag)
Adds new Boundary Integrator.
void Assemble()
Assembles the linear form i.e. sums over all domain/bdr integrators.
void SetConvention(const ComplexOperator::Convention &convention)
HypreParVector * ParallelAssemble()
Returns the vector assembled on the true dofs, i.e. P^t v.
void AddDomainIntegrator(LinearFormIntegrator *lfi_real, LinearFormIntegrator *lfi_imag)
Adds new Domain Integrator.
const ParLinearForm & real() const
ComplexOperator::Convention GetConvention() const
ParFiniteElementSpace * ParFESpace() const
ParComplexLinearForm(ParFiniteElementSpace *pf, ComplexOperator::Convention convention=ComplexOperator::HERMITIAN)
const ParLinearForm & imag() const
Abstract parallel finite element space.
Definition pfespace.hpp:31
Class for parallel grid function.
Definition pgridfunc.hpp:50
real_t ComputeL2Error(Coefficient *exsol[], const IntegrationRule *irs[]=NULL, const Array< int > *elems=NULL) const override
Returns ||u_ex - u_h||_L2 in parallel for H1 or L2 elements.
Class for parallel linear form.
ParFiniteElementSpace * ParFESpace() const
Class for parallel meshes.
Definition pmesh.hpp:34
virtual void RecoverFEMSolution(const Vector &X, const Vector &b, Vector &x)
ComplexHypreParMatrix * ParallelAssemble()
Returns the matrix assembled on the true dofs, i.e. P^t A P.
ParSesquilinearForm(ParFiniteElementSpace *pf, ComplexOperator::Convention convention=ComplexOperator::HERMITIAN)
ParBilinearForm & imag()
void FormSystemMatrix(const Array< int > &ess_tdof_list, OperatorHandle &A)
void FormLinearSystem(const Array< int > &ess_tdof_list, Vector &x, Vector &b, OperatorHandle &A, Vector &X, Vector &B, int copy_interior=0)
ParFiniteElementSpace * ParFESpace() const
Return the parallel FE space associated with the ParBilinearForm.
virtual void Update(FiniteElementSpace *nfes=NULL)
void AddBoundaryIntegrator(BilinearFormIntegrator *bfi_real, BilinearFormIntegrator *bfi_imag)
Adds new Boundary Integrator.
void AddBdrFaceIntegrator(BilinearFormIntegrator *bfi_real, BilinearFormIntegrator *bfi_imag)
Adds new boundary Face Integrator. Assumes ownership of bfi.
const ParBilinearForm & real() const
void Finalize(int skip_zeros=1)
Finalizes the matrix initialization.
void AddDomainIntegrator(BilinearFormIntegrator *bfi_real, BilinearFormIntegrator *bfi_imag)
Adds new Domain Integrator.
void SetAssemblyLevel(AssemblyLevel assembly_level)
Set the desired assembly level.
void AddInteriorFaceIntegrator(BilinearFormIntegrator *bfi_real, BilinearFormIntegrator *bfi_imag)
Adds new interior Face Integrator. Assumes ownership of bfi.
void Assemble(int skip_zeros=1)
Assemble the local matrix.
ParBilinearForm & real()
const ParBilinearForm & imag() const
ComplexOperator::Convention GetConvention() const
void SetConvention(const ComplexOperator::Convention &convention)
ComplexOperator::Convention GetConvention() const
ComplexSparseMatrix * AssembleComplexSparseMatrix()
Returns the matrix assembled on the true dofs, i.e. P^t A P.
void SetDiagonalPolicy(mfem::Matrix::DiagonalPolicy dpolicy)
Sets diagonal policy used upon construction of the linear system.
void Finalize(int skip_zeros=1)
Finalizes the matrix initialization.
virtual void RecoverFEMSolution(const Vector &X, const Vector &b, Vector &x)
void Assemble(int skip_zeros=1)
Assemble the local matrix.
SesquilinearForm(FiniteElementSpace *fes, ComplexOperator::Convention convention=ComplexOperator::HERMITIAN)
void FormSystemMatrix(const Array< int > &ess_tdof_list, OperatorHandle &A)
FiniteElementSpace * FESpace() const
Return the parallel FE space associated with the ParBilinearForm.
void AddDomainIntegrator(BilinearFormIntegrator *bfi_real, BilinearFormIntegrator *bfi_imag)
Adds new Domain Integrator.
BilinearForm & real()
const BilinearForm & real() const
Matrix::DiagonalPolicy GetDiagonalPolicy() const
Returns the diagonal policy of the sesquilinear form.
BilinearForm & imag()
const BilinearForm & imag() const
void SetAssemblyLevel(AssemblyLevel assembly_level)
Set the desired assembly level.
void SetConvention(const ComplexOperator::Convention &convention)
void AddBoundaryIntegrator(BilinearFormIntegrator *bfi_real, BilinearFormIntegrator *bfi_imag)
Adds new Boundary Integrator.
virtual void Update(FiniteElementSpace *nfes=NULL)
void FormLinearSystem(const Array< int > &ess_tdof_list, Vector &x, Vector &b, OperatorHandle &A, Vector &X, Vector &B, int copy_interior=0)
void AddInteriorFaceIntegrator(BilinearFormIntegrator *bfi_real, BilinearFormIntegrator *bfi_imag)
Adds new interior Face Integrator. Assumes ownership of bfi.
void AddBdrFaceIntegrator(BilinearFormIntegrator *bfi_real, BilinearFormIntegrator *bfi_imag)
Adds new boundary Face Integrator. Assumes ownership of bfi.
Base class for vector Coefficients that optionally depend on time and space.
Vector data type.
Definition vector.hpp:82
void SyncAliasMemory(const Vector &v) const
Update the alias memory location of the vector to match v.
Definition vector.hpp:275
void SyncMemory(const Vector &v) const
Update the memory location of the vector to match v.
Definition vector.hpp:272
HYPRE_Int HYPRE_BigInt
real_t b
Definition lissajous.cpp:42
std::ostream & operator<<(std::ostream &os, SparseMatrix const &mat)
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
AssemblyLevel
Enumeration defining the assembly level for bilinear and nonlinear form classes derived from Operator...
float real_t
Definition config.hpp:46
std::function< real_t(const Vector &)> f(real_t mass_coeff)
Definition lor_mms.hpp:30