Skip to content

Conversation

lwJi
Copy link
Contributor

@lwJi lwJi commented Apr 11, 2025

No description provided.

@lwJi lwJi requested review from eschnett and rhaas80 April 11, 2025 18:51
@rhaas80
Copy link
Member

rhaas80 commented Apr 15, 2025

Since, as far as I recall, in CarpetX, we tie centering <1,1,1> to variable meaning ("is an average") can you explain what the derivative actually does? Computing a derivative of averaged quantities is "strange", since you'd be doing something like:

```
\frac{\partial}{\partial x} \left( \int_{x-h/2}^{x+h/2} \rho(x') dx' / h \right) = (rho(x+h/2) - rho(x-h/2)) / h
```

which is "strange" (but yes it is equal to \partial \rho(x) / \partial x + O(h^2).

@lwJi
Copy link
Contributor Author

lwJi commented Apr 15, 2025

  1. This is only used for the purpose of higher order flux correction (for shock detection purposes).
  2. There might be a cell centered version of Z4cow at some point.

@rhaas80
Copy link
Member

rhaas80 commented Apr 15, 2025

And it actually computes something sensible? Ie what does the calc_copy<1,1,1> routine actually compute?

@lwJi
Copy link
Contributor Author

lwJi commented Apr 15, 2025

It only used to detect shocks. It's an approximation to the cell center value of that cell and it's good enough for shock detection.

calc_copy is only copy from GF3D2 to GF3D5

@rhaas80
Copy link
Member

rhaas80 commented Apr 15, 2025

Ok, so calc_copy<1,1,1> seems ok. calc_deriv<1,1,1> if it does indeed get used to compute "an approximation to the cell center value of that cell" is not any better than just using the cell average directly which is also equal to the value at the center up to O(h^2), isn't it?

@lwJi
Copy link
Contributor Author

lwJi commented Apr 15, 2025

I don't understand. I need cell-centered derivative of a cell-centered grid function for shock detection purpose. The easiest way is to use finite difference. right?

@rhaas80
Copy link
Member

rhaas80 commented Apr 15, 2025

By "cell centered" what do you mean? CarpetX thinks of "<1,1,1>" as "an average over the cell", and not "the value of a function [eg the metric] sampled at the location of the center of the cell". 

Which one do you actually have?

@lwJi
Copy link
Contributor Author

lwJi commented Apr 15, 2025

It’s cell-average. But also an approximation of cell center value. Do you have a even easier way to construct derivative than finite difference

@rhaas80
Copy link
Member

rhaas80 commented Apr 15, 2025

Well, as long as you have checked that indeed calc_derivs2 is a 2nd order accurate approximation of the value at the center of the the cell derivative of the continuous function that was averaged to compute the cell averaged values, then this would be ok-ish.

How is it computed though? Just as a centered finite difference?  This would not be quite correct since it would differ from what a higher-order accurate derivative would have to do. 

Or (much more correctly) as a 2nd order reconstruction and derivative (which may indeed give the same expression, IDK)? I.e. compute the 2nd order polynomial \rho = a + b x + c x^2 such that \int_{xi-h/2}^{xi+h/2} \rho(x') dx' / h = rho_grid(xi) then the value of \partial \rho / \partial x at xi.

@lwJi
Copy link
Contributor Author

lwJi commented Apr 15, 2025

Derivs only provide finite difference

@lwJi
Copy link
Contributor Author

lwJi commented Apr 15, 2025

I think cell-centered grid is more fundamental at amrex level. However, the user can use it to represent cell-average (just as what we did with AsterX).

This PR just provides with the user that if they are using cell-centered grid and use it as sampling at that location they can take derivatives using Derives.

@lwJi
Copy link
Contributor Author

lwJi commented Apr 15, 2025

If the user is using cell-centered grid as cell-average, and finite difference is not an approximation for the derivatives, they can just not call Derivs to get the derivatives.

@lwJi
Copy link
Contributor Author

lwJi commented Apr 15, 2025

When you say that CarpetX assume that <1,1,1> is cell average, I believe you are talking about prolongation. But I believe we have prolongation operator which is not conserved also.

@rhaas80
Copy link
Member

rhaas80 commented Apr 15, 2025

When you say that CarpetX assume that <1,1,1> is cell average, I believe you are talking about prolongation. But I believe we have prolongation operator which is not conserved also.

only in a <..,0,...> direction. CarpetX does currently not handle the "at center but not an average" case.

@lwJi
Copy link
Contributor Author

lwJi commented Apr 15, 2025

prolongate_3d_rf2<CC, CC, CC, POLY, POLY, POLY, 3, 3, 3, FB_NONE>

@rhaas80
Copy link
Member

rhaas80 commented Jun 20, 2025

hmm, I guess we currently cannot use these since CarpetX will pick the prolongation operator based on the centering.

Still not quite sure what your cell centered derivatives act on? On a function sampled at the center or a derivative of the continuous function whose cell averages are stored in the cell?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants