47 const int ncomp = a_phi[lev]->nComp();
48 const auto prob_lo =
geom[lev].ProbLoArray();
49 const auto cell_size =
geom[lev].CellSizeArray();
50 const amrex::GpuArray<int, AMREX_SPACEDIM> periodic = {
51 AMREX_D_DECL(
geom[0].isPeriodic(0),
52 geom[0].isPeriodic(1),
53 geom[0].isPeriodic(2))};
54 std::vector<Set::Scalar> coordinates(
55 X.size() * AMREX_SPACEDIM);
56 for (
int n = 0; n < static_cast<int>(
X.size()); ++n)
57 for (
int d = 0; d < AMREX_SPACEDIM; ++d)
58 coordinates[n * AMREX_SPACEDIM + d] =
X[n](d);
59 amrex::Gpu::AsyncArray<Set::Scalar> X_device(
60 coordinates.data(), coordinates.size());
61 amrex::Gpu::AsyncArray<Set::Scalar> R_device(
R.data(),
R.size());
64 const int sphere_count =
static_cast<int>(this->X.size());
68 for (amrex::MFIter mfi(*a_phi[lev], amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi)
71 amrex::IndexType type = a_phi[lev]->ixType();
72 if (type == amrex::IndexType::TheCellType()) bx = mfi.growntilebox();
73 else if (type == amrex::IndexType::TheNodeType()) bx = mfi.grownnodaltilebox();
76 amrex::Array4<Set::Scalar>
const& phi = a_phi[lev]->array(mfi);
77 amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(
int i,
int j,
int k)
83 for (
int n = 0; n < sphere_count; n++)
86 Set::Scalar d1 = std::numeric_limits<Set::Scalar>::infinity();
89 for (
int direction = 0;
90 direction < AMREX_SPACEDIM; ++direction)
92 X[n * AMREX_SPACEDIM + direction];
93 d = (x - center).lpNorm<2>();
97 d1 = std::min((x - center + size(0) * Set::Vector::Unit(0)).lpNorm<2>(),
98 (x - center - size(0) * Set::Vector::Unit(0)).lpNorm<2>());
100#if AMREX_SPACEDIM > 1
103 d1 = std::min((x - center + size(1) * Set::Vector::Unit(1)).lpNorm<2>(),
104 (x - center - size(1) * Set::Vector::Unit(1)).lpNorm<2>());
107#if AMREX_SPACEDIM > 2
110 d1 = std::min((x - center + size(2) * Set::Vector::Unit(2)).lpNorm<2>(),
111 (x - center - size(2) * Set::Vector::Unit(2)).lpNorm<2>());
117 if (d <= (
R[n] +
eps))
121 min_grain_id = min_grain_id + m * (1. - min_grain_id);
125 phi(i, j, k, 0) = min_grain_id;
126 if (
invert) phi(i,j,k,0) = 1.0 - min_grain_id;
127 if (ncomp > 1) phi(i, j, k, 1) = 1.0 - min_grain_id;
134 std::string filename;
139 pp.
forbid(
"filename",
"use file.name instead");
167 std::ifstream datafile(filename);
169 if (datafile.is_open())
174 while (getline(datafile, line))
176 std::istringstream in(line);
178 std::string strx, stry, strz, strR;
179 in >> strx >> stry >> strz >> strR;
181 Set::Scalar x = (std::stod(strx) * unit).normalized_value();
182 Set::Scalar y = (std::stod(stry) * unit).normalized_value();
183 #if AMREX_SPACEDIM > 2
184 Set::Scalar z = (std::stod(strz) * unit).normalized_value();
186 Set::Scalar r = (std::stod(strR) * unit).normalized_value();
191 value.
X.push_back(
X);
192 value.
R.push_back(r);