LCOV - code coverage report
Current view: top level - fem - gridfunction.hpp (source / functions) Coverage Total Hit
Test: Palace Coverage Report Lines: 100.0 % 6 6
Test Date: 2025-10-23 22:45:05 Functions: - 0 0
Legend: Lines: hit not hit

            Line data    Source code
       1              : // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
       2              : // SPDX-License-Identifier: Apache-2.0
       3              : 
       4              : #ifndef PALACE_FEM_GRIDFUNCTION_HPP
       5              : #define PALACE_FEM_GRIDFUNCTION_HPP
       6              : 
       7              : #include <mfem.hpp>
       8              : 
       9              : namespace palace
      10              : {
      11              : 
      12              : class FiniteElementSpace;
      13              : 
      14              : //
      15              : // A real- or complex-valued grid function represented as two real grid functions, one for
      16              : // each component. This unifies mfem::ParGridFunction and mfem::ParComplexGridFunction, and
      17              : // replaces the latter due to some issues observed with memory aliasing on GPUs.
      18              : //
      19           34 : class GridFunction
      20              : {
      21              : private:
      22              :   mfem::ParGridFunction gfr, gfi;
      23              : 
      24              : public:
      25              :   GridFunction(mfem::ParFiniteElementSpace &fespace, bool complex = false);
      26              :   GridFunction(FiniteElementSpace &fespace, bool complex = false);
      27              : 
      28              :   // Get access to the real and imaginary grid function parts.
      29       106848 :   const mfem::ParGridFunction &Real() const { return gfr; }
      30          153 :   mfem::ParGridFunction &Real() { return gfr; }
      31              :   const mfem::ParGridFunction &Imag() const
      32              :   {
      33              :     MFEM_ASSERT(HasImag(),
      34              :                 "Invalid access of imaginary part of a real-valued GridFunction object!");
      35        86112 :     return gfi;
      36              :   }
      37              :   mfem::ParGridFunction &Imag()
      38              :   {
      39              :     MFEM_ASSERT(HasImag(),
      40              :                 "Invalid access of imaginary part of a real-valued GridFunction object!");
      41           75 :     return gfi;
      42              :   }
      43              : 
      44              :   // Check if the grid function is suited for storing complex-valued fields.
      45              :   bool HasImag() const { return (gfi.ParFESpace() != nullptr); }
      46              : 
      47              :   // Get access to the underlying finite element space (match MFEM interface).
      48              :   mfem::FiniteElementSpace *FESpace() { return gfr.FESpace(); }
      49              :   const mfem::FiniteElementSpace *FESpace() const { return gfr.FESpace(); }
      50              :   mfem::ParFiniteElementSpace *ParFESpace() { return gfr.ParFESpace(); }
      51              :   const mfem::ParFiniteElementSpace *ParFESpace() const { return gfr.ParFESpace(); }
      52              : 
      53              :   // Dimension of the vector field represented by the grid function.
      54            9 :   int VectorDim() const { return gfr.VectorDim(); }
      55              : 
      56              :   // Set all entries equal to s.
      57              :   GridFunction &operator=(std::complex<double> s);
      58              :   GridFunction &operator=(double s)
      59              :   {
      60              :     *this = std::complex<double>(s, 0.0);
      61              :     return *this;
      62              :   }
      63              : 
      64              :   // Scale all entries by s.
      65              :   GridFunction &operator*=(double s);
      66              : 
      67              :   // Transform for space update (for example on mesh change).
      68              :   void Update();
      69              : 
      70              :   // Get the associated MPI communicator.
      71              :   MPI_Comm GetComm() const { return ParFESpace()->GetComm(); }
      72              : };
      73              : 
      74              : }  // namespace palace
      75              : 
      76              : #endif  // PALACE_FEM_GRIDFUNCTION_HPP
        

Generated by: LCOV version 2.0-1