diff options
Diffstat (limited to 'Source/FieldSolver/FiniteDifferenceSolver/MacroscopicProperties')
2 files changed, 142 insertions, 119 deletions
diff --git a/Source/FieldSolver/FiniteDifferenceSolver/MacroscopicProperties/MacroscopicProperties.H b/Source/FieldSolver/FiniteDifferenceSolver/MacroscopicProperties/MacroscopicProperties.H index e638be1c5..040fe2a67 100644 --- a/Source/FieldSolver/FiniteDifferenceSolver/MacroscopicProperties/MacroscopicProperties.H +++ b/Source/FieldSolver/FiniteDifferenceSolver/MacroscopicProperties/MacroscopicProperties.H @@ -1,3 +1,10 @@ +/* Copyright 2020 Revathi Jambunathan + * + * This file is part of WarpX. + * + * License: BSD-3-Clause-LBNL + */ + #ifndef WARPX_MACROSCOPICPROPERTIES_H_ #define WARPX_MACROSCOPICPROPERTIES_H_ @@ -15,6 +22,81 @@ #include <memory> #include <string> + +enum MacroparameterInitType { ConstantValue, ParserFunction}; + +/** + * \brief Functor to return macropameter, either constant value, m_value, or + * spatially varying scalar value computed using the parser function, m_parser. + */ + +struct GetMacroparameter +{ + /* Type of initialization for macroparameter, constant or parser function */ + MacroparameterInitType m_type; + /* Constant value of the macroparameter. */ + amrex::Real m_value; + /* Parser funtion of the spatially varying macroparameter*/ + amrex::ParserExecutor<3> m_parser; + /** + * \brief Functor call. This method returns the value of the macroparameter, + * or property of the medium needed for the macroscopic Maxwell solver, + * at a given location (x,y,z) in the domain. + * + * @param[in] x x-coordinate of a given location + * @param[in] y y-coordinate of a given location + * @param[in] z z-coordinate of a given location + * @return value of the macroparameter at (x,y,z). + * m_value if init-type is constant + * m_parser(x,y,z) if init-type is parser function + */ + AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE + amrex::Real operator () (amrex::Real x, amrex::Real y, amrex::Real z) const noexcept + { + using namespace amrex::literals; + if (m_type == ConstantValue) + { + return m_value; + } + else if (m_type == ParserFunction) + { + return m_parser(x,y,z); + } + else + { + amrex::Abort("macroparameter init type not valid."); + return 0.; + } + return 0.; + } +}; + +/** + * \brief Functor for conductivity, sigma, of the medium. + */ +struct GetSigmaMacroparameter : GetMacroparameter +{ + /** Constructor to store the type of intialization, m_type, and the value or parser function. */ + GetSigmaMacroparameter () noexcept; +}; + +/** + * \brief Functor for permeability, mu, of the medium. + */ +struct GetMuMacroparameter : GetMacroparameter +{ + /** Constructor to store the type of intialization, m_type, and the value or parser function. */ + GetMuMacroparameter () noexcept; +}; + +/** + * \brief Functor for permittivity, epsilon, of the medium. + */ +struct GetEpsilonMacroparameter : GetMacroparameter +{ + /** Constructor to store the type of intialization, m_type, and the value or parser function. */ + GetEpsilonMacroparameter () noexcept; +}; /** * \brief This class contains the macroscopic properties of the medium needed to * evaluate macroscopic Maxwell equation. @@ -29,47 +111,25 @@ public: /** Initialize multifabs storing macroscopic multifabs */ void InitData (); - /** return MultiFab, sigma (conductivity) of the medium. */ - amrex::MultiFab& getsigma_mf () {return (*m_sigma_mf);} - /** return MultiFab, epsilon (permittivity) of the medium. */ - amrex::MultiFab& getepsilon_mf () {return (*m_eps_mf);} - /** return MultiFab, mu (permeability) of the medium. */ - amrex::MultiFab& getmu_mf () {return (*m_mu_mf);} - - /** Initializes the Multifabs storing macroscopic properties - * with user-defined functions(x,y,z). - */ - void InitializeMacroMultiFabUsingParser (amrex::MultiFab *macro_mf, - amrex::ParserExecutor<3> const& macro_parser, - int lev); - /** Gpu Vector with index type of the conductivity multifab */ - amrex::GpuArray<int, 3> sigma_IndexType; - /** Gpu Vector with index type of the permittivity multifab */ - amrex::GpuArray<int, 3> epsilon_IndexType; - /** Gpu Vector with index type of the permeability multifab */ - amrex::GpuArray<int, 3> mu_IndexType; /** Gpu Vector with index type of the Ex multifab */ amrex::GpuArray<int, 3> Ex_IndexType; /** Gpu Vector with index type of the Ey multifab */ amrex::GpuArray<int, 3> Ey_IndexType; /** Gpu Vector with index type of the Ez multifab */ amrex::GpuArray<int, 3> Ez_IndexType; - /** Gpu Vector with index type of coarsening ratio with default value (1,1,1) */ - amrex::GpuArray<int, 3> macro_cr_ratio; + /** Gpu Vector with index type of the Bx multifab */ + amrex::GpuArray<int, 3> Bx_IndexType; + /** Gpu Vector with index type of the By multifab */ + amrex::GpuArray<int, 3> By_IndexType; + /** Gpu Vector with index type of the Bz multifab */ + amrex::GpuArray<int, 3> Bz_IndexType; -private: /** Conductivity, sigma, of the medium */ amrex::Real m_sigma = 0.0; /** Permittivity, epsilon, of the medium */ amrex::Real m_epsilon = PhysConst::ep0; /** Permeability, mu, of the medium */ amrex::Real m_mu = PhysConst::mu0; - /** Multifab for m_sigma */ - std::unique_ptr<amrex::MultiFab> m_sigma_mf; - /** Multifab for m_epsilon */ - std::unique_ptr<amrex::MultiFab> m_eps_mf; - /** Multifab for m_mu */ - std::unique_ptr<amrex::MultiFab> m_mu_mf; /** Stores initialization type for conductivity : constant or parser */ std::string m_sigma_s = "constant"; /** Stores initialization type for permittivity : constant or parser */ @@ -85,6 +145,7 @@ private: std::unique_ptr<amrex::Parser> m_sigma_parser; std::unique_ptr<amrex::Parser> m_epsilon_parser; std::unique_ptr<amrex::Parser> m_mu_parser; + }; /** diff --git a/Source/FieldSolver/FiniteDifferenceSolver/MacroscopicProperties/MacroscopicProperties.cpp b/Source/FieldSolver/FiniteDifferenceSolver/MacroscopicProperties/MacroscopicProperties.cpp index cfa3479da..7166eb99d 100644 --- a/Source/FieldSolver/FiniteDifferenceSolver/MacroscopicProperties/MacroscopicProperties.cpp +++ b/Source/FieldSolver/FiniteDifferenceSolver/MacroscopicProperties/MacroscopicProperties.cpp @@ -22,6 +22,49 @@ using namespace amrex; +GetSigmaMacroparameter::GetSigmaMacroparameter () noexcept +{ + auto& warpx = WarpX::GetInstance(); + auto& macroscopic_properties = warpx.GetMacroscopicProperties(); + if (macroscopic_properties.m_sigma_s == "constant") { + m_type = ConstantValue; + m_value = macroscopic_properties.m_sigma; + } + else if (macroscopic_properties.m_sigma_s == "parse_sigma_function") { + m_type = ParserFunction; + m_parser = macroscopic_properties.m_sigma_parser->compile<3>(); + } +} + +GetMuMacroparameter::GetMuMacroparameter () noexcept +{ + auto& warpx = WarpX::GetInstance(); + auto& macroscopic_properties = warpx.GetMacroscopicProperties(); + if (macroscopic_properties.m_mu_s == "constant") { + m_type = ConstantValue; + m_value = macroscopic_properties.m_mu; + } + else if (macroscopic_properties.m_mu_s == "parse_mu_function") { + m_type = ParserFunction; + m_parser = macroscopic_properties.m_mu_parser->compile<3>(); + } +} + +GetEpsilonMacroparameter::GetEpsilonMacroparameter () noexcept +{ + auto& warpx = WarpX::GetInstance(); + auto& macroscopic_properties = warpx.GetMacroscopicProperties(); + if (macroscopic_properties.m_epsilon_s == "constant") { + m_type = ConstantValue; + m_value = macroscopic_properties.m_epsilon; + } + else if (macroscopic_properties.m_epsilon_s == "parse_epsilon_function") { + m_type = ParserFunction; + m_parser = macroscopic_properties.m_epsilon_parser->compile<3>(); + } +} + + MacroscopicProperties::MacroscopicProperties () { ReadParameters(); @@ -105,112 +148,31 @@ MacroscopicProperties::InitData () amrex::Print() << "we are in init data of macro \n"; auto & warpx = WarpX::GetInstance(); - // Get BoxArray and DistributionMap of warpx instant. - int lev = 0; - BoxArray ba = warpx.boxArray(lev); - DistributionMapping dmap = warpx.DistributionMap(lev); - const amrex::IntVect ng = warpx.getngE(); - // Define material property multifabs using ba and dmap from WarpX instance - // sigma is cell-centered MultiFab - m_sigma_mf = std::make_unique<MultiFab>(ba, dmap, 1, ng); - // epsilon is cell-centered MultiFab - m_eps_mf = std::make_unique<MultiFab>(ba, dmap, 1, ng); - // mu is cell-centered MultiFab - m_mu_mf = std::make_unique<MultiFab>(ba, dmap, 1, ng); - // Initialize sigma - if (m_sigma_s == "constant") { - - m_sigma_mf->setVal(m_sigma); - - } else if (m_sigma_s == "parse_sigma_function") { - - InitializeMacroMultiFabUsingParser(m_sigma_mf.get(), m_sigma_parser->compile<3>(), lev); - } - // Initialize epsilon - if (m_epsilon_s == "constant") { - - m_eps_mf->setVal(m_epsilon); - - } else if (m_epsilon_s == "parse_epsilon_function") { - - InitializeMacroMultiFabUsingParser(m_eps_mf.get(), m_epsilon_parser->compile<3>(), lev); - - } - // Initialize mu - if (m_mu_s == "constant") { - - m_mu_mf->setVal(m_mu); - - } else if (m_mu_s == "parse_mu_function") { - - InitializeMacroMultiFabUsingParser(m_mu_mf.get(), m_mu_parser->compile<3>(), lev); - - } - - - IntVect sigma_stag = m_sigma_mf->ixType().toIntVect(); - IntVect epsilon_stag = m_eps_mf->ixType().toIntVect(); - IntVect mu_stag = m_mu_mf->ixType().toIntVect(); IntVect Ex_stag = warpx.getEfield_fp(0,0).ixType().toIntVect(); IntVect Ey_stag = warpx.getEfield_fp(0,1).ixType().toIntVect(); IntVect Ez_stag = warpx.getEfield_fp(0,2).ixType().toIntVect(); + IntVect Bx_stag = warpx.getBfield_fp(0,0).ixType().toIntVect(); + IntVect By_stag = warpx.getBfield_fp(0,1).ixType().toIntVect(); + IntVect Bz_stag = warpx.getBfield_fp(0,2).ixType().toIntVect(); + for ( int idim = 0; idim < AMREX_SPACEDIM; ++idim) { - sigma_IndexType[idim] = sigma_stag[idim]; - epsilon_IndexType[idim] = epsilon_stag[idim]; - mu_IndexType[idim] = mu_stag[idim]; Ex_IndexType[idim] = Ex_stag[idim]; Ey_IndexType[idim] = Ey_stag[idim]; Ez_IndexType[idim] = Ez_stag[idim]; - macro_cr_ratio[idim] = 1; + Bx_IndexType[idim] = Bx_stag[idim]; + By_IndexType[idim] = By_stag[idim]; + Bz_IndexType[idim] = Bz_stag[idim]; } #if (AMREX_SPACEDIM==2) - sigma_IndexType[2] = 0; - epsilon_IndexType[2] = 0; - mu_IndexType[2] = 0; Ex_IndexType[2] = 0; Ey_IndexType[2] = 0; Ez_IndexType[2] = 0; - macro_cr_ratio[2] = 1; + Bx_IndexType[2] = 0; + By_IndexType[2] = 0; + Bz_IndexType[2] = 0; #endif } -void -MacroscopicProperties::InitializeMacroMultiFabUsingParser ( - MultiFab *macro_mf, ParserExecutor<3> const& macro_parser, - int lev) -{ - auto& warpx = WarpX::GetInstance(); - const auto dx_lev = warpx.Geom(lev).CellSizeArray(); - const RealBox& real_box = warpx.Geom(lev).ProbDomain(); - IntVect iv = macro_mf->ixType().toIntVect(); - for ( MFIter mfi(*macro_mf, TilingIfNotGPU()); mfi.isValid(); ++mfi ) { - // Initialize ghost cells in addition to valid cells - - const Box& tb = mfi.tilebox(iv, macro_mf->nGrowVect()); - auto const& macro_fab = macro_mf->array(mfi); - amrex::ParallelFor (tb, - [=] AMREX_GPU_DEVICE (int i, int j, int k) { - // Shift x, y, z position based on index type - Real fac_x = (1._rt - iv[0]) * dx_lev[0] * 0.5_rt; - Real x = i * dx_lev[0] + real_box.lo(0) + fac_x; -#if (AMREX_SPACEDIM==2) - amrex::Real y = 0._rt; - Real fac_z = (1._rt - iv[1]) * dx_lev[1] * 0.5_rt; - Real z = j * dx_lev[1] + real_box.lo(1) + fac_z; -#else - Real fac_y = (1._rt - iv[1]) * dx_lev[1] * 0.5_rt; - Real y = j * dx_lev[1] + real_box.lo(1) + fac_y; - Real fac_z = (1._rt - iv[2]) * dx_lev[2] * 0.5_rt; - Real z = k * dx_lev[2] + real_box.lo(2) + fac_z; -#endif - // initialize the macroparameter - macro_fab(i,j,k) = macro_parser(x,y,z); - }); - - } - - -} |