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

Fixing divergence error with AMR (Issue #617) #625

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

Conversation

tomidakn
Copy link
Contributor

This is to fix the divergence error with AMR reported in #617.

When a MeshBlock contacting a finer MeshBlock is refined, the original code refined normal B-fields on the shared face by interpolating the coarser fields, but they do not exactly match the existing finer fields on the already refined neighbor MeshBlock. With this commit, the shared face fields are copied from the finer MeshBlock, hence enforcing the divergence B constraint.

Prerequisite checklist

  • My code follows the Athena++ Style Guide
  • My change requires a change to the documentation.
  • I have updated the documentation in the Wiki accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@changgoo
Copy link
Contributor

failure from the pgen_compile test:

src/mesh/amr_loadbalance.cpp:1223:47: error: implicit conversion loses integer precision: 'std::vector::size_type' (aka 'unsigned long') to 'const int' [-Werror,-Wshorten-64-to-32]
  const int nf = my_blocks(0)->pmr->pvars_fc_.size();
            ~~   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
1 error generated.

@changgoo
Copy link
Contributor

another error:

src/mesh/amr_loadbalance.cpp: In member function ‘void Mesh::PrepareAndSendFaceFieldCorrection(LogicalLocation*, int*, int*, int*, int)’:
src/mesh/amr_loadbalance.cpp:1296:48: error: suggest parentheses around arithmetic in operand of ‘^’ [-Werror=parentheses]
 1296 |             ffc_send_.emplace_back(i, n, xf2^1 + 2, sffc2, -1);
      |                                              ~~^~~
src/mesh/amr_loadbalance.cpp:1326:48: error: suggest parentheses around arithmetic in operand of ‘^’ [-Werror=parentheses]
 1326 |             ffc_send_.emplace_back(i, n, xf3^1 + 4, sffc3, -1);
      |                                              ~~^~~

@felker
Copy link
Contributor

felker commented Oct 15, 2024

@tomidakn can you check that my latest suggestion is what is intendend? I had to remind myself of the counter-intuitivie operator precedence rules in C re: bitwise operators and arithmetic operators. Interestingly, ChatGPT 4o-mini gets it wrong:
image

It was my mistake and I have to thank the compiler.
@tomidakn
Copy link
Contributor Author

I'm afraid I made the same mistake as Chat-GPT.

@felker
Copy link
Contributor

felker commented Oct 15, 2024

don't worry, I have scolded the AI
image
image

@changgoo
Copy link
Contributor

Wow, I also didn't appreciate the pgen_compile test much and often blame that it is too picky. But, now I see why we have that!

@changgoo
Copy link
Contributor

retest this on stellar

@felker
Copy link
Contributor

felker commented Oct 15, 2024

Wow, I also didn't appreciate the pgen_compile test much and often blame that it is too picky. But, now I see why we have that!

see, I didnt just implement these strict tests just to be annoying! 😂

@@ -78,6 +78,26 @@ struct LogicalLocation { // aggregate and POD type
//! prototype for overloading the comparison operator (defined in meshblock_tree.cpp)
bool operator==(const LogicalLocation &l1, const LogicalLocation &l2);


Copy link
Contributor

Choose a reason for hiding this comment

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

Could you say a bit about why this moved from being a (mostly?) "multigrid-specific" feature?
I see that the LogicalLocationHash and unordered_map's are currently used in Multigrid and meshblock_tree.* Can you say more about the maps / can the same maps be shared across these classes?

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.

3 participants