diff --git a/exec/immersedIons/main_driver.cpp b/exec/immersedIons/main_driver.cpp index 51dd39c8f..cb099f475 100644 --- a/exec/immersedIons/main_driver.cpp +++ b/exec/immersedIons/main_driver.cpp @@ -339,7 +339,7 @@ void main_driver(const char* argv) double simParticles = 0; double wetRad[nspecies]; double dxAv = (dx[0] + dx[1] + dx[2])/3.0; //This is probably the wrong way to do this. - std::string line; + //std::string line; for(int j=0;j external; + // external field cell-centered + std::array< MultiFab, AMREX_SPACEDIM > externalCC; + for (int d=0; d externalFC; + for (int d=0; d beta_es; + std::array< MultiFab, AMREX_SPACEDIM > permittivity_fc; + for (int d=0; d permittivity_map; + int epscount = 0; + + std::string filename = "epsilon_mem.dat"; + std::ifstream permittivityFile(filename); // permittivity file for non-solvent part + std::string line; + while (std::getline(permittivityFile, line)) { + std::istringstream ss(line); + ss >> i_mf; + ss >> j_mf; + ss >> k_mf; + ss >> new_permittivity; + IntVect mf_idx = IntVect(AMREX_D_DECL(i_mf,j_mf,k_mf)); + permittivity_map.insert(make_pair(mf_idx, new_permittivity)); + epscount++; + } + Print() << "Loaded " << epscount << " cells of different permittivity." << std::endl; + permittivityFile.close(); + + // Update non-uniform permittivity for (int d=0; dsecond; + } else { + h_data(i,j,k) = permittivity; // default value from input file + } + }); +#ifdef AMREX_USE_GPU + Gpu::htod_memcpy_async(d_fab.dataPtr(), h_fab.dataPtr(), h_fab.nBytes()); + Gpu::streamSynchronize(); +#endif + + } } + /////////////////////////////////////////// // structure factor for charge-charge @@ -1316,7 +1385,8 @@ void main_driver(const char* argv) //Most of these functions are sensitive to the order of execution. We can fix this, but for now leave them in this order. for (int d=0; d& phi_fc, int start_incomp, int start_outcomp, int ncomp, - const Geometry& geom, int increment) + const Geometry& geom, Real factor, int increment) { BL_PROFILE_VAR("ComputeDiv()",ComputeDiv); @@ -27,10 +27,15 @@ void ComputeDiv(MultiFab& div, amrex::ParallelFor(bx, ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept { - div_fab(i,j,k,start_outcomp+n) += + Real temp = AMREX_D_TERM( (phix_fab(i+1,j,k,start_incomp+n) - phix_fab(i,j,k,start_incomp+n)) / dx[0], + (phiy_fab(i,j+1,k,start_incomp+n) - phiy_fab(i,j,k,start_incomp+n)) / dx[1], + (phiz_fab(i,j,k+1,start_incomp+n) - phiz_fab(i,j,k,start_incomp+n)) / dx[2]);; + if (factor == 0.) { + div_fab(i,j,k,start_outcomp+n) += temp; + } else { + div_fab(i,j,k,start_outcomp+n) += factor*temp; + } }); } } @@ -183,7 +188,7 @@ void ComputeGrad(const MultiFab & phi_in, std::array & // Computes gradient at cell centres from cell centred data - ouputs to a three component mf. void ComputeCentredGrad(const MultiFab & phi, std::array & gphi, - const Geometry & geom) + const Geometry & geom, Real factor) { BL_PROFILE_VAR("ComputeCentredGrad()",ComputeCentredGrad); @@ -201,9 +206,9 @@ void ComputeCentredGrad(const MultiFab & phi, amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept { - AMREX_D_TERM(gphix_fab(i,j,k) = (phi_fab(i+1,j,k) - phi_fab(i-1,j,k) ) / (2.*dx[0]);, - gphiy_fab(i,j,k) = (phi_fab(i,j+1,k) - phi_fab(i,j-1,k) ) / (2.*dx[1]);, - gphiz_fab(i,j,k) = (phi_fab(i,j,k+1) - phi_fab(i,j,k-1) ) / (2.*dx[2]);); + AMREX_D_TERM(gphix_fab(i,j,k) = factor*(phi_fab(i+1,j,k) - phi_fab(i-1,j,k) ) / (2.*dx[0]);, + gphiy_fab(i,j,k) = factor*(phi_fab(i,j+1,k) - phi_fab(i,j-1,k) ) / (2.*dx[1]);, + gphiz_fab(i,j,k) = factor*(phi_fab(i,j,k+1) - phi_fab(i,j,k-1) ) / (2.*dx[2]);); }); } } diff --git a/src_common/common_functions.H b/src_common/common_functions.H index a3d1df052..ba89882b0 100644 --- a/src_common/common_functions.H +++ b/src_common/common_functions.H @@ -65,14 +65,14 @@ void AverageCCToEdge(const MultiFab& cc_in, std::array& edge void ComputeDiv(MultiFab & div, const std::array & phi_fc, int start_incomp, int start_outcomp, int ncomp, - const Geometry & geom, int increment=0); + const Geometry & geom, Real factor, int increment=0); void ComputeGrad(const MultiFab & phi_in, std::array & gphi, int start_incomp, int start_outcomp, int ncomp, int bccomp, const Geometry & geom, int increment=0); void ComputeCentredGrad(const MultiFab& phi, std::array& gphi, - const Geometry& geom); + const Geometry& geom, Real factor); void ComputeCentredGradCompDir(const MultiFab & phi, MultiFab& gphi, diff --git a/src_electrostatic/electrostatic.H b/src_electrostatic/electrostatic.H index 9a66e327c..3830562f0 100644 --- a/src_electrostatic/electrostatic.H +++ b/src_electrostatic/electrostatic.H @@ -10,7 +10,11 @@ using namespace amrex; void esSolve(MultiFab& potential, MultiFab& charge, std::array< MultiFab, AMREX_SPACEDIM >& efieldCC, - const std::array< MultiFab, AMREX_SPACEDIM >& external, const Geometry geom); + const std::array< MultiFab, AMREX_SPACEDIM >& permittivity_fc, + const std::array< MultiFab, AMREX_SPACEDIM >& beta_es, + const std::array< MultiFab, AMREX_SPACEDIM >& externalCC, + const std::array< MultiFab, AMREX_SPACEDIM >& externalFC, + const Geometry geom); void calculateField(MultiFab& potential, const Geometry geom); diff --git a/src_electrostatic/electrostatic.cpp b/src_electrostatic/electrostatic.cpp index db6009ae9..ed5c90e92 100644 --- a/src_electrostatic/electrostatic.cpp +++ b/src_electrostatic/electrostatic.cpp @@ -1,12 +1,17 @@ #include "electrostatic.H" #include "common_functions.H" #include +#include using namespace amrex; void esSolve(MultiFab& potential, MultiFab& charge, std::array< MultiFab, AMREX_SPACEDIM >& efieldCC, - const std::array< MultiFab, AMREX_SPACEDIM >& external, const Geometry geom) + const std::array< MultiFab, AMREX_SPACEDIM >& permittivity_fc, + const std::array< MultiFab, AMREX_SPACEDIM >& beta_es, + const std::array< MultiFab, AMREX_SPACEDIM >& externalCC, + const std::array< MultiFab, AMREX_SPACEDIM >& externalFC, + const Geometry geom) { BL_PROFILE_VAR("esSolve()",esSolve); @@ -45,11 +50,35 @@ void esSolve(MultiFab& potential, MultiFab& charge, } } + potential.setVal(0.); const BoxArray& ba = charge.boxArray(); const DistributionMapping& dmap = charge.DistributionMap(); + // Copy charge in the RHS of Poisson Solver + MultiFab charge_unscaled(ba,dmap,1,charge.nGrow()); // create new charge (unscaled) MFab + MultiFab::Copy(charge_unscaled,charge,0,0,1,charge.nGrow()); // copy contents of charge/eps into charge + charge_unscaled.mult(permittivity,charge.nGrow()); // multiply the charge value by permittvity to get correct charge + MultiFab rhs(ba,dmap,1,0); // create RHS MFab + MultiFab::Copy(rhs,charge_unscaled,0,0,1,0); // Copy charge into rhs + + std::array< MultiFab, AMREX_SPACEDIM > epsE_ext; + for (int d=0; d