Skip to content

Commit

Permalink
Illustrate with examples
Browse files Browse the repository at this point in the history
  • Loading branch information
marchdf committed Jun 14, 2024
1 parent a037e52 commit 532804c
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 102 deletions.
1 change: 0 additions & 1 deletion amr-wind/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ target_include_directories(${amr_wind_lib_name} PUBLIC
add_subdirectory(core)
add_subdirectory(boundary_conditions)
add_subdirectory(convection)
add_subdirectory(derive)
add_subdirectory(diffusion)
add_subdirectory(projection)
add_subdirectory(setup)
Expand Down
50 changes: 21 additions & 29 deletions amr-wind/core/Field.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,22 +391,17 @@ void Field::to_uniform_space() noexcept

// scale velocity to accommodate for mesh mapping -> U^bar = U * J/fac
for (int lev = 0; lev < m_repo.num_active_levels(); ++lev) {
for (amrex::MFIter mfi(mesh_fac(lev)); mfi.isValid(); ++mfi) {

amrex::Array4<amrex::Real> const& field = operator()(lev).array(
mfi);
amrex::Array4<amrex::Real const> const& fac =
mesh_fac(lev).const_array(mfi);
amrex::Array4<amrex::Real const> const& detJ =
mesh_detJ(lev).const_array(mfi);

amrex::ParallelFor(
mfi.growntilebox(), AMREX_SPACEDIM,
[=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept {
field(i, j, k, n) *= detJ(i, j, k) / fac(i, j, k, n);
});
}
const auto& fac = mesh_fac(lev).const_arrays();
const auto& detJ = mesh_detJ(lev).const_arrays();
const auto& field = operator()(lev).arrays();
amrex::ParallelFor(
mesh_fac(lev), amrex::IntVect(0), operator()(lev).nComp(),
[=] AMREX_GPU_DEVICE(int nbx, int i, int j, int k, int n) noexcept {
field[nbx](i, j, k, n) *=
detJ[nbx](i, j, k) / fac[nbx](i, j, k, n);
});
}
amrex::Gpu::synchronize();
m_mesh_mapped = true;
}

Expand All @@ -426,21 +421,18 @@ void Field::to_stretched_space() noexcept

// scale field back to stretched mesh -> U = U^bar * fac/J
for (int lev = 0; lev < m_repo.num_active_levels(); ++lev) {
for (amrex::MFIter mfi(mesh_fac(lev)); mfi.isValid(); ++mfi) {
amrex::Array4<amrex::Real> const& field = operator()(lev).array(
mfi);
amrex::Array4<amrex::Real const> const& fac =
mesh_fac(lev).const_array(mfi);
amrex::Array4<amrex::Real const> const& detJ =
mesh_detJ(lev).const_array(mfi);

amrex::ParallelFor(
mfi.growntilebox(), AMREX_SPACEDIM,
[=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept {
field(i, j, k, n) *= fac(i, j, k, n) / detJ(i, j, k);
});
}

const auto& fac = mesh_fac(lev).const_arrays();
const auto& detJ = mesh_detJ(lev).const_arrays();
const auto& field = operator()(lev).arrays();
amrex::ParallelFor(
mesh_fac(lev), amrex::IntVect(0), operator()(lev).nComp(),
[=] AMREX_GPU_DEVICE(int nbx, int i, int j, int k, int n) noexcept {
field[nbx](i, j, k, n) *=
fac[nbx](i, j, k, n) / detJ[nbx](i, j, k);
});
}
amrex::Gpu::synchronize();
m_mesh_mapped = false;
}

Expand Down
54 changes: 24 additions & 30 deletions amr-wind/core/field_ops.H
Original file line number Diff line number Diff line change
Expand Up @@ -310,18 +310,15 @@ lower_bound(FType& field, const amrex::Real min_value, const int icomp = 0)
const auto& repo = field.repo();
const int nlevels = repo.num_active_levels();
for (int lev = 0; lev < nlevels; ++lev) {

for (amrex::MFIter mfi(field(lev)); mfi.isValid(); ++mfi) {
const auto& bx = mfi.tilebox();
const auto& field_arr = field(lev).array(mfi);

amrex::ParallelFor(
bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
field_arr(i, j, k, icomp) =
amrex::max(min_value, field_arr(i, j, k, icomp));
});
}
const auto& farrs = field(lev).arrays();
amrex::ParallelFor(
field(lev),
[=] AMREX_GPU_DEVICE(int nbx, int i, int j, int k) noexcept {
farrs[nbx](i, j, k, icomp) =
amrex::max(min_value, farrs[nbx](i, j, k, icomp));
});
}
amrex::Gpu::synchronize();
}

/** Computes the global maximum of a field from all levels
Expand Down Expand Up @@ -378,28 +375,25 @@ inline void normalize(FType& field)

const int nlevels = repo.num_active_levels();
for (int lev = 0; lev < nlevels; ++lev) {

for (amrex::MFIter mfi(field(lev)); mfi.isValid(); ++mfi) {
const auto& bx = mfi.tilebox();
const auto& field_arr = field(lev).array(mfi);

amrex::ParallelFor(
bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
// Compute magnitude
amrex::Real mag = 0.;
const auto& farrs = field(lev).arrays();
amrex::ParallelFor(
field(lev),
[=] AMREX_GPU_DEVICE(int nbx, int i, int j, int k) noexcept {
auto farr = farrs[nbx];
// Compute magnitude
amrex::Real mag = 0.;
for (int icomp = 0; icomp < ncomp; ++icomp) {
mag = mag + farr(i, j, k, icomp) * farr(i, j, k, icomp);
}
if (mag > eps) {
for (int icomp = 0; icomp < ncomp; ++icomp) {
mag = mag + field_arr(i, j, k, icomp) *
field_arr(i, j, k, icomp);
}
if (mag > eps) {
for (int icomp = 0; icomp < ncomp; ++icomp) {
field_arr(i, j, k, icomp) =
field_arr(i, j, k, icomp) / std::sqrt(mag);
}
farr(i, j, k, icomp) =
farr(i, j, k, icomp) / std::sqrt(mag);
}
});
}
}
});
}
amrex::Gpu::synchronize();
}

} // namespace amr_wind::field_ops
Expand Down
5 changes: 0 additions & 5 deletions amr-wind/derive/CMakeLists.txt

This file was deleted.

37 changes: 0 additions & 37 deletions amr-wind/derive/field_algebra.cpp

This file was deleted.

0 comments on commit 532804c

Please sign in to comment.