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
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
1328c7a
adding darcy equation
zasexton Sep 25, 2023
813262d
darcy equation can be built but generates a trivially zero solution
zasexton Sep 25, 2023
4e7d748
commenting files to find mesh indexing error
zasexton Oct 5, 2023
e5ff25c
correcting gN, gE, and IEN after reading meshes
zasexton Oct 9, 2023
a737609
Merge branch 'SimVascular:main' into 0-indexed-meshes(#114)
zasexton Oct 9, 2023
2121667
removing IEN resetting in vtk_xml.cpp since this functionality is mov…
zasexton Oct 10, 2023
a9d4d97
Merge remote-tracking branch 'origin/0-indexed-meshes(#114)' into 0-i…
zasexton Oct 10, 2023
8e11b75
adding general parameters for unsteady darcy problem
zasexton Oct 12, 2023
6621f6f
added final version of the hash map for gN, gE, and IEN setting for f…
zasexton Oct 15, 2023
ca53ab3
adding binary mask permutation for non-tet elements (#114)
zasexton Oct 17, 2023
fd04be0
adding boundary node counter-clockwise ordering to element matching (…
zasexton Oct 19, 2023
7b4dd90
Merge branch 'SimVascular:main' into 0-indexed-meshes(#114)
zasexton Oct 25, 2023
0858ce0
completed 2D darcy general model formulation for (#71)
zasexton Oct 27, 2023
7a97ef6
adding scientific notation and 16 precision to global node matching (…
zasexton Oct 27, 2023
7cbf43a
Merge branch 'Tissue-perfusion-model-#71' into 0-indexed-meshes(#114)
zasexton Oct 27, 2023
dbfd582
Revert "Merge branch 'Tissue-perfusion-model-#71' into 0-indexed-mesh…
zasexton Oct 27, 2023
ca9ff01
encapsulating hash map generation (#114)
zasexton Nov 3, 2023
b9b7e94
Merge branch 'SimVascular:main' into 0-indexed-meshes(#114)
zasexton Nov 3, 2023
7ed7fd0
remove commented lines performing un-encapsulated hash map generation
zasexton Nov 3, 2023
3555c55
adding error checking for duplicate nodes during hash map generation …
zasexton Nov 6, 2023
6a26966
Merge remote-tracking branch 'origin/0-indexed-meshes(#114)' into 0-i…
zasexton Nov 6, 2023
1f5733a
Merge branch 'main' into 0-indexed-meshes(#114)
ktbolt Nov 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 75 additions & 4 deletions Code/Source/svFSI/load_msh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
#include <iostream>
#include <fstream>
#include <sstream>
#include <chrono>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <algorithm>


namespace load_msh {

Expand Down Expand Up @@ -109,7 +115,43 @@ void read_sv(Simulation* simulation, mshType& mesh, const MeshParameters* mesh_p
if (com_mod.ichckIEN) {
read_msh_ns::check_ien(simulation, mesh);
}

std::cout << "Hash Map Construction: Nodes " << std::endl;
auto start_time = std::chrono::high_resolution_clock::now();
// Create a hash map for nodes and elements.
std::unordered_map<std::string, int> mesh_node_map;
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.

}
mesh_node_map[key] = i;
}
auto end_time = std::chrono::high_resolution_clock::now();
std::cout << "Time to set node hash map: " << std::chrono::duration_cast<std::chrono::milliseconds>(end_time - start_time).count() << " ms" << std::endl;
std::cout << "Hash Map Construction: Nodes. Done." << std::endl;
std::cout << "Hash Map Construction: Elements " << std::endl;
start_time = std::chrono::high_resolution_clock::now();
// Create a hash map for elements IEN
std::unordered_map<std::string, int> mesh_element_set;
for (int i = 0; i<mesh.gnEl; i++) {
for (int j = 0; j < mesh.eNoN; j++) {
std::vector<int> element_nodes;
for (int k = 0; k < mesh.eNoN; k++) {
if (k != j) {
element_nodes.push_back(mesh.gIEN(k, i));
}
}
std::sort(element_nodes.begin(), element_nodes.end());
std::string key = "";
for (int node: element_nodes) {
key += std::to_string(node) + ",";
}
mesh_element_set[key] = i;
}
}
end_time = std::chrono::high_resolution_clock::now();
std::cout << "Time to set element hash map: " << std::chrono::duration_cast<std::chrono::milliseconds>(end_time - start_time).count() << " ms" << std::endl;
std::cout << "Hash Map Construction: Elements. Done." << std::endl;
// Read face meshes.
//
// Creates nodal coordinates and element connectivity data.
Expand Down Expand Up @@ -154,8 +196,7 @@ void read_sv(Simulation* simulation, mshType& mesh, const MeshParameters* mesh_p
// If node IDs were not read then create them.
if (face.gN.size() == 0) {
read_msh_ns::calc_nbc(mesh, face);

// Reset the connecttivity with the new node IDs?
// Reset the connectivity with the new node IDs?
for (int e = 0; e < face.nEl; e++) {
for (int a = 0; a < face.eNoN; a++) {
int Ac = face.IEN(a,e);
Expand All @@ -165,7 +206,37 @@ void read_sv(Simulation* simulation, mshType& mesh, const MeshParameters* mesh_p
}
}
}

std::cout << "face.nNo: " << face.nNo << std::endl;
start_time = std::chrono::high_resolution_clock::now();
// Set face global node IDs
for (int a = 0; a<face.nNo; a++) {
std::string key = "";
for (int j = 0; j<com_mod.nsd; j++) {
key += std::to_string(face.x(j,a)) + ",";
}
face.gN(a) = mesh_node_map[key];
}
end_time = std::chrono::high_resolution_clock::now();
std::cout << "Time to set face global IDs: " << std::chrono::duration_cast<std::chrono::milliseconds>(end_time - start_time).count() << " ms" << std::endl;
std::cout << "face node set. Done" << std::endl;
// Set face element IDs
for (int e = 0; e < face.nEl; e++) {
std::vector<int> element_nodes;
for (int a = 0; a < face.eNoN; a++) {
int Ac = face.IEN(a,e);
Ac = face.gN(Ac);
face.IEN(a,e) = Ac;
element_nodes.push_back(Ac);
}
std::string key = "";
std::sort(element_nodes.begin(), element_nodes.end());
for (int a = 0; a<face.eNoN; a++) {
key += std::to_string(element_nodes[a]) + ",";
}
face.gE(e) = mesh_element_set[key];
}
end_time = std::chrono::high_resolution_clock::now();
std::cout << "Time to set face global IDs: " << std::chrono::duration_cast<std::chrono::milliseconds>(end_time - start_time).count() << " ms" << std::endl;
nn::select_eleb(simulation, mesh, face);
}

Expand Down
17 changes: 9 additions & 8 deletions Code/Source/svFSI/vtk_xml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,15 +420,16 @@ void read_vtp(const std::string& file_name, faceType& face)

if (face.gN.size() == 0) {
std::cout << "[WARNING] No node IDs found in the '" << file_name << "' face file.";
} else {
for (int e = 0; e < face.nEl; e++) {
for (int a = 0; a < face.eNoN; a++) {
int Ac = face.IEN(a,e);
Ac = face.gN(Ac);
face.IEN(a,e) = Ac;
}
}
}
//else {
// for (int e = 0; e < face.nEl; e++) {
// for (int a = 0; a < face.eNoN; a++) {
//int Ac = face.IEN(a,e);
//Ac = face.gN(Ac);
//face.IEN(a,e) = Ac;
// }
// }
//}

// Create essential BC array.
//
Expand Down