LCOV - code coverage report
Current view: top level - models - lumpedportoperator.hpp (source / functions) Coverage Total Hit
Test: Palace Coverage Report Lines: 75.0 % 4 3
Test Date: 2025-10-23 22:45:05 Functions: 100.0 % 1 1
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_MODELS_LUMPED_PORT_OPERATOR_HPP
       5              : #define PALACE_MODELS_LUMPED_PORT_OPERATOR_HPP
       6              : 
       7              : #include <complex>
       8              : #include <map>
       9              : #include <memory>
      10              : #include <vector>
      11              : #include <mfem.hpp>
      12              : #include "fem/lumpedelement.hpp"
      13              : 
      14              : namespace palace
      15              : {
      16              : 
      17              : class GridFunction;
      18              : class IoData;
      19              : class MaterialOperator;
      20              : class MaterialPropertyCoefficient;
      21              : class SumVectorCoefficient;
      22              : 
      23              : namespace config
      24              : {
      25              : 
      26              : struct LumpedPortData;
      27              : 
      28              : }  // namespace config
      29              : 
      30              : //
      31              : // Helper class for lumped ports in a model.
      32              : //
      33              : class LumpedPortData
      34              : {
      35              : public:
      36              :   // Reference to material property data (not owned).
      37              :   const MaterialOperator &mat_op;
      38              : 
      39              :   // To accommodate multielement lumped ports, a port may be made up of elements with
      40              :   // different attributes and directions which add in parallel.
      41              :   std::vector<std::unique_ptr<LumpedElementData>> elems;
      42              : 
      43              :   // Lumped port properties.
      44              :   double R, L, C;
      45              :   int excitation;
      46              :   bool active;
      47              : 
      48              : private:
      49              :   // Linear forms for postprocessing integrated quantities on the port.
      50              :   mutable std::unique_ptr<mfem::LinearForm> s, v;
      51              : 
      52              :   void InitializeLinearForms(mfem::ParFiniteElementSpace &nd_fespace) const;
      53              : 
      54              : public:
      55              :   LumpedPortData(const config::LumpedPortData &data, const MaterialOperator &mat_op,
      56              :                  const mfem::ParMesh &mesh);
      57              : 
      58          112 :   double GetToSquare(const LumpedElementData &elem) const
      59              :   {
      60          112 :     return elem.GetGeometryWidth() / elem.GetGeometryLength() * elems.size();
      61              :   }
      62              : 
      63           66 :   [[nodiscard]] constexpr bool HasExcitation() const { return excitation != 0; }
      64              : 
      65              :   enum class Branch
      66              :   {
      67              :     TOTAL,
      68              :     R,
      69              :     L,
      70              :     C
      71              :   };
      72              :   std::complex<double> GetCharacteristicImpedance(double omega = 0.0,
      73              :                                                   Branch branch = Branch::TOTAL) const;
      74              : 
      75              :   double GetExcitationPower() const;
      76              :   double GetExcitationVoltage() const;
      77              : 
      78              :   std::complex<double> GetPower(GridFunction &E, GridFunction &B) const;
      79              :   std::complex<double> GetSParameter(GridFunction &E) const;
      80              :   std::complex<double> GetVoltage(GridFunction &E) const;
      81              : };
      82              : 
      83              : //
      84              : // A class handling lumped port boundaries and their postprocessing.
      85              : //
      86            0 : class LumpedPortOperator
      87              : {
      88              : private:
      89              :   // Mapping from port index to data structure containing port information and methods to
      90              :   // calculate circuit properties like voltage and current on lumped or multielement lumped
      91              :   // ports.
      92              :   std::map<int, LumpedPortData> ports;
      93              : 
      94              :   void SetUpBoundaryProperties(const IoData &iodata, const MaterialOperator &mat_op,
      95              :                                const mfem::ParMesh &mesh);
      96              :   void PrintBoundaryInfo(const IoData &iodata, const mfem::ParMesh &mesh);
      97              : 
      98              : public:
      99              :   LumpedPortOperator(const IoData &iodata, const MaterialOperator &mat_op,
     100              :                      const mfem::ParMesh &mesh);
     101              : 
     102              :   // Access data structures for the lumped port with the given index.
     103              :   const LumpedPortData &GetPort(int idx) const;
     104              :   auto begin() const { return ports.begin(); }
     105              :   auto end() const { return ports.end(); }
     106              :   auto rbegin() const { return ports.rbegin(); }
     107              :   auto rend() const { return ports.rend(); }
     108              :   auto Size() const { return ports.size(); }
     109              : 
     110              :   // Returns array of lumped port attributes.
     111              :   mfem::Array<int> GetAttrList() const;
     112              :   mfem::Array<int> GetRsAttrList() const;
     113              :   mfem::Array<int> GetLsAttrList() const;
     114              :   mfem::Array<int> GetCsAttrList() const;
     115              : 
     116              :   // Add contributions to system matrices from lumped elements with nonzero inductance,
     117              :   // resistance, and/or capacitance.
     118              :   void AddStiffnessBdrCoefficients(double coeff, MaterialPropertyCoefficient &fb);
     119              :   void AddDampingBdrCoefficients(double coeff, MaterialPropertyCoefficient &fb);
     120              :   void AddMassBdrCoefficients(double coeff, MaterialPropertyCoefficient &fb);
     121              : 
     122              :   // Add contributions to the right-hand side source term vector for an incident field at
     123              :   // excited port boundaries, -U_inc/(iω) for the real version (versus the full -U_inc for
     124              :   // the complex one).
     125              :   void AddExcitationBdrCoefficients(int excitation_idx, SumVectorCoefficient &fb);
     126              : };
     127              : 
     128              : }  // namespace palace
     129              : 
     130              : #endif  // PALACE_MODELS_LUMPED_PORT_OPERATOR_HPP
        

Generated by: LCOV version 2.0-1