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

0 indexed meshes(#114) #120

Merged
merged 22 commits into from
Nov 7, 2023
Merged

Conversation

zasexton
Copy link
Contributor

*Arbitrary Mesh Indexing for Problem Initialization *

Current situation & Problem

In response to issue #114. Face mesh data for svFSIplus assumes that GlobalNodeID and GlobalElementID are indexed at 1. This scheme is inconsistent with how VTK tools external to SimVascular construct connectivity data on meshes. The different scheme thus makes it difficult to build models in a scripted fashion either though SimVascular's Python VTK functions or external VTK functions. Further changes were made to avoid hanging that occurred during previous integration testing.

Release Notes

  • arbitrary element type to be correctly initialized by the solver
  • agreement with internal and external mesh generation routines

Documentation

No new functions are added through this pull. Instead changes are introduced to existing functions for importing and handling mesh initialization.

Testing

Further testing will be needed for different element types for VTK_WEDGE. In addition, changes introduced to the code should be checked for clarity and minimal code needed for fast implementation. I've included my thoughts as I wrote these changes in #114.

Code of Conduct & Contributing Guidelines

@zasexton
Copy link
Contributor Author

Okay, trying this again but hopefully with working integration tests this time. @ktbolt and @mrp089 mostly what I want to make sure is that any of these changes are how we would like to address this issue.

Specifically I assume that we conserve the counter-clockwise ordering of nodes within elements of the imported meshes (the same conventions used by VTK) thus the following elements have the following node orders:

  • VTK_HEXAHEDRON
      7-------6
     /|      /|
    / |     / |
   4-------5  |
   |  3----|--2
   | /     | /
   |/      |/
   0-------1

Node Ordering for Faces

  1. Bottom face: 0-3-2-1 (counter-clockwise when viewed from below)
  2. Top face: 4-5-6-7 (counter-clockwise when viewed from above)
  3. Front face: 0-1-5-4 (counter-clockwise when viewed from front)
  4. Back face: 2-3-7-6 (counter-clockwise when viewed from back)
  5. Left face: 3-0-4-7 (counter-clockwise when viewed from left)
  6. Right face: 1-2-6-5 (counter-clockwise when viewed from right)
  • VTK_WEDGE
3-----------5
|\         /|
| \       / |
|  \     /  |
|   \   /   |
|    \ /    |
|     4     |
0-----|-----2
 \    |    /       
  \   |   /
   \  |  /
    \ | /
      1

Node ordering of Faces

  1. Bottom triangular face: 0-1-2 (counter-clockwise when viewed from below)
  2. Top triangular face: 3-4-5 (counter-clockwise when viewed from above)
  3. Back quadrilateral face: 2-0-3-5 (counter-clockwise when viewed from the back)
  4. Left quadrilateral face: 0-1-4-3 (counter-clockwise when viewed from the left)
  5. Right quadrilateral face: 1-2-5-4 (counter-clockwise when viewed from the right)
  • VTK_TETRA
       3
      /|\
     / | \
    /  |  \
   /   |   \
  0----|----2
   \   |   /
    \  |  /
     \ | /
      \|/
       1

Node ordering for Faces

  1. Face 0-1-2 (counter-clockwise when viewed from outside, in this case, from below)
  2. Face 0-1-3 (counter-clockwise when viewed from the left)
  3. Face 1-2-3 (counter-clockwise when viewed from the right)
  4. Face 2-0-3 (counter-clockwise when viewed from the back)
  • VTK_QUAD
3-------2
|       |
|       |
|       |
0-------1

Node ordering of Edges

  1. Bottom edge: 0-1 (counter-clockwise when viewed from the front)
  2. Right edge: 1-2 (counter-clockwise when viewed from the front)
  3. Top edge: 2-3 (counter-clockwise when viewed from the front)
  4. Left edge: 3-0 (counter-clockwise when viewed from the front)
  • VTK_TRIANGLE
      2
     / \
    /   \
   /     \
  0-------1

Node ordering of Edges

  1. Bottom edge: 0-1 (counter-clockwise when viewed from the front)
  2. Right edge: 1-2 (counter-clockwise when viewed from the front)
  3. Left edge: 2-0 (counter-clockwise when viewed from the front)
  • VTK_LINE
0----------1

Node ordering

  1. Start of the line segment: 0
  2. End of the line segment: 1

These ordering schemes for the boundaries are reflected in as a mesh attribute ordering which is a std::vector<std::vector<int>> and mapped to the element type in the vtk_xml_parser.cpp file here:
https://github.com/zasexton/svFSIplus/blob/fd04be0c476969788e54980ece00185a2c8d5ffe/Code/Source/svFSI/vtk_xml_parser.cpp#L43-L67

@ktbolt
Copy link
Collaborator

ktbolt commented Oct 19, 2023

@zasexton svFSIplus will reorder element connectivity to whatever node ordering it needs.

@zasexton
Copy link
Contributor Author

@ktbolt yes and to avoid checking all combinations of nodes for matching (which seemed to cause hanging on the test_niederer_benchmark_ECGs_quadrature I decided to supply this explicit ordering. This is not intended to be used in place of other reordering schemes.

@zasexton zasexton marked this pull request as ready for review October 23, 2023 16:29
for (int i = 0; i<mesh.gnNo; i++){
std::string key = "";
for (int j = 0; j<com_mod.nsd; j++){
key += std::to_string(mesh.x(j,i)) + ",";
Copy link
Collaborator

Choose a reason for hiding this comment

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

std::to_string() only converts to six significant digits. If you want to use strings then you will need to use std::stringstream and std::setprecision().

It would be faster (?) and use less memory but a bit more complicated to map the coordinates into an integer index.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I can include this. Is there a certain precision that we should set by default?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Assuming a precision that will convert a double exactly is the problem with using strings, would need to set it to 16 maybe but then the strings would be 18 bytes, larger using std::scientific.

I think a better solution is to map the coordinates to an integer index into a map of some sort.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've changed the unsorted_map keys for the global nodes to be constructed as strings from 16 precision scientific format of the coordinates using std::scientific and std::set_precision. Maybe we can change this to an integer map later on...

Copy link
Collaborator

Choose a reason for hiding this comment

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

@zasexton Good, we can refine the code later if needed.

@ktbolt
Copy link
Collaborator

ktbolt commented Oct 27, 2023

@zasexton You mixing in code from two different Issues.

@zasexton
Copy link
Contributor Author

Yes I was trying to merge the other way around so I could continue on the perfusion problem (oops). I reverted those changes

@ktbolt
Copy link
Collaborator

ktbolt commented Oct 27, 2023

@zasexton Add a check if the unsorted_map key already exists when mapping the global nodes. This will uncover any problems with the specified precision.

Also encapsulate all of these functions into a class, separating each portion of the computation into its own method.

@zasexton
Copy link
Contributor Author

zasexton commented Nov 3, 2023

encapsulation of functions creating the hash maps for the global node and element IDs have been added the load_msh.cpp file in the load_msh namespace. These have been encapsulated in the MeshHashMaps class.

Copy link
Collaborator

@ktbolt ktbolt left a comment

Choose a reason for hiding this comment

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

Very nice! Be sure to remove commented out code, it is always confusing.

@zasexton
Copy link
Contributor Author

zasexton commented Nov 7, 2023

@ktbolt @mrp089 let me know if there are any other considerations that need to be made for this pull request. Otherwise I think it should be ready for a final review

@ktbolt ktbolt merged commit f55cecc into SimVascular:main Nov 7, 2023
5 checks passed
mrp089 referenced this pull request in mrp089/svFSIplus_old Nov 30, 2023
* adding darcy equation

* darcy equation can be built but generates a trivially zero solution

* commenting files to find mesh indexing error

* correcting gN, gE, and IEN after reading meshes

* removing IEN resetting in vtk_xml.cpp since this functionality is moved into load_msh.cpp

* adding general parameters for unsteady darcy problem

* added final version of the hash map for gN, gE, and IEN setting for face meshes

* adding binary mask permutation for non-tet elements (#114)

* adding boundary node counter-clockwise ordering to element matching (#114)

* completed 2D darcy general model formulation for (#71)

* adding scientific notation and 16 precision to global node matching (#114)

* Revert "Merge branch 'Tissue-perfusion-model-#71' into 0-indexed-meshes(#114)"

This reverts commit 7cbf43a0b21cdb5706b5292f8c5f62cd8b0d4070, reversing
changes made to 7a97ef62e0b7b2e1d380230b081f62e508dce471.

* encapsulating hash map generation (#114)

* remove commented lines performing un-encapsulated hash map generation

* adding error checking for duplicate nodes during hash map generation (#114)

---------

Co-authored-by: Dave Parker <[email protected]>
mrp089 referenced this pull request in mrp089/svFSIplus_old Nov 30, 2023
* adding darcy equation

* darcy equation can be built but generates a trivially zero solution

* commenting files to find mesh indexing error

* correcting gN, gE, and IEN after reading meshes

* removing IEN resetting in vtk_xml.cpp since this functionality is moved into load_msh.cpp

* adding general parameters for unsteady darcy problem

* added final version of the hash map for gN, gE, and IEN setting for face meshes

* adding binary mask permutation for non-tet elements (#114)

* adding boundary node counter-clockwise ordering to element matching (#114)

* completed 2D darcy general model formulation for (#71)

* adding scientific notation and 16 precision to global node matching (#114)

* Revert "Merge branch 'Tissue-perfusion-model-#71' into 0-indexed-meshes(#114)"

This reverts commit 7cbf43a0b21cdb5706b5292f8c5f62cd8b0d4070, reversing
changes made to 7a97ef62e0b7b2e1d380230b081f62e508dce471.

* encapsulating hash map generation (#114)

* remove commented lines performing un-encapsulated hash map generation

* adding error checking for duplicate nodes during hash map generation (#114)

---------

Co-authored-by: Dave Parker <[email protected]>
mrp089 referenced this pull request in mrp089/svFSIplus_old Nov 30, 2023
* adding darcy equation

* darcy equation can be built but generates a trivially zero solution

* commenting files to find mesh indexing error

* correcting gN, gE, and IEN after reading meshes

* removing IEN resetting in vtk_xml.cpp since this functionality is moved into load_msh.cpp

* adding general parameters for unsteady darcy problem

* added final version of the hash map for gN, gE, and IEN setting for face meshes

* adding binary mask permutation for non-tet elements (#114)

* adding boundary node counter-clockwise ordering to element matching (#114)

* completed 2D darcy general model formulation for (#71)

* adding scientific notation and 16 precision to global node matching (#114)

* Revert "Merge branch 'Tissue-perfusion-model-#71' into 0-indexed-meshes(#114)"

This reverts commit 7cbf43a0b21cdb5706b5292f8c5f62cd8b0d4070, reversing
changes made to 7a97ef62e0b7b2e1d380230b081f62e508dce471.

* encapsulating hash map generation (#114)

* remove commented lines performing un-encapsulated hash map generation

* adding error checking for duplicate nodes during hash map generation (#114)

---------

Co-authored-by: Dave Parker <[email protected]>
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.

2 participants