MFEM v4.10.0
Finite element discretization library
Loading...
Searching...
No Matches
complex_fem.hpp
Go to the documentation of this file.
1// Copyright (c) 2010-2026, 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 /// Copy assignment. Only the data of the base class Vector is copied.
86 /** It is assumed that this object and @a rhs use FiniteElementSpace%s that
87 have the same size.
88
89 @note Defining this method overwrites the implicitly defined copy
90 assignment operator. */
92 { return operator=((const Vector &)rhs); }
93
94 /// Copy the data from @a v.
95 /** The size of @a v must be equal to double of the size of the associated
96 FiniteElementSpace #fes. */
98 {
99 MFEM_ASSERT(fes && v.Size() == 2*fes->GetVSize(), "");
101 return *this;
102 }
103
104 /// Assign constant values to the ComplexGridFunction data.
105 ComplexGridFunction &operator=(const std::complex<real_t> & value)
106 { *gfr = value.real(); *gfi = value.imag(); return *this; }
107
108 virtual void ProjectCoefficient(Coefficient &real_coeff,
109 Coefficient &imag_coeff);
110 virtual void ProjectCoefficient(VectorCoefficient &real_vcoeff,
111 VectorCoefficient &imag_vcoeff);
112
113 virtual void ProjectBdrCoefficient(Coefficient &real_coeff,
114 Coefficient &imag_coeff,
115 Array<int> &attr);
116 virtual void ProjectBdrCoefficientNormal(VectorCoefficient &real_coeff,
117 VectorCoefficient &imag_coeff,
118 Array<int> &attr);
119 virtual void ProjectBdrCoefficientTangent(VectorCoefficient &real_coeff,
120 VectorCoefficient &imag_coeff,
121 Array<int> &attr);
122
124 const FiniteElementSpace *FESpace() const { return fes; }
125
126 GridFunction & real() { return *gfr; }
127 GridFunction & imag() { return *gfi; }
128 const GridFunction & real() const { return *gfr; }
129 const GridFunction & imag() const { return *gfi; }
130
131 /// Update the memory location of the real and imaginary GridFunction @a gfr
132 /// and @a gfi to match the ComplexGridFunction.
133 void Sync() { gfr->SyncMemory(*this); gfi->SyncMemory(*this); }
134
135 /// Update the alias memory location of the real and imaginary GridFunction
136 /// @a gfr and @a gfi to match the ComplexGridFunction.
137 void SyncAlias() { gfr->SyncAliasMemory(*this); gfi->SyncAliasMemory(*this); }
138
139 /// @brief Returns ||u_ex - u_h||_L2 for complex-valued scalar fields
140 ///
141 /// @see GridFunction::ComputeL2Error(Coefficient &exsol,
142 /// const IntegrationRule *irs[],
143 /// const Array<int> *elems) const
144 /// for more detailed documentation.
146 const IntegrationRule *irs[] = NULL) const
147 {
148 real_t err_r = gfr->ComputeL2Error(exsolr, irs);
149 real_t err_i = gfi->ComputeL2Error(exsoli, irs);
150 return sqrt(err_r * err_r + err_i * err_i);
151 }
152
153 /// @brief Returns ||u_ex - u_h||_L2 for complex-valued vector fields
154 ///
155 /// @see GridFunction::ComputeL2Error(VectorCoefficient &exsol,
156 /// const IntegrationRule *irs[],
157 /// const Array<int> *elems) const
158 /// for more detailed documentation.
160 VectorCoefficient &exsoli,
161 const IntegrationRule *irs[] = NULL,
162 Array<int> *elems = NULL) const
163 {
164 real_t err_r = gfr->ComputeL2Error(exsolr, irs, elems);
165 real_t err_i = gfi->ComputeL2Error(exsoli, irs, elems);
166 return sqrt(err_r * err_r + err_i * err_i);
167 }
168
169 /// @brief Returns Max|u_ex - u_h| error for complex-valued H1 or L2 elements
170 ///
171 /// Compute the $L_\infty$ error across the entire domain.
172 ///
173 /// @param[in] exsolr Coefficient object reproducing the real part of the
174 /// anticipated values of the scalar field, Re(u_ex).
175 /// @param[in] exsoli Coefficient object reproducing the imaginary part of
176 /// the anticipated values of the scalar field, Im(u_ex).
177 /// @param[in] irs Optional pointer to an array of custom integration
178 /// rules e.g. higher order than the default rules. If
179 /// present the array will be indexed by
180 /// Geometry::Type.
181 ///
182 /// @note Uses ComputeLpError internally. See the ComputeLpError
183 /// documentation for generalizations of this error computation.
184 ///
185 /// @note If an array of integration rules is provided through @a irs, be
186 /// sure to include valid rules for each element type that may occur
187 /// in the list of elements.
188 ///
190 Coefficient &exsoli,
191 const IntegrationRule *irs[] = NULL) const
192 {
193 return ComputeLpError(infinity(), exsolr, exsoli, NULL, irs);
194 }
195
196 /// @brief Returns ||u_ex - u_h||_Lp for complex-valued H1 or L2 elements
197 ///
198 /// Computes:
199 /// $$(\sum_{elems} \int_{elem} w \, |u_{ex} - u_h|^p)^{1/p}$$
200 /// Where:
201 /// $$|u_{ex} - u_h| = \sqrt{Re(u_{ex} - u_h)^2 + Im(u_{ex} - u_h)^2}$$
202 ///
203 /// @param[in] p Real value indicating the exponent of the $L^p$ norm.
204 /// To avoid domain errors p should have a positive value,
205 /// either finite or infinite.
206 /// @param[in] exsolr Coefficient object reproducing the real part of the
207 /// anticipated values of the scalar field, Re(u_ex).
208 /// @param[in] exsoli Coefficient object reproducing the imaginary part of
209 /// the anticipated values of the scalar field, Im(u_ex).
210 /// @param[in] weight Optional pointer to a Coefficient object reproducing
211 /// a weighting function, w.
212 /// @param[in] irs Optional pointer to an array of custom integration
213 /// rules e.g. higher order than the default rules. If
214 /// present the array will be indexed by Geometry::Type.
215 /// @param[in] elems Optional pointer to a marker array, with a length
216 /// equal to the number of local elements, indicating
217 /// which elements to integrate over. Only those elements
218 /// corresponding to non-zero entries in @a elems will
219 /// contribute to the computed L2 error.
220 ///
221 /// @note If an array of integration rules is provided through @a irs, be
222 /// sure to include valid rules for each element type that may occur
223 /// in the list of elements.
224 ///
225 /// @note Quadratures with negative weights (as in some simplex integration
226 /// rules in MFEM) can produce negative integrals even with
227 /// non-negative integrands. To avoid returning negative errors this
228 /// function uses the absolute values of the element-wise integrals.
229 /// This may lead to results which are not entirely consistent with
230 /// such integration rules.
231 virtual real_t ComputeLpError(const real_t p,
232 Coefficient &exsolr,
233 Coefficient &exsoli,
234 Coefficient *weight = NULL,
235 const IntegrationRule *irs[] = NULL,
236 const Array<int> *elems = NULL) const;
237
238 /// Save the ComplexGridFunction to an output stream.
239 virtual void Save(std::ostream &out) const;
240
241 /// Save the ComplexGridFunction to a file
242 /** The given @a precision will be used for ASCII output. */
243 virtual void Save(const char *fname, int precision=16) const;
244
245 /// Destroys the grid function.
247
248};
249
250/** Overload operator<< for std::ostream and ComplexGridFunction; not valid
251 for the class ParComplexGridFunction */
252std::ostream &operator<<(std::ostream &out, const ComplexGridFunction &sol);
253
254/** Class for a complex-valued linear form
255
256 The @a convention argument in the class's constructor is documented in the
257 mfem::ComplexOperator class found in linalg/complex_operator.hpp.
258
259 When supplying integrators to the ComplexLinearForm either the real or
260 imaginary integrator can be NULL. This indicates that the corresponding
261 portion of the complex-valued field is equal to zero.
262 */
264{
265private:
267
268protected:
271
272public:
275 convention = ComplexOperator::HERMITIAN);
276
277 /** @brief Create a ComplexLinearForm on the FiniteElementSpace @a fes, using
278 the same integrators as the LinearForms @a lf_r (real) and @a lf_i (imag).
279
280 The pointer @a fes is not owned by the newly constructed object.
281
282 The integrators are copied as pointers and they are not owned by the
283 newly constructed ComplexLinearForm. */
286 convention = ComplexOperator::HERMITIAN);
287
288 virtual ~ComplexLinearForm();
289
290 /// Assign constant values to the ComplexLinearForm data.
291 ComplexLinearForm &operator=(const std::complex<real_t> & value)
292 { *lfr = value.real(); *lfi = value.imag(); return *this; }
293
296 convention) { conv = convention; }
297
298 /// Adds new Domain Integrator.
300 LinearFormIntegrator *lfi_imag);
301
302 /// Adds new Domain Integrator, restricted to the given attributes.
304 LinearFormIntegrator *lfi_imag,
305 Array<int> &elem_attr_marker);
306
307 /// Adds new Boundary Integrator.
309 LinearFormIntegrator *lfi_imag);
310
311 /** @brief Add new Boundary Integrator, restricted to the given boundary
312 attributes.
313
314 Assumes ownership of @a lfi_real and @a lfi_imag.
315
316 The array @a bdr_attr_marker is stored internally as a pointer to the
317 given Array<int> object. */
319 LinearFormIntegrator *lfi_imag,
320 Array<int> &bdr_attr_marker);
321
322 /// Adds new Boundary Face Integrator. Assumes ownership of @a lfi.
324 LinearFormIntegrator *lfi_imag);
325
326 /** @brief Add new Boundary Face Integrator, restricted to the given boundary
327 attributes.
328
329 Assumes ownership of @a lfi_real and @a lfi_imag.
330
331 The array @a bdr_attr_marker is stored internally as a pointer to the
332 given Array<int> object. */
334 LinearFormIntegrator *lfi_imag,
335 Array<int> &bdr_attr_marker);
336
337 FiniteElementSpace *FESpace() const { return lfr->FESpace(); }
338
339 LinearForm & real() { return *lfr; }
340 LinearForm & imag() { return *lfi; }
341 const LinearForm & real() const { return *lfr; }
342 const LinearForm & imag() const { return *lfi; }
343
344 /// Update the memory location of the real and imaginary LinearForm @a lfr
345 /// and @a lfi to match the ComplexLinearForm.
346 void Sync() { lfr->SyncMemory(*this); lfi->SyncMemory(*this); }
347
348 /// Update the alias memory location of the real and imaginary LinearForm @a
349 /// lfr and @a lfi to match the ComplexLinearForm.
350 void SyncAlias() { lfr->SyncAliasMemory(*this); lfi->SyncAliasMemory(*this); }
351
352 void Update();
354
355 /// Assembles the linear form i.e. sums over all domain/bdr integrators.
356 void Assemble();
357
358 std::complex<real_t> operator()(const ComplexGridFunction &gf) const;
359};
360
361
362/** Class for sesquilinear form
363
364 A sesquilinear form is a generalization of a bilinear form to complex-valued
365 fields. Sesquilinear forms are linear in the second argument but the first
366 argument involves a complex conjugate in the sense that:
367
368 a(alpha u, beta v) = conj(alpha) beta a(u, v)
369
370 The @a convention argument in the class's constructor is documented in the
371 mfem::ComplexOperator class found in linalg/complex_operator.hpp.
372
373 When supplying integrators to the SesquilinearForm either the real or
374 imaginary integrator can be NULL. This indicates that the corresponding
375 portion of the complex-valued material coefficient is equal to zero.
376*/
378{
379private:
381
382 /** This data member allows one to specify what should be done to the
383 diagonal matrix entries and corresponding RHS values upon elimination of
384 the constrained DoFs. */
386
387 BilinearForm *blfr;
388 BilinearForm *blfi;
389
390 /* These methods check if the real/imag parts of the sesquilinear form are
391 not empty */
392 bool RealInteg();
393 bool ImagInteg();
394
395 void BuildComplexOperator(OperatorHandle &A_r, OperatorHandle &A_i,
396 OperatorHandle &A) const;
397
398public:
401 convention = ComplexOperator::HERMITIAN);
402 /** @brief Create a SesquilinearForm on the FiniteElementSpace @a fes, using
403 the same integrators as the BilinearForms @a bfr and @a bfi .
404
405 The pointer @a fes is not owned by the newly constructed object.
406
407 The integrators are copied as pointers and they are not owned by the
408 newly constructed SesquilinearForm. */
411 convention = ComplexOperator::HERMITIAN);
412
415 convention) { conv = convention; }
416
417 /// Set the desired assembly level.
418 /** Valid choices are:
419
420 - AssemblyLevel::LEGACY (default)
421 - AssemblyLevel::FULL
422 - AssemblyLevel::PARTIAL
423 - AssemblyLevel::ELEMENT
424 - AssemblyLevel::NONE
425
426 This method must be called before assembly. */
427 void SetAssemblyLevel(AssemblyLevel assembly_level)
428 {
429 blfr->SetAssemblyLevel(assembly_level);
430 blfi->SetAssemblyLevel(assembly_level);
431 }
432
433 BilinearForm & real() { return *blfr; }
434 BilinearForm & imag() { return *blfi; }
435 const BilinearForm & real() const { return *blfr; }
436 const BilinearForm & imag() const { return *blfi; }
437
438 /// Adds new Domain Integrator.
440 BilinearFormIntegrator *bfi_imag);
441
442 /// Adds new Domain Integrator, restricted to the given attributes.
444 BilinearFormIntegrator *bfi_imag,
445 Array<int> &elem_marker);
446
447 /// Adds new Boundary Integrator.
449 BilinearFormIntegrator *bfi_imag);
450
451 /// Adds new Boundary Integrator, restricted to specific boundary attributes.
453 BilinearFormIntegrator *bfi_imag,
454 Array<int> &bdr_marker);
455
456 /// Adds new interior Face Integrator. Assumes ownership of @a bfi.
458 BilinearFormIntegrator *bfi_imag);
459
460 /// Adds new boundary Face Integrator. Assumes ownership of @a bfi.
462 BilinearFormIntegrator *bfi_imag);
463
464 /** @brief Adds new boundary Face Integrator, restricted to specific boundary
465 attributes.
466
467 Assumes ownership of @a bfi.
468
469 The array @a bdr_marker is stored internally as a pointer to the given
470 Array<int> object. */
472 BilinearFormIntegrator *bfi_imag,
473 Array<int> &bdr_marker);
474
475 /// Assemble the local matrix
476 void Assemble(int skip_zeros = 1);
477
478 /// Finalizes the matrix initialization.
479 void Finalize(int skip_zeros = 1);
480
481 /// Returns the matrix assembled on the true dofs, i.e. P^t A P.
482 /** The returned matrix has to be deleted by the caller. */
484
485 /// Return the parallel FE space associated with the ParBilinearForm.
486 FiniteElementSpace *FESpace() const { return blfr->FESpace(); }
487
489 OperatorHandle &A, Vector &X, Vector &B,
490 int copy_interior = 0);
491
493 OperatorHandle &A);
494
495 /** Call this method after solving a linear system constructed using the
496 FormLinearSystem method to recover the solution as a ParGridFunction-size
497 vector in x. Use the same arguments as in the FormLinearSystem call. */
498 virtual void RecoverFEMSolution(const Vector &X, const Vector &b, Vector &x);
499
500 virtual void Update(FiniteElementSpace *nfes = NULL);
501
502 /// Sets diagonal policy used upon construction of the linear system
504
505 /// Returns the diagonal policy of the sesquilinear form
506 Matrix::DiagonalPolicy GetDiagonalPolicy() const {return diag_policy;}
507
508 virtual ~SesquilinearForm();
509};
510
511/** Class for a mixed sesquilinear form
512
513 A mixed sesquilinear form is a generalization of a mixed bilinear form to
514 complex-valued fields. Mixed sesquilinear forms are linear in the second
515 argument but the first argument involves a complex conjugate in the sense
516 that:
517
518 a(alpha u, beta v) = conj(alpha) beta a(u, v)
519
520 The @a convention argument in the class's constructor is documented in the
521 mfem::ComplexOperator class found in linalg/complex_operator.hpp.
522
523 When supplying integrators to the MixedSesquilinearForm either the real or
524 imaginary integrator can be NULL. This indicates that the corresponding
525 portion of the complex-valued material coefficient is equal to zero.
526*/
528{
529private:
531
532 MixedBilinearForm * mblfr;
533 MixedBilinearForm * mblfi;
534
535 /* These methods check if the real/imag parts of the sesqulinear form are not
536 empty */
537 bool RealInteg();
538 bool ImagInteg();
539
540public:
542 FiniteElementSpace * trial_fes,
543 FiniteElementSpace * test_fes,
545
546 /** @brief Create a MixedSesquilinearForm on the given trial and test
547 FiniteElementSpaces, using the same integrators as the
548 MixedBilinearForms @a bfr and @a bfi.
549
550 The FiniteElementSpace pointers are not owned by the newly constructed
551 object.
552
553 The integrators are copied as pointers and they are not owned by the
554 newly constructed MixedSesquilinearForm. */
556 FiniteElementSpace * trial_fes,
557 FiniteElementSpace * test_fes,
558 MixedBilinearForm * bfr,
559 MixedBilinearForm * bfi,
561
563 void SetConvention(const ComplexOperator::Convention & convention) { conv = convention; }
564
565 /// Set the desired assembly level.
566 /** Valid choices are:
567
568 - AssemblyLevel::LEGACY (default)
569 - AssemblyLevel::FULL
570 - AssemblyLevel::PARTIAL
571 - AssemblyLevel::ELEMENT
572 - AssemblyLevel::NONE
573
574 This method must be called before assembly. */
575 void SetAssemblyLevel(AssemblyLevel assembly_level)
576 {
577 mblfr->SetAssemblyLevel(assembly_level);
578 mblfi->SetAssemblyLevel(assembly_level);
579 }
580
581 MixedBilinearForm & real() { return *mblfr; }
582 MixedBilinearForm & imag() { return *mblfi; }
583 const MixedBilinearForm & real() const { return *mblfr; }
584 const MixedBilinearForm & imag() const { return *mblfi; }
585
586 /// Adds new Domain Integrator.
588 BilinearFormIntegrator * bfi_imag);
589
590 /// Adds new Domain Integrator, restricted to specific attributes.
592 BilinearFormIntegrator * bfi_imag,
593 Array<int> & elem_marker);
594
595 /// Adds new Boundary Integrator.
597 BilinearFormIntegrator * bfi_imag);
598
599 /** @brief Adds new boundary Integrator, restricted to specific boundary
600 attributes.
601
602 Assumes ownership of @a bfi.
603
604 The mfem::array @a bdr_marker is stored internally as a pointer to the given
605 mfem::Array<int> object. */
607 BilinearFormIntegrator * bfi_imag,
608 Array<int> & bdr_marker);
609
610 /// Adds new interior Face Integrator. Assumes ownership of @a bfi.
612 BilinearFormIntegrator * bfi_imag);
613
614 /// Adds new boundary Face Integrator. Assumes ownership of @a bfi.
616 BilinearFormIntegrator * bfi_imag);
617
618 /** @brief Adds new boundary Face Integrator, restricted to specific boundary
619 attributes.
620
621 Assumes ownership of @a bfi.
622
623 The mfem::array @a bdr_marker is stored internally as a pointer to the given
624 mfem::Array<int> object. */
626 BilinearFormIntegrator * bfi_imag,
627 Array<int> & bdr_marker);
628
629 /** @brief Add a trace face integrator. Assumes ownership of @a bfi.
630
631 This type of integrator assembles terms over all faces of the mesh using
632 the face FE from the trial space and the two adjacent volume FEs from
633 the test space. */
635 BilinearFormIntegrator * bfi_imag);
636
637 /// Adds a boundary trace face integrator. Assumes ownership of @a bfi.
639 BilinearFormIntegrator * bfi_imag);
640
641 /// Adds a boundary trace face integrator. Assumes ownership of @a bfi.
643 BilinearFormIntegrator * bfi_imag,
644 Array<int> &bdr_marker);
645
646 /// Assemble the local matrix
647 void Assemble(int skip_zeros = 1);
648
649 /// Finalizes the matrix initialization.
650 void Finalize(int skip_zeros = 1);
651
652 /// Updates the internal mixed forms with the new finite element space.
653 virtual void Update();
654
655 /** @brief Return a ComplexSparseMatrix wrapping the local (L-dof) real
656 and imaginary matrices of the form.
657
658 The returned wrapper has to be deleted by the caller, but it does not
659 own the wrapped real and imaginary matrices, which remain owned by
660 this form. */
662
663 /// Return the trial FE space associated with the MixedSesquilinearForm.
665
666 /// Read-only access to the associated trial FiniteElementSpace.
667 const FiniteElementSpace *TrialFESpace() const { return mblfr->TrialFESpace(); }
668
669 /// Return the test FE space associated with the MixedSesquilinearForm.
671
672 /// Read-only access to the associated test FiniteElementSpace.
673 const FiniteElementSpace *TestFESpace() const { return mblfr->TestFESpace(); }
674
675
676 void FormRectangularLinearSystem(const Array<int> & ess_trial_tdof_list,
677 const Array<int> & ess_test_tdof_list,
678 Vector & x,
679 Vector & b,
680 OperatorHandle & A,
681 Vector & X,
682 Vector & B);
683
684 void FormRectangularSystemMatrix(const Array<int> & ess_trial_tdof_list,
685 const Array<int> & ess_test_tdof_list,
686 OperatorHandle & A);
687
688 virtual ~MixedSesquilinearForm();
689};
690
691#ifdef MFEM_USE_MPI
692
693/// Class for parallel complex-valued grid function - real + imaginary part
694/// Vector with associated parallel FE space.
696{
697private:
698 ParGridFunction * pgfr;
699 ParGridFunction * pgfi;
700
701protected:
702 /// FE space on which the grid function lives. Owned if #fec_owned
703 /// is not NULL.
705
706 /** @brief Used when the grid function is read from a file. It can also be
707 set explicitly, see MakeOwner().
708
709 If not NULL, this pointer is owned by the ParComplexGridFunction. */
711
712 long fes_sequence; // see FiniteElementSpace::sequence, Mesh::sequence
713
714 void Destroy();
715
716public:
717
718 /** @brief Construct a ParComplexGridFunction associated with the
719 ParFiniteElementSpace @a *pf. */
721
722 /** @brief Construct a ParComplexGridFunction on a given ParMesh,
723 @a pmesh, reading from an std::istream.
724
725 In the process, a ParFiniteElementSpace and a FiniteElementCollection are
726 constructed. The new ParComplexGridFunction assumes ownership of both. */
727 ParComplexGridFunction(ParMesh *pmesh, std::istream &input);
728
729 void Update();
730
731 /** Return update counter, similar to Mesh::GetSequence(). Used to
732 check if it is up to date with the space. */
733 long GetSequence() const { return fes_sequence; }
734
735 /// Make the ParComplexGridFunction the owner of #fec_owned and #pfes.
736 /** If the new FiniteElementCollection, @a fec_, is NULL, ownership
737 of #fec_owned and #pfes is taken away. */
739
740 /// Returns a pointer to the FiniteElementCollection used to
741 /// construct this ParComplexGridFunction if this class owns that
742 /// object. Otherwise this function will return NULL.
744
745 /// Shortcut for calling FiniteElementSpace::GetVectorDim() on the
746 /// underlying #pfes
747 int VectorDim() const;
748
749 /// Assign constant values to the ParComplexGridFunction data.
750 ParComplexGridFunction &operator=(const std::complex<real_t> & value)
751 { *pgfr = value.real(); *pgfi = value.imag(); return *this; }
752
753 virtual void ProjectCoefficient(Coefficient &real_coeff,
754 Coefficient &imag_coeff);
755 virtual void ProjectCoefficient(VectorCoefficient &real_vcoeff,
756 VectorCoefficient &imag_vcoeff);
757
758 virtual void ProjectBdrCoefficient(Coefficient &real_coeff,
759 Coefficient &imag_coeff,
760 Array<int> &attr);
761 virtual void ProjectBdrCoefficientNormal(VectorCoefficient &real_coeff,
762 VectorCoefficient &imag_coeff,
763 Array<int> &attr);
764 virtual void ProjectBdrCoefficientTangent(VectorCoefficient &real_coeff,
765 VectorCoefficient &imag_coeff,
766 Array<int> &attr);
767
768 void Distribute(const Vector *tv);
769 void Distribute(const Vector &tv) { Distribute(&tv); }
770
771 /// Returns the vector restricted to the true dofs.
772 void ParallelProject(Vector &tv) const;
773
775 const FiniteElementSpace *FESpace() const { return pfes; }
776
778 const ParFiniteElementSpace *ParFESpace() const { return pfes; }
779
780 ParGridFunction & real() { return *pgfr; }
781 ParGridFunction & imag() { return *pgfi; }
782 const ParGridFunction & real() const { return *pgfr; }
783 const ParGridFunction & imag() const { return *pgfi; }
784
785 /// Update the memory location of the real and imaginary ParGridFunction @a
786 /// pgfr and @a pgfi to match the ParComplexGridFunction.
787 void Sync() { pgfr->SyncMemory(*this); pgfi->SyncMemory(*this); }
788
789 /// Update the alias memory location of the real and imaginary
790 /// ParGridFunction @a pgfr and @a pgfi to match the ParComplexGridFunction.
792 { pgfr->SyncAliasMemory(*this); pgfi->SyncAliasMemory(*this); }
793
794 /// @brief Returns ||u_ex - u_h||_L2 in parallel for complex-valued
795 /// scalar fields
796 ///
797 /// @see GridFunction::ComputeL2Error(Coefficient &exsol,
798 /// const IntegrationRule *irs[],
799 /// const Array<int> *elems) const
800 /// for more detailed documentation.
802 const IntegrationRule *irs[] = NULL,
803 Array<int> *elems = NULL) const
804 {
805 real_t err_r = pgfr->ComputeL2Error(exsolr, irs, elems);
806 real_t err_i = pgfi->ComputeL2Error(exsoli, irs, elems);
807 return hypot(err_r, err_i);
808 }
809
810 /// @brief Returns ||u_ex - u_h||_L2 in parallel for complex-valued
811 /// vector fields
812 ///
813 /// @see GridFunction::ComputeL2Error(VectorCoefficient &exsol,
814 /// const IntegrationRule *irs[],
815 /// const Array<int> *elems) const
816 /// for more detailed documentation.
818 VectorCoefficient &exsoli,
819 const IntegrationRule *irs[] = NULL,
820 Array<int> *elems = NULL) const
821 {
822 real_t err_r = pgfr->ComputeL2Error(exsolr, irs, elems);
823 real_t err_i = pgfi->ComputeL2Error(exsoli, irs, elems);
824 return hypot(err_r, err_i);
825 }
826
827 /// Save the local portion of the ParComplexGridFunction
828 /** This differs from the serial ComplexGridFunction::Save in that it
829 takes into account the signs of the local dofs. */
830 void Save(std::ostream &out) const;
831
832 /// Save the ParComplexGridFunction to files
833 /** Saves one file for each MPI rank. The files will be given suffixes
834 according to the MPI rank. The given @a precision will be used for ASCII
835 output. */
836 void Save(const char *fname, int precision=16) const;
837
838 /// Destroys grid function.
840
841};
842
843/** Overload operator<< for std::ostream and ParComplexGridFunction */
844std::ostream &operator<<(std::ostream &out, const ParComplexGridFunction &sol);
845
846/** Class for a complex-valued, parallel linear form
847
848 The @a convention argument in the class's constructor is documented in the
849 mfem::ComplexOperator class found in linalg/complex_operator.hpp.
850
851 When supplying integrators to the ParComplexLinearForm either the real or
852 imaginary integrator can be NULL. This indicates that the corresponding
853 portion of the complex-valued field is equal to zero.
854 */
856{
857private:
859
860protected:
863
865
866public:
867
870 convention = ComplexOperator::HERMITIAN);
871
872 /** @brief Create a ParComplexLinearForm on the ParFiniteElementSpace @a pf,
873 using the same integrators as the LinearForms @a plf_r (real) and
874 @a plf_i (imag).
875
876 The pointer @a fes is not owned by the newly constructed object.
877
878 The integrators are copied as pointers and they are not owned by the newly
879 constructed ParComplexLinearForm. */
881 ParLinearForm *plf_i,
883 convention = ComplexOperator::HERMITIAN);
884
885 virtual ~ParComplexLinearForm();
886
887 /// Assign constant values to the ParComplexLinearForm data.
888 ParComplexLinearForm &operator=(const std::complex<real_t> & value)
889 { *plfr = value.real(); *plfi = value.imag(); return *this; }
890
893 convention) { conv = convention; }
894
895 /// Adds new Domain Integrator.
897 LinearFormIntegrator *lfi_imag);
898
899 /// Adds new Domain Integrator, restricted to specific attributes.
901 LinearFormIntegrator *lfi_imag,
902 Array<int> &elem_attr_marker);
903
904 /// Adds new Boundary Integrator.
906 LinearFormIntegrator *lfi_imag);
907
908 /** @brief Add new Boundary Integrator, restricted to the given boundary
909 attributes.
910
911 Assumes ownership of @a lfi_real and @a lfi_imag.
912
913 The array @a bdr_attr_marker is stored internally as a pointer to the
914 given Array<int> object. */
916 LinearFormIntegrator *lfi_imag,
917 Array<int> &bdr_attr_marker);
918
919 /// Adds new Boundary Face Integrator. Assumes ownership of @a lfi.
921 LinearFormIntegrator *lfi_imag);
922
923 /** @brief Add new Boundary Face Integrator, restricted to the given boundary
924 attributes.
925
926 Assumes ownership of @a lfi_real and @a lfi_imag.
927
928 The array @a bdr_attr_marker is stored internally as a pointer to the
929 given Array<int> object. */
931 LinearFormIntegrator *lfi_imag,
932 Array<int> &bdr_attr_marker);
933
935
936 ParLinearForm & real() { return *plfr; }
937 ParLinearForm & imag() { return *plfi; }
938 const ParLinearForm & real() const { return *plfr; }
939 const ParLinearForm & imag() const { return *plfi; }
940
941 /// Update the memory location of the real and imaginary ParLinearForm @a lfr
942 /// and @a lfi to match the ParComplexLinearForm.
943 void Sync() { plfr->SyncMemory(*this); plfi->SyncMemory(*this); }
944
945 /// Update the alias memory location of the real and imaginary ParLinearForm
946 /// @a plfr and @a plfi to match the ParComplexLinearForm.
947 void SyncAlias() { plfr->SyncAliasMemory(*this); plfi->SyncAliasMemory(*this); }
948
949 void Update(ParFiniteElementSpace *pf = NULL);
950
951 /// Assembles the linear form i.e. sums over all domain/bdr integrators.
952 void Assemble();
953
954 /// Assemble the vector on the true dofs, i.e. P^t v.
955 void ParallelAssemble(Vector &tv);
956
957 /// Returns the vector assembled on the true dofs, i.e. P^t v.
959
960 std::complex<real_t> operator()(const ParComplexGridFunction &gf) const;
961
962};
963
964/** Class for a parallel sesquilinear form
965
966 A sesquilinear form is a generalization of a bilinear form to complex-valued
967 fields. Sesquilinear forms are linear in the second argument but the
968 first argument involves a complex conjugate in the sense that:
969
970 a(alpha u, beta v) = conj(alpha) beta a(u, v)
971
972 The @a convention argument in the class's constructor is documented in the
973 mfem::ComplexOperator class found in linalg/complex_operator.hpp.
974
975 When supplying integrators to the ParSesquilinearForm either the real or
976 imaginary integrator can be NULL. This indicates that the corresponding
977 portion of the complex-valued material coefficient is equal to zero.
978*/
980{
981private:
983
984 ParBilinearForm *pblfr;
985 ParBilinearForm *pblfi;
986
987 /* These methods check if the real/imag parts of the sesqulinear form are not
988 empty */
989 bool RealInteg();
990 bool ImagInteg();
991
992 void SetImaginaryEssentialDiagonalToZero(
994
995 void BuildComplexOperator(OperatorHandle &A_r, OperatorHandle &A_i,
996 OperatorHandle &A) const;
997
998public:
1001 convention = ComplexOperator::HERMITIAN);
1002
1003 /** @brief Create a ParSesquilinearForm on the ParFiniteElementSpace @a pf,
1004 using the same integrators as the ParBilinearForms @a pbfr and @a pbfi .
1005
1006 The pointer @a pf is not owned by the newly constructed object.
1007
1008 The integrators are copied as pointers and they are not owned by the
1009 newly constructed ParSesquilinearForm. */
1011 ParBilinearForm *pbfi,
1013 convention = ComplexOperator::HERMITIAN);
1014
1017 convention) { conv = convention; }
1018
1019 /// Set the desired assembly level.
1020 /** Valid choices are:
1021
1022 - AssemblyLevel::LEGACY (default)
1023 - AssemblyLevel::FULL
1024 - AssemblyLevel::PARTIAL
1025 - AssemblyLevel::ELEMENT
1026 - AssemblyLevel::NONE
1027
1028 This method must be called before assembly. */
1029 void SetAssemblyLevel(AssemblyLevel assembly_level)
1030 {
1031 pblfr->SetAssemblyLevel(assembly_level);
1032 pblfi->SetAssemblyLevel(assembly_level);
1033 }
1034
1035 ParBilinearForm & real() { return *pblfr; }
1036 ParBilinearForm & imag() { return *pblfi; }
1037 const ParBilinearForm & real() const { return *pblfr; }
1038 const ParBilinearForm & imag() const { return *pblfi; }
1039
1040 /// Adds new Domain Integrator.
1042 BilinearFormIntegrator *bfi_imag);
1043
1044 /// Adds new Domain Integrator, restricted to specific attributes.
1046 BilinearFormIntegrator *bfi_imag,
1047 Array<int> &elem_marker);
1048
1049 /// Adds new Boundary Integrator.
1051 BilinearFormIntegrator *bfi_imag);
1052
1053 /** @brief Adds new boundary Integrator, restricted to specific boundary
1054 attributes.
1055
1056 Assumes ownership of @a bfi.
1057
1058 The array @a bdr_marker is stored internally as a pointer to the given
1059 Array<int> object. */
1061 BilinearFormIntegrator *bfi_imag,
1062 Array<int> &bdr_marker);
1063
1064 /// Adds new interior Face Integrator. Assumes ownership of @a bfi.
1066 BilinearFormIntegrator *bfi_imag);
1067
1068 /// Adds new boundary Face Integrator. Assumes ownership of @a bfi.
1070 BilinearFormIntegrator *bfi_imag);
1071
1072 /** @brief Adds new boundary Face Integrator, restricted to specific boundary
1073 attributes.
1074
1075 Assumes ownership of @a bfi.
1076
1077 The array @a bdr_marker is stored internally as a pointer to the given
1078 Array<int> object. */
1080 BilinearFormIntegrator *bfi_imag,
1081 Array<int> &bdr_marker);
1082
1083 /// Assemble the local matrix
1084 void Assemble(int skip_zeros = 1);
1085
1086 /// Finalizes the matrix initialization.
1087 void Finalize(int skip_zeros = 1);
1088
1089 /// Returns the matrix assembled on the true dofs, i.e. P^t A P.
1090 /** The returned matrix has to be deleted by the caller. */
1092
1093 /// Return the parallel FE space associated with the ParBilinearForm.
1094 ParFiniteElementSpace *ParFESpace() const { return pblfr->ParFESpace(); }
1095
1097 OperatorHandle &A, Vector &X, Vector &B,
1098 int copy_interior = 0);
1099
1101 OperatorHandle &A);
1102
1103 /** Call this method after solving a linear system constructed using the
1104 FormLinearSystem method to recover the solution as a ParGridFunction-size
1105 vector in x. Use the same arguments as in the FormLinearSystem call. */
1106 virtual void RecoverFEMSolution(const Vector &X, const Vector &b, Vector &x);
1107
1108 virtual void Update(FiniteElementSpace *nfes = NULL);
1109
1110 virtual ~ParSesquilinearForm();
1111};
1112
1113/** Class for a parallel mixed sesquilinear form
1114
1115 A mixed sesquilinear form is a generalization of a mixed bilinear form to
1116 complex-valued fields. Mixed sesquilinear forms are linear in the second
1117 argument but the first argument involves a complex conjugate in the sense
1118 that:
1119
1120 a(alpha u, beta v) = conj(alpha) beta a(u, v)
1121
1122 The @a convention argument in the class's constructor is documented in the
1123 mfem::ComplexOperator class found in linalg/complex_operator.hpp.
1124
1125 When supplying integrators to the ParMixedSesquilinearForm either the real
1126 or imaginary integrator can be NULL. This indicates that the corresponding
1127 portion of the complex-valued material coefficient is equal to zero.
1128*/
1130{
1131private:
1133
1134 ParMixedBilinearForm * pmblfr;
1135 ParMixedBilinearForm * pmblfi;
1136
1137 /* These methods check if the real/imag parts of the sesqulinear form are
1138 not empty */
1139 bool RealInteg();
1140 bool ImagInteg();
1141
1142public:
1144 ParFiniteElementSpace * trial_fes,
1145 ParFiniteElementSpace * test_fes,
1147
1148 /** @brief Create a ParMixedSesquilinearForm on the given trial and test
1149 ParFiniteElementSpaces, using the same integrators as the
1150 ParMixedBilinearForms @a pbfr and @a pbfi.
1151
1152 The ParFiniteElementSpace pointers are not owned by the newly
1153 constructed object.
1154
1155 The integrators are copied as pointers and they are not owned by the
1156 newly constructed ParMixedSesquilinearForm. */
1158 ParFiniteElementSpace * trial_fes,
1159 ParFiniteElementSpace * test_fes,
1160 ParMixedBilinearForm * pbfr,
1161 ParMixedBilinearForm * pbfi,
1163
1165 void SetConvention(const ComplexOperator::Convention & convention) { conv = convention; }
1166
1167 /// Set the desired assembly level.
1168 /** Valid choices are:
1169
1170 - AssemblyLevel::LEGACY (default)
1171 - AssemblyLevel::FULL
1172 - AssemblyLevel::PARTIAL
1173 - AssemblyLevel::ELEMENT
1174 - AssemblyLevel::NONE
1175
1176 This method must be called before assembly. */
1177 void SetAssemblyLevel(AssemblyLevel assembly_level)
1178 {
1179 pmblfr->SetAssemblyLevel(assembly_level);
1180 pmblfi->SetAssemblyLevel(assembly_level);
1181 }
1182
1183 ParMixedBilinearForm & real() { return *pmblfr; }
1184 ParMixedBilinearForm & imag() { return *pmblfi; }
1185 const ParMixedBilinearForm & real() const { return *pmblfr; }
1186 const ParMixedBilinearForm & imag() const { return *pmblfi; }
1187
1188 /// Adds new Domain Integrator.
1190 BilinearFormIntegrator * bfi_imag);
1191
1192 /// Adds new Domain Integrator, restricted to specific attributes.
1194 BilinearFormIntegrator * bfi_imag,
1195 Array<int> & elem_marker);
1196
1197 /// Adds new Boundary Integrator.
1199 BilinearFormIntegrator * bfi_imag);
1200
1201 /** @brief Adds new boundary Integrator, restricted to specific boundary
1202 attributes.
1203
1204 Assumes ownership of @a bfi.
1205
1206 The mfem::array @a bdr_marker is stored internally as a pointer to the given
1207 mfem::Array<int> object. */
1209 BilinearFormIntegrator * bfi_imag,
1210 Array<int> & bdr_marker);
1211
1212 /// Adds new interior Face Integrator. Assumes ownership of @a bfi.
1214 BilinearFormIntegrator * bfi_imag);
1215
1216 /// Adds new boundary Face Integrator. Assumes ownership of @a bfi.
1218 BilinearFormIntegrator * bfi_imag);
1219
1220 /** @brief Adds new boundary Face Integrator, restricted to specific boundary
1221 attributes.
1222
1223 Assumes ownership of @a bfi.
1224
1225 The mfem::array @a bdr_marker is stored internally as a pointer to the given
1226 mfem::Array<int> object. */
1228 BilinearFormIntegrator * bfi_imag,
1229 Array<int> & bdr_marker);
1230
1231 /** @brief Add a trace face integrator. Assumes ownership of @a bfi.
1232
1233 This type of integrator assembles terms over all faces of the mesh using
1234 the face FE from the trial space and the two adjacent volume FEs from
1235 the test space. */
1237 BilinearFormIntegrator * bfi_imag);
1238
1239 /// Adds a boundary trace face integrator. Assumes ownership of @a bfi.
1241 BilinearFormIntegrator * bfi_imag);
1242
1243 /// Adds a boundary trace face integrator. Assumes ownership of @a bfi.
1245 BilinearFormIntegrator * bfi_imag,
1246 Array<int> &bdr_marker);
1247
1248 /// Assemble the local matrix
1249 void Assemble(int skip_zeros = 1);
1250
1251 /// Finalizes the matrix initialization.
1252 void Finalize(int skip_zeros = 1);
1253
1254 /// Updates the internal mixed forms with the new finite element space.
1255 virtual void Update();
1256
1257 /// Returns the matrix assembled on the true dofs, i.e. P^t A P.
1258 /** The returned matrix has to be deleted by the caller. */
1260
1261 void FormRectangularLinearSystem(const Array<int> & ess_trial_tdof_list,
1262 const Array<int> & ess_test_tdof_list,
1263 Vector & x,
1264 Vector & b,
1265 OperatorHandle & A,
1266 Vector & X,
1267 Vector & B);
1268
1269 void FormRectangularSystemMatrix(const Array<int> & ess_trial_tdof_list,
1270 const Array<int> & ess_test_tdof_list,
1271 OperatorHandle & A);
1272
1273 virtual ~ParMixedSesquilinearForm();
1274};
1275
1276#endif // MFEM_USE_MPI
1277
1278}
1279
1280#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().
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.
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.
ComplexGridFunction & operator=(const ComplexGridFunction &rhs)
Copy assignment. Only the data of the base class Vector is copied.
virtual void Save(std::ostream &out) const
Save the ComplexGridFunction to an output stream.
const GridFunction & real() const
ComplexGridFunction & operator=(const Vector &v)
Copy the data from v.
virtual real_t ComputeMaxError(Coefficient &exsolr, Coefficient &exsoli, const IntegrationRule *irs[]=NULL) const
Returns Max|u_ex - u_h| error for complex-valued H1 or L2 elements.
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:210
int GetVSize() const
Return the number of vector dofs, i.e. GetNDofs() x GetVDim().
Definition fespace.hpp:824
Class for grid function - Vector with associated FE space.
Definition gridfunc.hpp:53
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:96
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:67
void SetAssemblyLevel(AssemblyLevel assembly_level)
Set the desired assembly level. The default is AssemblyLevel::LEGACY.
FiniteElementSpace * TestFESpace()
Return the test FE space associated with the BilinearForm.
FiniteElementSpace * TrialFESpace()
Return the trial FE space associated with the BilinearForm.
void AddDomainIntegrator(BilinearFormIntegrator *bfi_real, BilinearFormIntegrator *bfi_imag)
Adds new Domain Integrator.
void AddBdrTraceFaceIntegrator(BilinearFormIntegrator *bfi_real, BilinearFormIntegrator *bfi_imag)
Adds a boundary trace face integrator. Assumes ownership of bfi.
void FormRectangularLinearSystem(const Array< int > &ess_trial_tdof_list, const Array< int > &ess_test_tdof_list, Vector &x, Vector &b, OperatorHandle &A, Vector &X, Vector &B)
const MixedBilinearForm & imag() const
const FiniteElementSpace * TestFESpace() const
Read-only access to the associated test FiniteElementSpace.
void AddInteriorFaceIntegrator(BilinearFormIntegrator *bfi_real, BilinearFormIntegrator *bfi_imag)
Adds new interior Face Integrator. Assumes ownership of bfi.
void SetConvention(const ComplexOperator::Convention &convention)
MixedSesquilinearForm(FiniteElementSpace *trial_fes, FiniteElementSpace *test_fes, ComplexOperator::Convention convention=ComplexOperator::HERMITIAN)
void FormRectangularSystemMatrix(const Array< int > &ess_trial_tdof_list, const Array< int > &ess_test_tdof_list, OperatorHandle &A)
const FiniteElementSpace * TrialFESpace() const
Read-only access to the associated trial FiniteElementSpace.
const MixedBilinearForm & real() const
MixedBilinearForm & real()
void AddBoundaryIntegrator(BilinearFormIntegrator *bfi_real, BilinearFormIntegrator *bfi_imag)
Adds new Boundary Integrator.
FiniteElementSpace * TrialFESpace()
Return the trial FE space associated with the MixedSesquilinearForm.
virtual void Update()
Updates the internal mixed forms with the new finite element space.
void Assemble(int skip_zeros=1)
Assemble the local matrix.
void SetAssemblyLevel(AssemblyLevel assembly_level)
Set the desired assembly level.
void AddBdrFaceIntegrator(BilinearFormIntegrator *bfi_real, BilinearFormIntegrator *bfi_imag)
Adds new boundary Face Integrator. Assumes ownership of bfi.
ComplexOperator::Convention GetConvention() const
MixedBilinearForm & imag()
FiniteElementSpace * TestFESpace()
Return the test FE space associated with the MixedSesquilinearForm.
ComplexSparseMatrix * AssembleComplexSparseMatrix()
Return a ComplexSparseMatrix wrapping the local (L-dof) real and imaginary matrices of the form.
void Finalize(int skip_zeros=1)
Finalizes the matrix initialization.
void AddTraceFaceIntegrator(BilinearFormIntegrator *bfi_real, BilinearFormIntegrator *bfi_imag)
Add a trace face integrator. Assumes ownership of bfi.
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:50
@ DIAG_ONE
Set the diagonal value to one.
Definition operator.hpp:52
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:35
Class for parallel bilinear form using different test and trial FE spaces.
ComplexHypreParMatrix * ParallelAssemble()
Returns the matrix assembled on the true dofs, i.e. P^t A P.
void AddBdrFaceIntegrator(BilinearFormIntegrator *bfi_real, BilinearFormIntegrator *bfi_imag)
Adds new boundary Face Integrator. Assumes ownership of bfi.
void SetAssemblyLevel(AssemblyLevel assembly_level)
Set the desired assembly level.
ParMixedSesquilinearForm(ParFiniteElementSpace *trial_fes, ParFiniteElementSpace *test_fes, ComplexOperator::Convention convention=ComplexOperator::HERMITIAN)
void FormRectangularLinearSystem(const Array< int > &ess_trial_tdof_list, const Array< int > &ess_test_tdof_list, Vector &x, Vector &b, OperatorHandle &A, Vector &X, Vector &B)
void AddTraceFaceIntegrator(BilinearFormIntegrator *bfi_real, BilinearFormIntegrator *bfi_imag)
Add a trace face integrator. Assumes ownership of bfi.
void Assemble(int skip_zeros=1)
Assemble the local matrix.
void AddInteriorFaceIntegrator(BilinearFormIntegrator *bfi_real, BilinearFormIntegrator *bfi_imag)
Adds new interior Face Integrator. Assumes ownership of bfi.
void FormRectangularSystemMatrix(const Array< int > &ess_trial_tdof_list, const Array< int > &ess_test_tdof_list, OperatorHandle &A)
void SetConvention(const ComplexOperator::Convention &convention)
const ParMixedBilinearForm & real() const
ParMixedBilinearForm & imag()
ParMixedBilinearForm & real()
void AddBdrTraceFaceIntegrator(BilinearFormIntegrator *bfi_real, BilinearFormIntegrator *bfi_imag)
Adds a boundary trace face integrator. Assumes ownership of bfi.
virtual void Update()
Updates the internal mixed forms with the new finite element space.
void Finalize(int skip_zeros=1)
Finalizes the matrix initialization.
const ParMixedBilinearForm & imag() const
void AddBoundaryIntegrator(BilinearFormIntegrator *bfi_real, BilinearFormIntegrator *bfi_imag)
Adds new Boundary Integrator.
ComplexOperator::Convention GetConvention() const
void AddDomainIntegrator(BilinearFormIntegrator *bfi_real, BilinearFormIntegrator *bfi_imag)
Adds new Domain Integrator.
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
int Size() const
Returns the size of the vector.
Definition vector.hpp:234
Vector & operator=(const real_t *v)
Copy Size() entries from v.
Definition vector.cpp:197
const int * ess_tdof_list
HYPRE_Int HYPRE_BigInt
real_t b
Definition lissajous.cpp:42
real_t weight(const Vector &x)
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
constexpr real_t infinity()
Define a shortcut for std::numeric_limits<double>::infinity()
Definition vector.hpp:47
real_t p(const Vector &x, real_t t)
real_t sol(const Vector &x)