From a9d9320314ae9092da938f3e4521d0e9fbf7b143 Mon Sep 17 00:00:00 2001 From: Andy Nonaka Date: Thu, 19 Dec 2024 10:31:37 -0800 Subject: [PATCH 1/5] add 2d support --- ExampleCodes/FFT/Basic/inputs_2d | 11 ++++++ ExampleCodes/FFT/Basic/{inputs => inputs_3d} | 0 ExampleCodes/FFT/Basic/main.cpp | 41 ++++++++++++-------- 3 files changed, 36 insertions(+), 16 deletions(-) create mode 100644 ExampleCodes/FFT/Basic/inputs_2d rename ExampleCodes/FFT/Basic/{inputs => inputs_3d} (100%) diff --git a/ExampleCodes/FFT/Basic/inputs_2d b/ExampleCodes/FFT/Basic/inputs_2d new file mode 100644 index 00000000..4b6a0c84 --- /dev/null +++ b/ExampleCodes/FFT/Basic/inputs_2d @@ -0,0 +1,11 @@ +n_cell_x = 64 +n_cell_y = 64 + +max_grid_size_x = 32 +max_grid_size_y = 32 + +prob_lo_x = 0. +prob_lo_y = 0. + +prob_hi_x = 1. +prob_hi_y = 1. diff --git a/ExampleCodes/FFT/Basic/inputs b/ExampleCodes/FFT/Basic/inputs_3d similarity index 100% rename from ExampleCodes/FFT/Basic/inputs rename to ExampleCodes/FFT/Basic/inputs_3d diff --git a/ExampleCodes/FFT/Basic/main.cpp b/ExampleCodes/FFT/Basic/main.cpp index 34834389..b0702fc7 100644 --- a/ExampleCodes/FFT/Basic/main.cpp +++ b/ExampleCodes/FFT/Basic/main.cpp @@ -29,10 +29,10 @@ int main (int argc, char* argv[]) // physical dimensions of the domain Real prob_lo_x = 0.; - Real prob_lo_y = 0.; - Real prob_lo_z = 0.; Real prob_hi_x = 1.; + Real prob_lo_y = 0.; Real prob_hi_y = 1.; + Real prob_lo_z = 0.; Real prob_hi_z = 1.; // ********************************** @@ -47,25 +47,33 @@ int main (int argc, char* argv[]) pp.get("n_cell_x",n_cell_x); pp.get("n_cell_y",n_cell_y); +#if (AMREX_SPACEDIM == 3) pp.get("n_cell_z",n_cell_z); +#endif pp.get("max_grid_size_x",max_grid_size_x); pp.get("max_grid_size_y",max_grid_size_y); +#if (AMREX_SPACEDIM == 3) pp.get("max_grid_size_z",max_grid_size_z); +#endif pp.query("prob_lo_x",prob_lo_x); - pp.query("prob_lo_y",prob_lo_y); - pp.query("prob_lo_z",prob_lo_z); - pp.query("prob_hi_x",prob_hi_x); + pp.query("prob_lo_y",prob_lo_y); pp.query("prob_hi_y",prob_hi_y); +#if (AMREX_SPACEDIM == 3) + pp.query("prob_lo_z",prob_lo_z); pp.query("prob_hi_z",prob_hi_z); +#endif + } // Determine the domain length in each direction - Real L_x = std::abs(prob_hi_x - prob_lo_x); - Real L_y = std::abs(prob_hi_y - prob_lo_y); - Real L_z = std::abs(prob_hi_z - prob_lo_z); + Real cen_x = (prob_hi_x - prob_lo_x) / 2.; + Real cen_y = (prob_hi_y - prob_lo_y) / 2.; +#if (AMREX_SPACEDIM == 3) + Real cen_z = (prob_hi_z - prob_lo_z) / 2.; +#endif // define lower and upper indices of domain IntVect dom_lo(AMREX_D_DECL( 0, 0, 0)); @@ -122,11 +130,14 @@ int main (int argc, char* argv[]) // SET VALUES FOR EACH CELL // ********************************** - Real x = (i+0.5) * dx[0]; - Real y = (AMREX_SPACEDIM>=2) ? (j+0.5) * dx[1] : 0.; - Real z = (AMREX_SPACEDIM==3) ? (k+0.5) * dx[2] : 0.; - - phi_ptr(i,j,k) = std::exp(-10.*((x-0.5)*(x-0.5)+(y-0.5)*(y-0.5)+(z-0.5)*(z-0.5))); + Real x = prob_lo_x + (i+0.5) * dx[0]; + Real y = prob_lo_y + (j+0.5) * dx[1]; +#if (AMREX_SPACEDIM == 2) + phi_ptr(i,j,k) = std::exp(-10.*((x-cen_x)*(x-cen_x)+(y-cen_y)*(y-cen_y))); +#elif (AMREX_SPACEDIM == 3) + Real z = prob_lo_z + (k+0.5) * dx[2]; + phi_ptr(i,j,k) = std::exp(-10.*((x-cen_x)*(x-cen_x)+(y-cen_y)*(y-cen_y)+(z-cen_z)*(z-cen_z))); +#endif }); } @@ -161,9 +172,7 @@ int main (int argc, char* argv[]) my_fft.backward(phi_after); // scale phi_after by 1/n_cells so it matches the original phi - long n_cells = n_cell_x; - if (AMREX_SPACEDIM >= 2) n_cells *= n_cell_y; - if (AMREX_SPACEDIM >= 3) n_cells *= n_cell_z; + long n_cells = (AMREX_SPACEDIM == 2) ? n_cell_x*n_cell_y : n_cell_x*n_cell_y*n_cell_z; phi_after.mult(1./n_cells); // time and step are dummy variables required to WriteSingleLevelPlotfile From 2cd80d539b527f184552566f8dafc5de78930be1 Mon Sep 17 00:00:00 2001 From: Andy Nonaka Date: Thu, 19 Dec 2024 10:32:15 -0800 Subject: [PATCH 2/5] whitespace --- ExampleCodes/FFT/Basic/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ExampleCodes/FFT/Basic/main.cpp b/ExampleCodes/FFT/Basic/main.cpp index b0702fc7..bac3a176 100644 --- a/ExampleCodes/FFT/Basic/main.cpp +++ b/ExampleCodes/FFT/Basic/main.cpp @@ -132,7 +132,7 @@ int main (int argc, char* argv[]) Real x = prob_lo_x + (i+0.5) * dx[0]; Real y = prob_lo_y + (j+0.5) * dx[1]; -#if (AMREX_SPACEDIM == 2) +#if (AMREX_SPACEDIM == 2) phi_ptr(i,j,k) = std::exp(-10.*((x-cen_x)*(x-cen_x)+(y-cen_y)*(y-cen_y))); #elif (AMREX_SPACEDIM == 3) Real z = prob_lo_z + (k+0.5) * dx[2]; From b17550b7d4547f8c4270adca30c9731425b01a1c Mon Sep 17 00:00:00 2001 From: Andy Nonaka Date: Thu, 19 Dec 2024 11:27:39 -0800 Subject: [PATCH 3/5] dependencies for CI --- .github/workflows/dependencies/dependencies_hip.sh | 3 ++- .github/workflows/dependencies/dependencies_nvcc11.sh | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/dependencies/dependencies_hip.sh b/.github/workflows/dependencies/dependencies_hip.sh index ab1151c2..93522a5f 100755 --- a/.github/workflows/dependencies/dependencies_hip.sh +++ b/.github/workflows/dependencies/dependencies_hip.sh @@ -57,7 +57,8 @@ sudo apt-get install -y --no-install-recommends \ roctracer-dev \ rocprofiler-dev \ rocrand-dev \ - rocprim-dev + rocprim-dev \ + rocsparse-dev # activate # diff --git a/.github/workflows/dependencies/dependencies_nvcc11.sh b/.github/workflows/dependencies/dependencies_nvcc11.sh index fae05417..c7fb48ec 100755 --- a/.github/workflows/dependencies/dependencies_nvcc11.sh +++ b/.github/workflows/dependencies/dependencies_nvcc11.sh @@ -39,6 +39,7 @@ sudo apt-get install -y \ cuda-minimal-build-11-2 \ cuda-nvml-dev-11-2 \ cuda-nvtx-11-2 \ - libcurand-dev-11-2 + libcurand-dev-11-2 \ + libcusparse-dev-11-2 sudo ln -s cuda-11.2 /usr/local/cuda From 8780f072f63713323f6d045d131a14b7d63af2e8 Mon Sep 17 00:00:00 2001 From: Andy Nonaka Date: Thu, 19 Dec 2024 11:29:23 -0800 Subject: [PATCH 4/5] change width of gaussian to illicit more structure in the fft --- ExampleCodes/FFT/Basic/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ExampleCodes/FFT/Basic/main.cpp b/ExampleCodes/FFT/Basic/main.cpp index bac3a176..0ec3d676 100644 --- a/ExampleCodes/FFT/Basic/main.cpp +++ b/ExampleCodes/FFT/Basic/main.cpp @@ -133,10 +133,10 @@ int main (int argc, char* argv[]) Real x = prob_lo_x + (i+0.5) * dx[0]; Real y = prob_lo_y + (j+0.5) * dx[1]; #if (AMREX_SPACEDIM == 2) - phi_ptr(i,j,k) = std::exp(-10.*((x-cen_x)*(x-cen_x)+(y-cen_y)*(y-cen_y))); + phi_ptr(i,j,k) = std::exp(-500.*((x-cen_x)*(x-cen_x)+(y-cen_y)*(y-cen_y))); #elif (AMREX_SPACEDIM == 3) Real z = prob_lo_z + (k+0.5) * dx[2]; - phi_ptr(i,j,k) = std::exp(-10.*((x-cen_x)*(x-cen_x)+(y-cen_y)*(y-cen_y)+(z-cen_z)*(z-cen_z))); + phi_ptr(i,j,k) = std::exp(-500.*((x-cen_x)*(x-cen_x)+(y-cen_y)*(y-cen_y)+(z-cen_z)*(z-cen_z))); #endif }); From d261a37a466260fcdfe032765c7169b371d7efc9 Mon Sep 17 00:00:00 2001 From: Andy Nonaka Date: Thu, 19 Dec 2024 11:54:32 -0800 Subject: [PATCH 5/5] proper spectral box --- ExampleCodes/FFT/Basic/main.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ExampleCodes/FFT/Basic/main.cpp b/ExampleCodes/FFT/Basic/main.cpp index 0ec3d676..6df9a304 100644 --- a/ExampleCodes/FFT/Basic/main.cpp +++ b/ExampleCodes/FFT/Basic/main.cpp @@ -179,8 +179,7 @@ int main (int argc, char* argv[]) Real time = 0.; int step = 0; - Box cdomain = geom.Domain(); - cdomain.setBig(0,cdomain.length(0)/2); + Box cdomain = cba.minimalBox(); Geometry cgeom(cdomain, real_box, CoordSys::cartesian, is_periodic); // arguments