5#include "AMReX_MultiFab.H"
8using namespace amrex::literals;
38template <
typename T1,
typename T2>
45 const amrex::IntVect& nghost)
47 const int nlevels = dst.repo().num_active_levels();
48 for (
int lev = 0; lev < nlevels; ++lev) {
50 dst(lev), src(lev), srccomp, dstcomp, numcomp, nghost);
66template <
typename T1,
typename T2>
68add(T1& dst,
const T2& src,
int srccomp,
int dstcomp,
int numcomp,
int nghost)
70 add(dst, src, srccomp, dstcomp, numcomp, amrex::IntVect(nghost));
86template <
typename T1,
typename T2>
94 const amrex::IntVect& nghost)
96 const int nlevels = dst.repo().num_active_levels();
97 for (
int lev = 0; lev < nlevels; ++lev) {
98 if (ncomp_dst == ncomp_src) {
99 amrex::MultiFab::Divide(
100 dst(lev), src(lev), srccomp, dstcomp, ncomp_dst, nghost);
101 }
else if (ncomp_src == 1) {
102 for (
int n = 0; n < ncomp_dst; ++n) {
103 amrex::MultiFab::Divide(
104 dst(lev), src(lev), srccomp, dstcomp + n, ncomp_src,
109 "field_ops::divide : number of divisor components (ncomp_src) "
110 "must either be 1 or match number of dividend components "
129template <
typename T1,
typename T2>
140 dst, src, srccomp, dstcomp, ncomp_src, ncomp_dst,
141 amrex::IntVect(nghost));
156template <
typename T1,
typename T2>
163 const amrex::IntVect& nghost)
165 const int nlevels = dst.repo().num_active_levels();
166 for (
int lev = 0; lev < nlevels; ++lev) {
167 amrex::MultiFab::Copy(
168 dst(lev), src(lev), srccomp, dstcomp, numcomp, nghost);
184template <
typename T1,
typename T2>
186copy(T1& dst,
const T2& src,
int srccomp,
int dstcomp,
int numcomp,
int nghost)
188 copy(dst, src, srccomp, dstcomp, numcomp, amrex::IntVect(nghost));
204template <
typename T1,
typename T2>
212 const amrex::IntVect& nghost)
214 const int nlevels = dst.repo().num_active_levels();
215 for (
int lev = 0; lev < nlevels; ++lev) {
216 amrex::MultiFab::Saxpy(
217 dst(lev), a, src(lev), srccomp, dstcomp, numcomp, nghost);
234template <
typename T1,
typename T2>
244 saxpy(dst, a, src, srccomp, dstcomp, numcomp, amrex::IntVect(nghost));
260template <
typename T1,
typename T2>
268 const amrex::IntVect& nghost)
270 const int nlevels = dst.repo().num_active_levels();
271 for (
int lev = 0; lev < nlevels; ++lev) {
272 amrex::MultiFab::Xpay(
273 dst(lev), a, src(lev), srccomp, dstcomp, numcomp, nghost);
290template <
typename T1,
typename T2>
300 xpay(dst, a, src, srccomp, dstcomp, numcomp, amrex::IntVect(nghost));
319template <
typename T1,
typename T2,
typename T3>
330 const amrex::IntVect& nghost)
332 const int nlevels = dst.repo().num_active_levels();
333 for (
int lev = 0; lev < nlevels; ++lev) {
334 amrex::MultiFab::LinComb(
335 dst(lev), a, x(lev), xcomp, b, y(lev), ycomp, dstcomp, numcomp,
356template <
typename T1,
typename T2,
typename T3>
370 dst, a, x, xcomp, b, y, ycomp, dstcomp, numcomp,
371 amrex::IntVect(nghost));
381template <
typename FType>
383lower_bound(FType& field,
const amrex::Real min_value,
const int icomp = 0)
385 const auto& repo = field.repo();
386 const int nlevels = repo.num_active_levels();
387 for (
int lev = 0; lev < nlevels; ++lev) {
388 const auto& farrs = field(lev).arrays();
391 [=] AMREX_GPU_DEVICE(
int nbx,
int i,
int j,
int k)
noexcept {
392 farrs[nbx](i, j, k, icomp) =
393 amrex::max(min_value, farrs[nbx](i, j, k, icomp));
396 amrex::Gpu::streamSynchronize();
404template <
typename FType>
407 const auto& repo = field.repo();
408 const auto ncomp = field.num_comp();
410 amrex::Real maxglobal = 0.0_rt;
411 const int nlevels = repo.num_active_levels();
412 for (
int lev = 0; lev < nlevels; ++lev) {
413 amrex::Real maxglobal_lev = 0.0_rt;
414 maxglobal_lev = amrex::ReduceMax(
416 [=] AMREX_GPU_HOST_DEVICE(
418 amrex::Array4<amrex::Real const>
const& field_arr)
420 amrex::Real mx = 0.0_rt;
421 amrex::Loop(b, [=, &mx](
int i,
int j,
int k)
noexcept {
422 amrex::Real mag = 0.0_rt;
423 for (
int icomp = 0; icomp < ncomp; ++icomp) {
424 mag = mag + field_arr(i, j, k, icomp) *
425 field_arr(i, j, k, icomp);
427 mx = amrex::max(std::sqrt(mag), mx);
431 maxglobal = amrex::max(maxglobal, maxglobal_lev);
434 amrex::ParallelAllReduce::Max<amrex::Real>(
435 maxglobal, amrex::ParallelContext::CommunicatorSub());
444template <
typename FType>
447 const amrex::Real eps =
448 std::numeric_limits<amrex::Real>::epsilon() * 1.0e4_rt;
449 const auto& repo = field.repo();
450 const auto ncomp = field.num_comp();
452 const int nlevels = repo.num_active_levels();
453 for (
int lev = 0; lev < nlevels; ++lev) {
454 const auto& farrs = field(lev).arrays();
457 [=] AMREX_GPU_DEVICE(
int nbx,
int i,
int j,
int k)
noexcept {
458 auto farr = farrs[nbx];
460 amrex::Real mag = 0.0_rt;
461 for (
int icomp = 0; icomp < ncomp; ++icomp) {
462 mag = mag + farr(i, j, k, icomp) * farr(i, j, k, icomp);
465 for (
int icomp = 0; icomp < ncomp; ++icomp) {
466 farr(i, j, k, icomp) =
467 farr(i, j, k, icomp) / std::sqrt(mag);
472 amrex::Gpu::streamSynchronize();
void divide(T1 &dst, const T2 &src, const int srccomp, const int dstcomp, const int ncomp_src, const int ncomp_dst, const amrex::IntVect &nghost)
Definition field_ops.H:87
void normalize(FType &field)
Definition field_ops.H:445
void saxpy(T1 &dst, const amrex::Real a, const T2 &src, const int srccomp, const int dstcomp, const int numcomp, const amrex::IntVect &nghost)
Definition field_ops.H:205
void add(T1 &dst, const T2 &src, int srccomp, int dstcomp, int numcomp, const amrex::IntVect &nghost)
Definition field_ops.H:40
void xpay(T1 &dst, const amrex::Real a, const T2 &src, const int srccomp, const int dstcomp, const int numcomp, const amrex::IntVect &nghost)
Definition field_ops.H:261
void copy(T1 &dst, const T2 &src, const int srccomp, const int dstcomp, const int numcomp, const amrex::IntVect &nghost)
Definition field_ops.H:157
void lower_bound(FType &field, const amrex::Real min_value, const int icomp=0)
Definition field_ops.H:383
void lincomb(T1 &dst, const amrex::Real a, const T2 &x, const int xcomp, const amrex::Real b, const T3 &y, const int ycomp, const int dstcomp, const int numcomp, const amrex::IntVect &nghost)
Definition field_ops.H:320
amrex::Real global_max_magnitude(FType &field)
Definition field_ops.H:405
Definition field_ops.H:23