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

Shaper mini app, not copying attributes to new mesh #318

Open
JonLangdon opened this issue Oct 13, 2024 · 4 comments
Open

Shaper mini app, not copying attributes to new mesh #318

JonLangdon opened this issue Oct 13, 2024 · 4 comments
Assignees

Comments

@JonLangdon
Copy link

Hi developers,

I am using the shaper mini app to fit a mesh to an object with 2 materials. Unfortunately, the attribute numbers for the materials do not appear in the output file where it shows all the elements are set to attribute 1. I believe the intended behavior is for the element attributes to equal the return value of the "material" function: int material(Vector &x, Vector &xmin, Vector &xmax). In the example, this returns a value of 1 or 2.

Debugging, I noticed that the values were correctly set when checking mesh->GetElement(i).attribute. So, the error appears to be in the "Printer" function used to save the mesh. It turns out that the output of shaper is a "non-conforming mesh". Therefore, the mesh is saved using the NCMesh type. It appears that the element attributes are not being copied to the elements in mesh to those in NCMesh. I added the following code to my copy of mesh.cpp within the Mesh::Printer after the if(Nonconforming) statement:

for (int i = 0; i < this->GetNE(); i++)
{
ncmesh->elements[i].attribute = this->elements[i]->GetAttribute();
}

This results in an output file with the attributes written into the elements. I don't know enough about your software to be sure this will produce the intended result (properly labelling the materials in the mesh), but at least, two material types do appear in the output file now.

@tzanio
Copy link
Member

tzanio commented Oct 15, 2024

Thanks for reporting this @JonLangdon, I can confirm it and I think it is really an issue with our output of AMR meshes in MFEM.

@hughcars and @dylan-copeland -- do you know why the attributes are lost when the NCMesh is saved here, are we missing something?

@dylan-copeland
Copy link

This looks like a bug to me. It is hard to believe this would go undetected for so long, but my guess is that this does happen in normal usage of NCMesh. In shaper, the attributes are set at the end, right before printing. Normally, attributes are set in a Mesh, which is then converted to NCMesh and adaptively refined with correct inheritance of attributes. If it is just this case of setting attributes in Mesh that is not supported, it should be an easy fix. I will work on an MFEM PR for this.

@dylan-copeland
Copy link

@JonLangdon can you please let us know if branch ncmesh-attr works for you? This sets the element attributes in NCMesh. Since this is an MFEM bug, not glvis, you should only need to rebuild MFEM, not glvis.
mfem/mfem#4539

@JonLangdon
Copy link
Author

@dylan-copeland Confirmed. The bug is resolved on the ncmesh-attr branch. Thank you!

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

No branches or pull requests

3 participants