|
| 1 | +#ifndef PONEMULTIEB_HPP |
| 2 | +#define PONEMULTIEB_HPP |
| 3 | + |
| 4 | +#include <AMRParam.hpp> |
| 5 | +#include <AMReX_FArrayBox.H> |
| 6 | +#include <AMReX_MLEBABecLap.H> |
| 7 | +#include <AMReX_MLMG.H> |
| 8 | +#include <AMReX_MultiFabUtil.H> |
| 9 | +#include <AMReX_ParmParse.H> |
| 10 | +#include <MLMGParam.hpp> |
| 11 | + |
| 12 | +namespace PeleRad |
| 13 | +{ |
| 14 | + |
| 15 | +class POneMultiEB |
| 16 | +{ |
| 17 | +private: |
| 18 | + MLMGParam mlmgpp_; |
| 19 | + |
| 20 | + amrex::LPInfo info_; |
| 21 | + |
| 22 | +public: |
| 23 | + amrex::Vector<amrex::Geometry>& geom_; |
| 24 | + amrex::Vector<amrex::BoxArray>& grids_; |
| 25 | + amrex::Vector<amrex::DistributionMapping>& dmap_; |
| 26 | + |
| 27 | + amrex::Vector<std::unique_ptr<amrex::EBFArrayBoxFactory>> const& factory_; |
| 28 | + |
| 29 | + amrex::Vector<amrex::MultiFab>& solution_; |
| 30 | + amrex::Vector<amrex::MultiFab> const& rhs_; |
| 31 | + amrex::Vector<amrex::MultiFab> const& acoef_; |
| 32 | + amrex::Vector<amrex::Array<amrex::MultiFab, AMREX_SPACEDIM>> const& bcoef_; |
| 33 | + |
| 34 | + amrex::Vector<amrex::MultiFab> const& robin_a_; |
| 35 | + amrex::Vector<amrex::MultiFab> const& robin_b_; |
| 36 | + amrex::Vector<amrex::MultiFab> const& robin_f_; |
| 37 | + |
| 38 | + amrex::Real const ascalar_ = 1.0; |
| 39 | + amrex::Real const bscalar_ = 1.0 / 3.0; |
| 40 | + |
| 41 | + POneMultiEB() = delete; |
| 42 | + |
| 43 | + POneMultiEB(POneMultiEB const&) = delete; |
| 44 | + |
| 45 | + // constructor |
| 46 | + POneMultiEB(MLMGParam const& mlmgpp, amrex::Vector<amrex::Geometry>& geom, |
| 47 | + amrex::Vector<amrex::BoxArray>& grids, |
| 48 | + amrex::Vector<amrex::DistributionMapping>& dmap, |
| 49 | + amrex::Vector<std::unique_ptr<amrex::EBFArrayBoxFactory>>& factory, |
| 50 | + amrex::Vector<amrex::MultiFab>& solution, |
| 51 | + amrex::Vector<amrex::MultiFab> const& rhs, |
| 52 | + amrex::Vector<amrex::MultiFab> const& acoef, |
| 53 | + amrex::Vector<amrex::Array<amrex::MultiFab, AMREX_SPACEDIM>> const& |
| 54 | + bcoef, |
| 55 | + amrex::Vector<amrex::MultiFab> const& robin_a, |
| 56 | + amrex::Vector<amrex::MultiFab> const& robin_b, |
| 57 | + amrex::Vector<amrex::MultiFab> const& robin_f) |
| 58 | + : mlmgpp_(mlmgpp), |
| 59 | + geom_(geom), |
| 60 | + grids_(grids), |
| 61 | + dmap_(dmap), |
| 62 | + factory_(factory), |
| 63 | + solution_(solution), |
| 64 | + rhs_(rhs), |
| 65 | + acoef_(acoef), |
| 66 | + bcoef_(bcoef), |
| 67 | + robin_a_(robin_a), |
| 68 | + robin_b_(robin_b), |
| 69 | + robin_f_(robin_f) |
| 70 | + { |
| 71 | + auto const max_coarsening_level = mlmgpp_.max_coarsening_level_; |
| 72 | + auto const agglomeration = mlmgpp_.agglomeration_; |
| 73 | + auto const consolidation = mlmgpp_.consolidation_; |
| 74 | + info_.setAgglomeration(agglomeration); |
| 75 | + info_.setConsolidation(consolidation); |
| 76 | + info_.setMaxCoarseningLevel(max_coarsening_level); |
| 77 | + } |
| 78 | + |
| 79 | + void solve() |
| 80 | + { |
| 81 | + auto const nlevels = geom_.size(); |
| 82 | + |
| 83 | + auto const linop_maxorder = mlmgpp_.linop_maxorder_; |
| 84 | + |
| 85 | + auto const& lobc = mlmgpp_.lobc_; |
| 86 | + auto const& hibc = mlmgpp_.hibc_; |
| 87 | + |
| 88 | + amrex::MLEBABecLap mlabec( |
| 89 | + geom_, grids_, dmap_, info_, amrex::GetVecOfConstPtrs(factory_)); |
| 90 | + |
| 91 | + mlabec.setDomainBC(lobc, hibc); |
| 92 | + mlabec.setScalars(ascalar_, bscalar_); |
| 93 | + mlabec.setMaxOrder(linop_maxorder); |
| 94 | + |
| 95 | + auto const max_iter = mlmgpp_.max_iter_; |
| 96 | + auto const max_fmg_iter = mlmgpp_.max_fmg_iter_; |
| 97 | + auto const verbose = mlmgpp_.verbose_; |
| 98 | + auto const bottom_verbose = mlmgpp_.bottom_verbose_; |
| 99 | + auto const use_hypre = mlmgpp_.use_hypre_; |
| 100 | + auto const bottom_reltol = mlmgpp_.bottom_reltol_; |
| 101 | + auto const bottom_abstol = mlmgpp_.bottom_abstol_; |
| 102 | + |
| 103 | + amrex::MLMG mlmg(mlabec); |
| 104 | + mlmg.setMaxIter(max_iter); |
| 105 | + mlmg.setMaxFmgIter(max_fmg_iter); |
| 106 | + mlmg.setVerbose(verbose); |
| 107 | + mlmg.setBottomVerbose(bottom_verbose); |
| 108 | + mlmg.setBottomSolver(amrex::BottomSolver::bicgstab); |
| 109 | + if (use_hypre) mlmg.setBottomSolver(amrex::MLMG::BottomSolver::hypre); |
| 110 | + mlmg.setBottomTolerance(bottom_reltol); |
| 111 | + mlmg.setBottomToleranceAbs(bottom_abstol); |
| 112 | + |
| 113 | + for (int ilev = 0; ilev < nlevels; ++ilev) |
| 114 | + { |
| 115 | + |
| 116 | + auto const& geom = geom_[ilev]; |
| 117 | + auto& solution = solution_[ilev]; |
| 118 | + auto const& acoef = acoef_[ilev]; |
| 119 | + auto const& bcoef = bcoef_[ilev]; |
| 120 | + auto const& robin_a = robin_a_[ilev]; |
| 121 | + auto const& robin_b = robin_b_[ilev]; |
| 122 | + auto const& robin_f = robin_f_[ilev]; |
| 123 | + |
| 124 | + // mlabec.setLevelBC(ilev, &solution, &robin_a, &robin_b, &robin_f); |
| 125 | + mlabec.setLevelBC(ilev, &solution); |
| 126 | + |
| 127 | + mlabec.setACoeffs(ilev, acoef); |
| 128 | + /* |
| 129 | + amrex::Array<amrex::MultiFab, AMREX_SPACEDIM> |
| 130 | + face_bcoef; for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) |
| 131 | + { |
| 132 | + amrex::BoxArray const& ba = amrex::convert( |
| 133 | + bcoef.boxArray(), |
| 134 | + amrex::IntVect::TheDimensionVector(idim)); |
| 135 | + face_bcoef[idim].define(ba, bcoef.DistributionMap(), |
| 136 | + 1, 0); |
| 137 | + } |
| 138 | + amrex::average_cellcenter_to_face( |
| 139 | + GetArrOfPtrs(face_bcoef), bcoef, geom); |
| 140 | + mlabec.setBCoeffs(ilev, |
| 141 | + amrex::GetArrOfConstPtrs(face_bcoef)); |
| 142 | + } |
| 143 | + */ |
| 144 | + |
| 145 | + mlabec.setBCoeffs(ilev, amrex::GetArrOfConstPtrs(bcoef)); |
| 146 | + |
| 147 | + amrex::MultiFab beta(grids_[ilev], dmap_[ilev], 1, 1, |
| 148 | + amrex::MFInfo(), *factory_[ilev]); |
| 149 | + beta.setVal(1.0); |
| 150 | + |
| 151 | + mlabec.setEBDirichlet(ilev, solution, beta); |
| 152 | + } |
| 153 | + auto const tol_rel = mlmgpp_.reltol_; |
| 154 | + auto const tol_abs = mlmgpp_.abstol_; |
| 155 | + |
| 156 | + mlmg.solve( |
| 157 | + GetVecOfPtrs(solution_), GetVecOfConstPtrs(rhs_), tol_rel, tol_abs); |
| 158 | + } |
| 159 | +}; |
| 160 | +} |
| 161 | + |
| 162 | +#endif |
0 commit comments