5#include "AMReX_MultiFab.H"
35template <
typename T1,
typename T2>
42 const amrex::IntVect& nghost)
44 const int nlevels = dst.repo().num_active_levels();
45 for (
int lev = 0; lev < nlevels; ++lev) {
47 dst(lev), src(lev), srccomp, dstcomp, numcomp, nghost);
63template <
typename T1,
typename T2>
65add(T1& dst,
const T2& src,
int srccomp,
int dstcomp,
int numcomp,
int nghost)
67 add(dst, src, srccomp, dstcomp, numcomp, amrex::IntVect(nghost));
83template <
typename T1,
typename T2>
91 const amrex::IntVect& nghost)
93 const int nlevels = dst.repo().num_active_levels();
94 for (
int lev = 0; lev < nlevels; ++lev) {
95 if (ncomp_dst == ncomp_src) {
96 amrex::MultiFab::Divide(
97 dst(lev), src(lev), srccomp, dstcomp, ncomp_dst, nghost);
98 }
else if (ncomp_src == 1) {
99 for (
int n = 0; n < ncomp_dst; ++n) {
100 amrex::MultiFab::Divide(
101 dst(lev), src(lev), srccomp, dstcomp + n, ncomp_src,
106 "field_ops::divide : number of divisor components (ncomp_src) "
107 "must either be 1 or match number of dividend components "
126template <
typename T1,
typename T2>
137 dst, src, srccomp, dstcomp, ncomp_src, ncomp_dst,
138 amrex::IntVect(nghost));
153template <
typename T1,
typename T2>
160 const amrex::IntVect& nghost)
162 const int nlevels = dst.repo().num_active_levels();
163 for (
int lev = 0; lev < nlevels; ++lev) {
164 amrex::MultiFab::Copy(
165 dst(lev), src(lev), srccomp, dstcomp, numcomp, nghost);
181template <
typename T1,
typename T2>
183copy(T1& dst,
const T2& src,
int srccomp,
int dstcomp,
int numcomp,
int nghost)
185 copy(dst, src, srccomp, dstcomp, numcomp, amrex::IntVect(nghost));
201template <
typename T1,
typename T2>
209 const amrex::IntVect& nghost)
211 const int nlevels = dst.repo().num_active_levels();
212 for (
int lev = 0; lev < nlevels; ++lev) {
213 amrex::MultiFab::Saxpy(
214 dst(lev), a, src(lev), srccomp, dstcomp, numcomp, nghost);
231template <
typename T1,
typename T2>
241 saxpy(dst, a, src, srccomp, dstcomp, numcomp, amrex::IntVect(nghost));
257template <
typename T1,
typename T2>
265 const amrex::IntVect& nghost)
267 const int nlevels = dst.repo().num_active_levels();
268 for (
int lev = 0; lev < nlevels; ++lev) {
269 amrex::MultiFab::Xpay(
270 dst(lev), a, src(lev), srccomp, dstcomp, numcomp, nghost);
287template <
typename T1,
typename T2>
297 xpay(dst, a, src, srccomp, dstcomp, numcomp, amrex::IntVect(nghost));
316template <
typename T1,
typename T2,
typename T3>
327 const amrex::IntVect& nghost)
329 const int nlevels = dst.repo().num_active_levels();
330 for (
int lev = 0; lev < nlevels; ++lev) {
331 amrex::MultiFab::LinComb(
332 dst(lev), a, x(lev), xcomp, b, y(lev), ycomp, dstcomp, numcomp,
353template <
typename T1,
typename T2,
typename T3>
367 dst, a, x, xcomp, b, y, ycomp, dstcomp, numcomp,
368 amrex::IntVect(nghost));
378template <
typename FType>
380lower_bound(FType& field,
const amrex::Real min_value,
const int icomp = 0)
382 const auto& repo = field.repo();
383 const int nlevels = repo.num_active_levels();
384 for (
int lev = 0; lev < nlevels; ++lev) {
385 const auto& farrs = field(lev).arrays();
388 [=] AMREX_GPU_DEVICE(
int nbx,
int i,
int j,
int k)
noexcept {
389 farrs[nbx](i, j, k, icomp) =
390 amrex::max(min_value, farrs[nbx](i, j, k, icomp));
393 amrex::Gpu::synchronize();
401template <
typename FType>
404 const auto& repo = field.repo();
405 const auto ncomp = field.num_comp();
407 amrex::Real maxglobal = 0.0;
408 const int nlevels = repo.num_active_levels();
409 for (
int lev = 0; lev < nlevels; ++lev) {
410 amrex::Real maxglobal_lev = 0.0;
411 maxglobal_lev = amrex::ReduceMax(
413 [=] AMREX_GPU_HOST_DEVICE(
415 amrex::Array4<amrex::Real const>
const& field_arr)
417 amrex::Real mx = 0.0;
418 amrex::Loop(b, [=, &mx](
int i,
int j,
int k)
noexcept {
419 amrex::Real mag = 0.0;
420 for (
int icomp = 0; icomp < ncomp; ++icomp) {
421 mag = mag + field_arr(i, j, k, icomp) *
422 field_arr(i, j, k, icomp);
424 mx = amrex::max(std::sqrt(mag), mx);
428 maxglobal = amrex::max(maxglobal, maxglobal_lev);
431 amrex::ParallelAllReduce::Max<amrex::Real>(
432 maxglobal, amrex::ParallelContext::CommunicatorSub());
441template <
typename FType>
444 const amrex::Real eps = 1.0e-12;
445 const auto& repo = field.repo();
446 const auto ncomp = field.num_comp();
448 const int nlevels = repo.num_active_levels();
449 for (
int lev = 0; lev < nlevels; ++lev) {
450 const auto& farrs = field(lev).arrays();
453 [=] AMREX_GPU_DEVICE(
int nbx,
int i,
int j,
int k)
noexcept {
454 auto farr = farrs[nbx];
456 amrex::Real mag = 0.;
457 for (
int icomp = 0; icomp < ncomp; ++icomp) {
458 mag = mag + farr(i, j, k, icomp) * farr(i, j, k, icomp);
461 for (
int icomp = 0; icomp < ncomp; ++icomp) {
462 farr(i, j, k, icomp) =
463 farr(i, j, k, icomp) / std::sqrt(mag);
468 amrex::Gpu::synchronize();
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:84
void normalize(FType &field)
Definition field_ops.H:442
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:202
void add(T1 &dst, const T2 &src, int srccomp, int dstcomp, int numcomp, const amrex::IntVect &nghost)
Definition field_ops.H:37
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:258
void copy(T1 &dst, const T2 &src, const int srccomp, const int dstcomp, const int numcomp, const amrex::IntVect &nghost)
Definition field_ops.H:154
void lower_bound(FType &field, const amrex::Real min_value, const int icomp=0)
Definition field_ops.H:380
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:317
amrex::Real global_max_magnitude(FType &field)
Definition field_ops.H:402
Definition field_ops.H:20