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

crash displaying vector fields with vdim != mesh dims and vdim > 1 #326

Closed
helloworld922 opened this issue Mar 2, 2025 · 4 comments
Closed
Assignees

Comments

@helloworld922
Copy link

Reproducer:

#include <mfem.hpp>

int main(int argc, char **argv) {
  using namespace mfem;
  int order = 2;
  // glvis will segfault for vdims != mesh_dims and vdims > 1
  int vdims = 3;
  int mesh_dims = 2;
  Mesh mesh;
  switch (mesh_dims) {
  case 1:
    mesh = Mesh::MakeCartesian1D(1);
    break;
  case 2:
    mesh =
        Mesh::MakeCartesian2D(1, 1, Element::Type::QUADRILATERAL, false, 1, 1);
    break;
  case 3:
    mesh = Mesh::MakeCartesian3D(1, 1, 1, Element::Type::HEXAHEDRON, 1, 1, 1);
    break;
  }

  L2_FECollection l2_coll(order, mesh_dims);
  FiniteElementSpace vec_space(&mesh, &l2_coll, vdims);
  Array<int> offset(2);
  offset[0] = 0;
  offset[1] = offset[0] + vec_space.GetVSize();
  BlockVector data(offset, Device::GetMemoryType());
  GridFunction vec_gf;
  vec_gf.MakeRef(&vec_space, data, offset[0]);

  socketstream sout;
  char vishost[] = "localhost";
  int visport = 19916;
  sout.open(vishost, visport);
  if (!sout) {
    std::cout << "Unable to connect to GLVis server at " << vishost << ':'
              << visport << std::endl;
    std::cout << "GLVis visualization disabled.\n";
    return -1;
  }
  sout.precision(8);
  sout << "solution\n" << mesh << vec_gf;
  sout << std::flush;
}

This causes glvis to crash (segfault?)

@najlkin najlkin added the bug label Mar 3, 2025
@najlkin najlkin self-assigned this Mar 3, 2025
@najlkin
Copy link
Contributor

najlkin commented Mar 3, 2025

Checking the code, it is not supported now as the space dimension is used to determine what visualization scene object is constructed. However, maybe we could treat it as 2D surface and use the 3D scene object for it 🤔 .

@najlkin
Copy link
Contributor

najlkin commented Mar 4, 2025

Not that easy, it causes crashes at many places in the 3D scene object as it assumes it has space dimension 3. It would be a lot of work to go through all methods and check for compatibility with 2D meshes.
Another option is to extrude the mesh to 3D, but there might be attributes, boundaries and so on, so it is not that easy as with 1D meshes, which are extruded to 2D for visualization.
So I do not know, I would suggest just splitting to 2D vdim=2 and 2D scalar components for now.

@najlkin
Copy link
Contributor

najlkin commented Mar 4, 2025

Ok, I have a solution based on mfem/mfem#4691 with extrusion of the mesh to 3D.

@najlkin
Copy link
Contributor

najlkin commented Mar 4, 2025

Closing in favor of #327 .

@najlkin najlkin closed this as completed Mar 4, 2025
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

2 participants