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

Mesh reader support for VTK high order elements [feature/vtk_high_order] #975

Merged
merged 32 commits into from Jan 24, 2021

Conversation

jonesholger
Copy link
Contributor

@jonesholger jonesholger commented Jun 24, 2019

Updated PR information (Dec. 2020 – Will)

This PR adds two new features to MFEM's VTK support:

  1. Reading XML VTK mesh files in addition to the "legacy" ASCII format
  2. Reading high-order VTK meshes. High-order support works for both XML and legacy VTK formats.

XML parsing is done using the TinyXML2 library.

To facilitate systematic conversion between VTK's high-order node ordering and MFEM's node ordering, mappings are created that use an intermediate lexicographic ordering. Some remarks about the lexicographic ordering:

  • All NodalFiniteElement subclasses now support GetLexicographicOrdering, which plays the same role as TensorBasisElement::GetDofMap, but with support for all non-tensor geometries
  • The "refined geometry vertices" for tetrahedral elements are now lexicographically ordered in the standard reference element rather than in an "auxiliary element"
  • As a consequence, the lexicographic DOF ordering given by GetLexicographicOrdering always agrees with the refined geometry vertex ordering.
  • These orderings are tested for all geometries, for orders 1 through 6 in the unit tests.
  • The VTK mesh reader supports arbitrary-order Lagrange elements. The node orderings are handled using the same mappings defined for high-order ParaView output, so pre-generated data tables are not required.

As part of this PR, the handling of the VTK format for input and output are both made more systematic. The files vtk.hpp and vtk.cpp now have a lot more features that should make dealing with VTK more convenient, for instance converting from a VTK element type to MFEM Geometry::Type can now be performed using VTKGeometry:: GetMFEMGeometry instead of manual switch statements. This simplifies the code in Mesh::PrintVTK and Mesh::PrintVTU.

For testing purposes, VTK meshes of Cartesian grids with low-order and high-order elements of all types can be created in ParaView with the source "Unstructured Cell Types".

Previous information (out of date)

This mesh reader update subtask for vtk is related to MFEM issue #678 & https://blog.kitware.com/modeling-arbitrary-order-lagrange-finite-elements-in-the-visualization-toolkit/

Quads to arbitrary order vtk ascii
Hexes to arbitrary order vtk ascii
Triangles to order 6 (vtk limit) vtk ascii
Tets to order 6 (vtk limit) vtk ascii
Wedge (or prism) to order 6 (vtk limit) vtk ascii
Create static maps based on Reference Elements up to order 6 for tri/tet/wedge
Mixed cell validation -- assuming all elements are the newer Lagrange High Order Elements

Samples have been uploaded to https://github.com/mfem/data/tree/master/vtk; more will be added later

PR Author Editor Reviewers Assignment Approval Merge
#975 @jonesholger @tzanio @acfisher + @bslazarov + @mlstowell 11/30/20 01/09/21 01/24/21

@jonesholger
Copy link
Contributor Author

jonesholger commented Jun 24, 2019

Consolidating a few related links here:
GLVis/glvis#64
https://blog.kitware.com/modeling-arbitrary-order-lagrange-finite-elements-in-the-visualization-toolkit/
https://glvis.org/curvilinear-vtk-meshes/
https://github.com/CEED/FMS
https://vtk.org/wp-content/uploads/2015/04/file-formats.pdf
https://lorensen.github.io/VTKExamples/site/VTKFileFormats/
https://www.visitusers.org/index.php?title=ASCII_VTK_Files
https://github.com/lorensen/VTKExamples
https://vtk.org/doc/nightly/html/vtkCellType_8h_source.html
https://github.com/agrayver/VTK_Lagrange
https://github.com/Kitware/VTK/blob/265ca48a79a36538c95622c237da11133608bbe5/Common/DataModel/vtkLagrangeQuadrilateral.cxx#L558
https://github.com/Kitware/VTK/blob/265ca48a79a36538c95622c237da11133608bbe5/Common/DataModel/vtkLagrangeHexahedron.cxx#L734
https://github.com/Kitware/VTK/blob/675adbc0feeb3f62730ecacb2af87917af124543/Filters/Sources/vtkCellTypeSource.cxx#L1307
https://github.com/Kitware/VTK/blob/675adbc0feeb3f62730ecacb2af87917af124543/Filters/Sources/vtkCellTypeSource.cxx#L345
https://github.com/Kitware/VTK/blob/5efd279913b4842bed0c1a0f2f119db89134e378/Common/DataModel/vtkCellType.h#L107-L114
https://github.com/Kitware/VTK/blob/675adbc0feeb3f62730ecacb2af87917af124543/Filters/Sources/vtkCellTypeSource.cxx#L1463
https://www.paraview.org/Wiki/ParaView_Release_Notes#Arbitrary-order_Lagrange_finite_element_support
https://github.com/Kitware/VTK/blob/675adbc0feeb3f62730ecacb2af87917af124543/Common/DataModel/vtkLagrangeInterpolation.cxx#L208

mfem/fem/fe.cpp

Lines 6878 to 6917 in 3e9a86c

case 2:
{
const int p1 = p + 1;
dof_map.SetSize(p1*p1);
// vertices
dof_map[0 + 0*p1] = 0;
dof_map[p + 0*p1] = 1;
dof_map[p + p*p1] = 2;
dof_map[0 + p*p1] = 3;
// edges
int o = 4;
for (int i = 1; i < p; i++)
{
dof_map[i + 0*p1] = o++;
}
for (int i = 1; i < p; i++)
{
dof_map[p + i*p1] = o++;
}
for (int i = 1; i < p; i++)
{
dof_map[(p-i) + p*p1] = o++;
}
for (int i = 1; i < p; i++)
{
dof_map[0 + (p-i)*p1] = o++;
}
// interior
for (int j = 1; j < p; j++)
{
for (int i = 1; i < p; i++)
{
dof_map[i + j*p1] = o++;
}
}
break;
}

https://gitlab.kitware.com/vtk/vtk/blob/master/Common/DataModel/vtkUnstructuredGrid.h#L339
dealii/dealii@b029f83
dealii/dealii@e65f906
https://kitware.github.io/paraview-docs/latest/python/paraview.simple.UnstructuredCellTypes.html

mesh/mesh_readers.cpp Outdated Show resolved Hide resolved
mesh/mesh_readers.cpp Outdated Show resolved Hide resolved
@acfisher acfisher requested a review from tzanio July 3, 2019 17:20
@tzanio tzanio added this to the mfem-4.1 milestone Aug 26, 2019
@tzanio tzanio changed the title Mesh reader support for vtk high order elements Mesh reader support for VTK high order elements [feature/vtk_high_order] Aug 30, 2019
@tzanio tzanio modified the milestones: mfem-4.1, mfem-4.2 Feb 27, 2020
@stale
Copy link

stale bot commented Oct 8, 2020

⚠️ This issue or PR has been automatically marked as stale because it has not had any activity in the last month. If no activity occurs in the next week, it will be automatically closed. Thank you for your contributions.

@stale stale bot added the stale label Oct 8, 2020
@pazner
Copy link
Member

pazner commented Oct 9, 2020

We just discussed this feature this week. We should revive this PR.

@stale stale bot removed the stale label Oct 9, 2020
@tzanio tzanio modified the milestones: mfem-4.2, mfem-4.3 Oct 17, 2020
@stale
Copy link

stale bot commented Nov 16, 2020

⚠️ This issue or PR has been automatically marked as stale because it has not had any activity in the last month. If no activity occurs in the next week, it will be automatically closed. Thank you for your contributions.

@stale stale bot added the stale label Nov 16, 2020
@camierjs camierjs added todo the mfem team will address this in the near future WIP Work in Progress and removed stale labels Nov 16, 2020
@pazner
Copy link
Member

pazner commented Dec 14, 2020

To help the reviewers, I edited the top-level comment with an updated summary of this PR — the information there was previously quite out of date.

@tzanio
Copy link
Member

tzanio commented Dec 21, 2020

@acfisher, @bslazarov and @mlstowell -- can you please review?

VerifyOrdering(el);
}

TEST_CASE("Lexicographic Ordering", "[FiniteElement,Geometry]")
Copy link
Member

Choose a reason for hiding this comment

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

This is a good test to have around!

@@ -8525,61 +8539,85 @@ H1_TetrahedronElement::H1_TetrahedronElement(const int p, const int btype)
Vector shape_x(p + 1), shape_y(p + 1), shape_z(p + 1), shape_l(p + 1);
#endif

auto tri = [](int k) { return (k*(k + 1))/2; };
Copy link
Member

Choose a reason for hiding this comment

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

Good use for lambdas.

@@ -731,6 +732,15 @@ class NodalFiniteElement : public ScalarFiniteElement
virtual void ProjectDiv(const FiniteElement &fe,
ElementTransformation &Trans,
DenseMatrix &div) const;

/** @brief Get an Array<int> that maps lexicographically ordered indices to
Copy link
Member

Choose a reason for hiding this comment

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

I think we should define exactly what is meant by "lexicographically ordered". Without knowing the lexicon and the rules we use to order it this array may not be useful.

Copy link
Member

Choose a reason for hiding this comment

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

How does the updated comment look to you?

Copy link
Member

Choose a reason for hiding this comment

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

Looks perfect. Thanks!

@tzanio
Copy link
Member

tzanio commented Jan 4, 2021

Extending approval due date to the end of this week...

@@ -731,6 +732,15 @@ class NodalFiniteElement : public ScalarFiniteElement
virtual void ProjectDiv(const FiniteElement &fe,
ElementTransformation &Trans,
DenseMatrix &div) const;

/** @brief Get an Array<int> that maps lexicographically ordered indices to
Copy link
Member

Choose a reason for hiding this comment

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

Looks perfect. Thanks!

@tzanio
Copy link
Member

tzanio commented Jan 10, 2021

ping: @bslazarov

@tzanio
Copy link
Member

tzanio commented Jan 10, 2021

Can you please update CHANGELOG

@tzanio
Copy link
Member

tzanio commented Jan 10, 2021

Merged in next for testing...

@tzanio tzanio added the in-next label Jan 10, 2021
@tzanio
Copy link
Member

tzanio commented Jan 11, 2021

Re-merged in next for testing ...

@tzanio
Copy link
Member

tzanio commented Jan 13, 2021

Re-merged in next for testing ...

Copy link
Member

@tzanio tzanio left a comment

Choose a reason for hiding this comment

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

@jonesholger and @pazner -- thank you so much for this important contributions. I am sure many of our users will appreciate it!

@mlstowell, @acfisher and @bslazarov -- thank you for reviewing!

@tzanio tzanio merged commit 7ae181b into master Jan 24, 2021
Pull Requests automation moved this from Review Now to Merged Jan 24, 2021
@tzanio tzanio deleted the feature/vtk_high_order branch January 24, 2021 20:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Pull Requests
  
Merged
Development

Successfully merging this pull request may close these issues.

None yet

7 participants