AMReX-Codes / amrex

AMReX: Software Framework for Block Structured AMR
https://amrex-codes.github.io/amrex
Other
540 stars 344 forks source link

Boundary conditions for face-centered variables #3116

Open Xudong-Ke-Lin opened 1 year ago

Xudong-Ke-Lin commented 1 year ago

Dear all,

I am having some problems implementing the FillDomainBoundary() for face-centered variables with non-periodic boundary conditions.

There is this line AMREX_ALWAYS_ASSERT(phi.ixType().cellCentered()) in the AMReX_BCUtil.cpp file that prevents it. Is FillDomainBoundary() only implemented for cell-centered variables? Is there a corresponding function for face-centered or nodal? Thanks in advance.

Best wishes, Don

WeiqunZhang commented 1 year ago

Thanks for reporting this. You can safely remove that assertion. When that function was first added, it only supported cell-centered data because it used PhysBCFunct that did not support face data at that time. But that's no longer the case. We will update that function by removing the assertion and turn it into a template so that the users can call the function directly. (Currently it is meant to be an example that people can copy and paste).

Xudong-Ke-Lin commented 1 year ago

Thank you very much for your reply! Can I safely remove the assertion now or when you update and turn it into a template?

WeiqunZhang commented 1 year ago

You can remove it now.

Xudong-Ke-Lin commented 1 year ago

Thank you!

Xudong-Ke-Lin commented 1 year ago

Hi Weiqun,

Sorry for asking this again but I have some questions in setting the boundary conditions at the top faces.

Firstly, I noticed that setBC() function (from AMReX_BCRec.cpp) used in the AMReX_PhysBCFunct.H file sets the boundary conditions to ind_dir if not at the domain boundaries.

In the AMReX_FilFC_C.cpp file, it never loops the "top" face. I believe this is because gdomain is oversized. To give one example, for a 2D domain with 128x64 cells, with a max_grid_size=32 and the number of ghost cells is 2. The boundary conditions in x are periodic and the BC in y is non-periodic. MultiFab is nodal in the y-direction (and centered in the x-direction). For a given bx with domain [-2,33]x[30,66] (i.e. x from -2 to 33), the gdomain is [-36,163]x[-37,101]. This is because the bcn->lo(idim) == BCType::int_dir condition is fulfilled in both directions: in the x-direction it should be fulfilled but in the y-direction it is fulfilled because of the setBC() function. The result is that this gdomain creates tmp that are [-2,-37]x[30,66], [-2,33]x[30,-37], [164,33]x[30,66] and [-2,33]x[101,66]. None of these tmp are the ghost cells. I should really update [-2,33]x[64,66], but gdomain is "oversized".

To solve this issue, I used the following condition to update gdomain

bcn->lo(idim) == BCType::int_dir && bcn->hi(idim) == BCType::int_dir;

This correctly captures the ghost cells that need an update by only growing the gdmain in the x-direction giving [-36,163]x[0,64]. However, I am not sure if this condition would change other functionalities. Can I just change this condition? Sorry for the long message and thanks in advance.

WeiqunZhang commented 1 year ago

I am sorry. I could not follow what you have described. Could you provide a test code that reproduces the issue?

Xudong-Ke-Lin commented 1 year ago

Hi Weiqun, sorry for replying late. I was trying to get you a test code that reproduces the issue, but then I realised that my problem was that I was not using an updated version of AMReX. All seems to work now, thank you very much!

Xudong-Ke-Lin commented 1 year ago

Hi Weiqun, sorry for reopening the issue again, I have recently spotted a problem related to face-centered data boundary conditions.

I tried using this problem: Tests/Amr/Advection_AmrLevel/Exec/UniformVelocity

I am also attaching the files that I changed problem.zip

The problem comes from when using for example x-face-centered data, the top y-domain ghost cells are not changed when using FillDomainBoundary(). This does not happen for cell-centered data, and I have included both as an example, both before and after using FillDomainBoundary().

Many thanks.

WeiqunZhang commented 1 year ago

If you are using AmrLevel, you should NOT call FillDomainBounary and FillBoundary. FillPatch will take care of everything. For your xface type, you do need to a different interpolater other than cell_cons_interp, because it's not cell data. You can use face_linear_interp.

Xudong-Ke-Lin commented 1 year ago

Hi Weiqun,

Thank you very much for your reply and information. After I changed the data (e.g. line 413), I am trying to calculate the ghost cells again. If I use FillPatch(), I believe it returns me the old data, not the updated data with updated ghost cells.

problem2.zip