Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eyoo/multicuts #1

Open
wants to merge 39 commits into
base: test-pr
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
df6b6d0
This branch is for visulization of multicut faces/cells. We mainly ad…
ejyoo921 Jun 28, 2024
734f7aa
As a baby step, we now can see how many multicuts detected, along wit…
ejyoo921 Jun 28, 2024
fb5c787
All the parts are implemented to write plot files of multicut locatio…
ejyoo921 Jul 2, 2024
ac65ec6
Merge branch 'AMReX-Codes:development' into eyoo/multicuts
ejyoo921 Jul 2, 2024
70b5111
1) Added parmparse called "plt_multiple_cuts" which is false by defau…
ejyoo921 Jul 3, 2024
b35cba5
Edited the parmparse option to turn on/off visualization/printing of…
ejyoo921 Jul 18, 2024
5c7561e
Erased everything for plotting; We now generate one text file loc_mul…
ejyoo921 Jul 19, 2024
92c65fa
We found a 'right' place to produce the plot file in AMReX_EB2_Level.…
ejyoo921 Jul 26, 2024
4b4b890
1) Created a multicut called 'multicut_bx'.
ejyoo921 Jul 29, 2024
823e97f
Deleted non-necessary printings.
ejyoo921 Jul 29, 2024
4007d81
Deleted total_multicuts value
ejyoo921 Jul 29, 2024
8e67650
minor changed after Bruce's comments. Run a tutorial input with a rot…
ejyoo921 Aug 7, 2024
1a7edb3
We now create separate plot files containing multi-cut locations from…
ejyoo921 Aug 15, 2024
5fe3c8e
cleaned up some useless comments. Now writing (i,j,k) and face boxes …
ejyoo921 Aug 26, 2024
2fd9f4d
<Cherry-pick due to detached head>
ejyoo921 Aug 15, 2024
11e7ddd
Merge branch 'AMReX-Codes:development' into eyoo/multicuts
ejyoo921 Aug 27, 2024
1b1a970
Cleanup more no useful comments && using now std::ofstream for text f…
ejyoo921 Aug 27, 2024
cc0af83
Removed #ifndef condition for GPU use since we no longer use amrex::P…
ejyoo921 Aug 28, 2024
436bb3f
Return to PrintToFile since ofstream is not compatible with CUDA
ejyoo921 Aug 28, 2024
0536861
Forgot to add #ifndef back
ejyoo921 Aug 28, 2024
9b63533
added AMREX_USE_GPU back -> check with Kestrel. is this even compilin…
ejyoo921 Aug 28, 2024
427d166
I just deleted the print txt file part in AMReX_EB2_3D_C.cpp. We may …
ejyoo921 Aug 29, 2024
df35481
2D version is added -> how can we chekc?
ejyoo921 Aug 29, 2024
bb08807
Whitespace edit
ejyoo921 Aug 29, 2024
3c0b9ce
Fixed 2D case error -
ejyoo921 Aug 29, 2024
7db7054
Fixed whitespace things
Aug 30, 2024
3aeff0e
RE-generate the MF for face-centered one. called multicut_face. 2D is…
ejyoo921 Aug 30, 2024
b8179f1
RE-generate the MF for face-centered one. called multicut_face. 2D is…
ejyoo921 Aug 30, 2024
0023869
1) fixed 2D bug
ejyoo921 Aug 30, 2024
0f19915
Whitespace sytling
Aug 30, 2024
fb47a1a
changed the location to call mcx,y,z arrays -> 2D is checked as well
ejyoo921 Sep 6, 2024
a0dc9c6
fixed notations in .H files
ejyoo921 Sep 6, 2024
048d390
Merge branch 'AMReX-Codes:development' into eyoo/multicuts
ejyoo921 Sep 6, 2024
8b4c582
Edited based on Bruce's comments on Sep 6.
ejyoo921 Sep 9, 2024
75b419a
I don't understand this pull -
ejyoo921 Sep 9, 2024
766e8a9
changed the way we fill the plot file data: Value of 2 is regular, 0 …
ejyoo921 Sep 9, 2024
0ba88b9
Merge branch 'AMReX-Codes:development' into eyoo/multicuts
ejyoo921 Sep 10, 2024
2304763
Merge branch 'AMReX-Codes:development' into eyoo/multicuts
ejyoo921 Sep 11, 2024
8eb29d8
make chage to cell-centered MF
ejyoo921 Sep 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 37 additions & 4 deletions Src/EB/AMReX_EB2_3D_C.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#include <AMReX_EB2_C.H>
//EY
#include <AMReX_MultiFab.H>
#include <AMReX_PlotFileUtil.H>

namespace amrex::EB2 {

Expand Down Expand Up @@ -368,7 +371,8 @@ int build_faces (Box const& bx, Array4<EBCellFlag> const& cell,
Array4<Real> const& m2z,
GpuArray<Real,AMREX_SPACEDIM> const& dx,
GpuArray<Real,AMREX_SPACEDIM> const& problo,
bool cover_multiple_cuts) noexcept
bool cover_multiple_cuts,
bool plt_multiple_cuts, Array4<Real> const& multicut_arr) noexcept
{
Gpu::Buffer<int> nmulticuts = {0};
int* hp = nmulticuts.hostData();
Expand Down Expand Up @@ -460,6 +464,11 @@ int build_faces (Box const& bx, Array4<EBCellFlag> const& cell,

if (ncuts > 2) {
Gpu::Atomic::Add(dp,1);
if (plt_multiple_cuts){
ejyoo921 marked this conversation as resolved.
Show resolved Hide resolved
multicut_arr(i,j,k) = 10.0;
// Not GPU friendly
amrex::PrintToFile("loc_multicuts") << "fx: (x,y,z) = (" << problo[0]+(i)*dx[0] << ","<< problo[1]+(j)*dx[1] << "," << problo[2]+(k)*dx[2] << ") \n";
}
}

if ((ncuts > 2) || (lym <= small && lyp <= small && lzm <= small && lzp <= small)) {
Expand Down Expand Up @@ -568,6 +577,11 @@ int build_faces (Box const& bx, Array4<EBCellFlag> const& cell,

if (ncuts > 2) {
Gpu::Atomic::Add(dp,1);
if (plt_multiple_cuts){
multicut_arr(i,j,k) = 10.0;
// Not GPU friendly
amrex::PrintToFile("loc_multicuts") << "fy: (x,y,z) = (" << problo[0]+(i)*dx[0] << ","<< problo[1]+(j)*dx[1] << "," << problo[2]+(k)*dx[2] << ") \n";
}
}

if ((ncuts > 2) || (lxm <= small && lxp <= small && lzm <= small && lzp <= small)) {
Expand Down Expand Up @@ -676,6 +690,11 @@ int build_faces (Box const& bx, Array4<EBCellFlag> const& cell,

if (ncuts > 2) {
Gpu::Atomic::Add(dp,1);
if (plt_multiple_cuts){
multicut_arr(i,j,k) = 10.0;
ejyoo921 marked this conversation as resolved.
Show resolved Hide resolved
// Not GPU friendly
amrex::PrintToFile("loc_multicuts") << "fz: (x,y,z) = (" << problo[0]+(i)*dx[0] << ","<< problo[1]+(j)*dx[1] << "," << problo[2]+(k)*dx[2] << ") \n";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

surround the PrintToFile bit with an #ifndef AMREX_USE_GPU so this can still compile on GPU.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let me try to run things.

}
}

if ((ncuts > 2) || (lxm <= small && lxp <= small && lym <= small && lyp <= small)) {
Expand Down Expand Up @@ -766,7 +785,16 @@ int build_faces (Box const& bx, Array4<EBCellFlag> const& cell,
}
});
} else {
amrex::Abort("amrex::EB2::build_faces: more than 2 cuts not supported");
//EY: Let's see the location of multicuts before aborting!
amrex::Print() << "dx = " << dx[0] << ", dy = " << dx[1] << ", dz = " << dx[2] << "\n";
ejyoo921 marked this conversation as resolved.
Show resolved Hide resolved
amrex::Print() << "Total number of multicut cells = " << *hp << "\n";

if (plt_multiple_cuts){
amrex::Print() << "Creating outputs for multicut locations." << "\n";
}
else{
amrex::Abort("amrex::EB2::build_faces: more than 2 cuts not supported");
}
}
}

Expand All @@ -785,7 +813,7 @@ void build_cells (Box const& bx, Array4<EBCellFlag> const& cell,
Array4<Real> const& barea, Array4<Real> const& bcent,
Array4<Real> const& bnorm, Array4<EBCellFlag> const& ctmp,
Array4<Real> const& levset, Real small_volfrac, Geometry const& geom,
bool extend_domain_face, bool cover_multiple_cuts,
bool extend_domain_face, bool cover_multiple_cuts, bool plt_multiple_cuts,
int& nsmallcells, int& nmulticuts) noexcept
{
Gpu::Buffer<int> n_smallcell_multicuts = {0,0};
Expand Down Expand Up @@ -930,7 +958,12 @@ void build_cells (Box const& bx, Array4<EBCellFlag> const& cell,

if (nsmallcells > 0 || nmulticuts > 0) {
if (!cover_multiple_cuts && nmulticuts > 0) {
amrex::Abort("amrex::EB2::build_cells: multi-cuts not supported");
if (plt_multiple_cuts){
amrex::Print() << "Passing EB2::build_cells" << "\n";
ejyoo921 marked this conversation as resolved.
Show resolved Hide resolved
}
else{
amrex::Abort("amrex::EB2::build_cells: multi-cuts not supported");
}
}
return;
} else {
Expand Down
5 changes: 3 additions & 2 deletions Src/EB/AMReX_EB2_C.H
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ int build_faces (Box const& bx, Array4<EBCellFlag> const& cell,
Array4<Real> const& m2z,
GpuArray<Real,AMREX_SPACEDIM> const& dx,
GpuArray<Real,AMREX_SPACEDIM> const& problo,
bool cover_multiple_cuts) noexcept;
bool cover_multiple_cuts,
bool plt_multiple_cuts, Array4<Real> const& multicut_arr) noexcept; //EY

void build_cells (Box const& bx, Array4<EBCellFlag> const& cell,
Array4<Type_t> const& fx, Array4<Type_t> const& fy,
Expand All @@ -69,7 +70,7 @@ void build_cells (Box const& bx, Array4<EBCellFlag> const& cell,
Array4<Real> const& barea, Array4<Real> const& bcent,
Array4<Real> const& bnorm, Array4<EBCellFlag> const& ctmp,
Array4<Real> const& levset, Real small_volfrac, Geometry const& geom,
bool extend_domain_face, bool cover_multiple_cuts,
bool extend_domain_face, bool cover_multiple_cuts, bool plt_multiple_cuts, //EY
int& nsmallcells, int& nmulticuts) noexcept;

void set_connection_flags(Box const& bx, Box const& bxg1,
Expand Down
24 changes: 22 additions & 2 deletions Src/EB/AMReX_EB2_Level.H
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
#include <AMReX_EB2_C.H>
#include <AMReX_EB2_IF_AllRegular.H>

//EY: Plotting
#include <AMReX_PlotFileUtil.H>

#ifdef AMREX_USE_OMP
#include <omp.h>
#endif
Expand Down Expand Up @@ -98,6 +101,9 @@ protected:
bool m_has_eb_info = true;
IndexSpace const* m_parent;

//EY
MultiFab multicut_bx;
ejyoo921 marked this conversation as resolved.
Show resolved Hide resolved

private:
template <typename G> friend class GShopLevel;

Expand Down Expand Up @@ -167,12 +173,14 @@ GShopLevel<G>::define_fine (G const& gshop, const Geometry& geom,
Real small_volfrac = 1.e-14;
#endif
bool cover_multiple_cuts = false;
bool plt_multiple_cuts = false; //EY
int maxiter = 32;
{
ParmParse pp("eb2");
pp.queryAdd("small_volfrac", small_volfrac);
pp.queryAdd("cover_multiple_cuts", cover_multiple_cuts);
pp.queryAdd("maxiter", maxiter);
pp.queryAdd("plt_multiple_cuts", plt_multiple_cuts); //EY
}
maxiter = std::min(100000, maxiter);

Expand Down Expand Up @@ -290,6 +298,9 @@ GShopLevel<G>::define_fine (G const& gshop, const Geometry& geom,
m_bndryarea.define(m_grids, m_dmap, 1, ng, mf_info);
m_bndrycent.define(m_grids, m_dmap, AMREX_SPACEDIM, ng, mf_info);
m_bndrynorm.define(m_grids, m_dmap, AMREX_SPACEDIM, ng, mf_info);
//EY
multicut_bx.define(m_grids, m_dmap, 1, ng, mf_info);

for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
m_areafrac[idim].define(amrex::convert(m_grids, IntVect::TheDimensionVector(idim)),
m_dmap, 1, ng, mf_info);
Expand Down Expand Up @@ -354,6 +365,9 @@ GShopLevel<G>::define_fine (G const& gshop, const Geometry& geom,
Array4<Real> const& bar = m_bndryarea.array(mfi);
Array4<Real> const& bct = m_bndrycent.array(mfi);
Array4<Real> const& bnm = m_bndrynorm.array(mfi);
//EY:
Array4<Real> const& multicut_arr = multicut_bx.array(mfi);

AMREX_D_TERM(Array4<Real> const& apx = m_areafrac[0].array(mfi);,
Array4<Real> const& apy = m_areafrac[1].array(mfi);,
Array4<Real> const& apz = m_areafrac[2].array(mfi););
Expand Down Expand Up @@ -415,7 +429,7 @@ GShopLevel<G>::define_fine (G const& gshop, const Geometry& geom,

nmc = build_faces(vbx, cfg, ftx, fty, ftz, xdg, ydg, zdg, lst,
xip, yip, zip, apx, apy, apz, fcx, fcy, fcz,
xm2, ym2, zm2, dx, problo, cover_multiple_cuts);
xm2, ym2, zm2, dx, problo, cover_multiple_cuts, plt_multiple_cuts, multicut_arr);

cellflagtmp.resize(m_cellflag[mfi].box());
Elixir cellflagtmp_eli = cellflagtmp.elixir();
Expand All @@ -424,7 +438,7 @@ GShopLevel<G>::define_fine (G const& gshop, const Geometry& geom,
build_cells(vbx, cfg, ftx, fty, ftz, apx, apy, apz,
fcx, fcy, fcz, xm2, ym2, zm2, dx, vfr, ctr,
bar, bct, bnm, cfgtmp, lst,
small_volfrac, geom, extend_domain_face, cover_multiple_cuts,
small_volfrac, geom, extend_domain_face, cover_multiple_cuts, plt_multiple_cuts,
nsm, nmc);

// Because it is used in a synchronous reduction kernel in
Expand Down Expand Up @@ -476,6 +490,12 @@ GShopLevel<G>::define_fine (G const& gshop, const Geometry& geom,
nsmallcells += nsm;
nmulticuts += nmc;
}
// EY: Here -> make plot file
if (plt_multiple_cuts)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move after the ParallelAllReduce for nmulticuts, then add nmulticuts > 0 && !cover_multiple_cuts to the conditional

{
WriteSingleLevelPlotfile("plt", multicut_bx, {"multicut"}, geom, 0.0, 0);
amrex::Abort("amrex::EB2::build_faces: more than 2 cuts not supported");
}
}

ParallelAllReduce::Sum<int>({nsmallcells,nmulticuts}, ParallelContext::CommunicatorSub());
Expand Down