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

Fix oops #1383

Merged
merged 2 commits into from
Jan 16, 2024
Merged

Fix oops #1383

merged 2 commits into from
Jan 16, 2024

Conversation

asalmgren
Copy link
Collaborator

No description provided.

@asalmgren asalmgren merged commit 7bc2df1 into erf-model:development Jan 16, 2024
11 checks passed
@asalmgren asalmgren deleted the fix_oops branch January 16, 2024 20:31
@@ -130,10 +129,16 @@ void ERFPC::AdvectWithFlow ( MultiFab* a_umac,
iv[1] += domain.smallEnd()[1];
Copy link
Contributor

Choose a reason for hiding this comment

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

@AMLattanzi @asalmgren Can lines 124-129 be replaced by ERFParticlesAssignor(p, plo, dxi, domain) (defined in ERFPC.H)? Same with lines 226-231 below?

@@ -98,8 +98,7 @@ void ERFPC::AdvectWithFlow ( MultiFab* a_umac,
bool use_terrain = (a_z_height != nullptr);
auto zheight = use_terrain ? (*a_z_height)[grid].array() : Array4<Real>{};
Copy link
Contributor

@debog debog Jan 20, 2024

Choose a reason for hiding this comment

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

@asalmgren @AMLattanzi how does this make zheight available on the GPU?

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is due to C++ lambda capture. If a C++ lambda uses [=], it will make a copy of all the variables used in the lambda's function body. These variables are part of the lambda function object. In the case of GPU, the CUDA runtime will copy the lambda function to GPU at kernel launch.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks, @WeiqunZhang! Makes sense now.

Comment on lines 130 to 144
ParticleReal zlo, zhi;
if (use_terrain) {
zlo = Real(0.25) * (zheight(iv[0],iv[1] ,iv[2] ) + zheight(iv[0]+1,iv[1] ,iv[2] ) +
zheight(iv[0],iv[1]+1,iv[2] ) + zheight(iv[0]+1,iv[1]+1,iv[2] ));
zhi = Real(0.25) * (zheight(iv[0],iv[1] ,iv[2]+1) + zheight(iv[0]+1,iv[1] ,iv[2]+1) +
zheight(iv[0],iv[1]+1,iv[2]+1) + zheight(iv[0]+1,iv[1]+1,iv[2]+1));
Real lx = (p.pos(0)-plo[0])*dxi[0] - static_cast<Real>(iv[0]-domain.smallEnd()[0]);
Real ly = (p.pos(1)-plo[1])*dxi[1] - static_cast<Real>(iv[1]-domain.smallEnd()[1]);
zlo = zheight(iv[0] ,iv[1] ,iv[2] ) * (1.0-lx) * (1.0-ly) +
zheight(iv[0]+1,iv[1] ,iv[2] ) * lx * (1.0-ly) +
zheight(iv[0] ,iv[1]+1,iv[2] ) * (1.0-lx) * ly +
zheight(iv[0]+1,iv[1]+1,iv[2] ) * lx * ly;
zhi = zheight(iv[0] ,iv[1] ,iv[2]+1) * (1.0-lx) * (1.0-ly) +
zheight(iv[0]+1,iv[1] ,iv[2]+1) * lx * (1.0-ly) +
zheight(iv[0] ,iv[1]+1,iv[2]+1) * (1.0-lx) * ly +
zheight(iv[0]+1,iv[1]+1,iv[2]+1) * lx * ly;
} else {
zlo = iv[2] * dx[2];
zhi = (iv[2]+1) * dx[2];
Copy link
Contributor

@debog debog Jan 20, 2024

Choose a reason for hiding this comment

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

@AMLattanzi @asalmgren Can lines 130-145 (or 130-151) be written as a separate function/functor? If functor, it could store zheight and use_terrain as member data? And we could use it for lines 232-252 as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually I want to move this functionality into a routine in amrex -- it is used by multiple codes. I was just going to make a new function called something like update_particle_idata that takes one particle and the zheight array. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

That would be nice since this is a particle functionality, not an ERF-specific thing. But terrain and zheight are specific to atmospheric flows. To make it more general, could we have xcoord, ycoord, zcoord (defaulted to nullptr?) instead of just zheight that allows mapping in all dimensions? ERF would then call this function with only zheight.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We're working on the generalized functionality ...

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we could parallel what is done in the BinMapper functor. This would move the functionality to AMReX, clean up the ERF code since the above snippet now lives in a functor, and would be similar to what we do without curvilinear coordinates.

@debog
Copy link
Contributor

debog commented Jan 20, 2024

@asalmgren @AMLattanzi If you agree with my comments above, then I can try to implement them and send a pull request.

@gardner48 Tagging you so that you get notified as well.

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.

4 participants