-
Notifications
You must be signed in to change notification settings - Fork 43
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
add Gmsh mesh file parser #233
Conversation
@@ -83,6 +83,25 @@ def help_other(set_command=False): | |||
view.mgr.pycon.command = cmd.strip() | |||
|
|||
|
|||
def help_mesh_viewer(path, set_command=False): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also added a sample command in sample_mesh app for, once mesh viewer app is completed, then this sample command can be removed.
82b1843
to
a4610de
Compare
In this commit added mesh file io for modmesh, it lets modmesh has capabilty to read third-party mesh generator generated file and convert the content to a data structure that allow modmesh can use it to do some calculation. Currently mesh io only support Gmsh format.
This PR contains almost 1000 lines of diff and will not be easy to review. Would it be possible to break it into smaller pieces? For review efficiency a batch of review should be around 300 lines of diff. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the great work. Let's polish the code.
modmesh/core.py
Outdated
@@ -64,6 +64,7 @@ | |||
'METAL_BUILT', | |||
'metal_running', | |||
'HAS_VIEW', | |||
'Gmsh', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a class and should be put before constants, ordered in the same convention as other classes or functions.
cpp/modmesh/io/CMakeLists.txt
Outdated
@@ -0,0 +1,23 @@ | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
io
the name conflict with Python io
module. It is unnecessary ambiguity. Please rename this directory as inout
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I renamed the module name to inout
in 7432534
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
cpp/modmesh/io/gmsh.hpp
Outdated
|
||
namespace modmesh | ||
{ | ||
namespace IO |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
namespace should not use uppercase, and it should not have the unnecessary ambiguity to the Python module named io
.
In addition, IO
is a pretty short name and may conflict with symbols in foreign code base.
Please rename it to inout
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I renamed the namespace to inout
in 7432534 too.
cpp/modmesh/io/gmsh.hpp
Outdated
{ | ||
namespace IO | ||
{ | ||
namespace Gmsh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do not use uppercase in namespace. Beside, I don't think it is necessary to have 3 levels of namespace. Gmsh is just one of the format. Please remove the namespace.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have removed namespace Gmsh
in 7432534
cpp/modmesh/io/gmsh.hpp
Outdated
{ | ||
namespace Gmsh | ||
{ | ||
struct ElementDef |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about naming it like GmshElementDef
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I renamed ElementDef
to GmshElementDef
in 7432534
cpp/modmesh/io/gmsh.hpp
Outdated
inline ElementDef ElementDef::by_id(uint16_t id) | ||
{ | ||
#define VEC(...) __VA_ARGS__ | ||
#define MM_DECL_SWITCH_ELEMENT_TYPE(ID, NDIM, NNDS, MMTPN, MMCL) \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use of macro makes the code easy to read. Thanks.
cpp/modmesh/io/gmsh.hpp
Outdated
explicit Gmsh(const std::string & file_path) | ||
{ | ||
bool meta_enter = false, node_enter = false, element_enter = false; | ||
// clang-format off |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to turn clang-format back on!!
cpp/modmesh/io/gmsh.hpp
Outdated
}; | ||
|
||
// Check the finite state machine state transition is valid or not to check msh file format is correct | ||
bool _isValidTransition(const std::string s) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not prepend _
to any C++ symbols. You already made them private and mixing the C++ access with Python private convention is a bad idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have removed _
from these private member function.
cpp/modmesh/io/gmsh.hpp
Outdated
using real_type = typename number_base::real_type; | ||
|
||
public: | ||
explicit Gmsh(const std::string & file_path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you make it also take a string as data, in addition to a string as path? Both are useful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I change it to use string as data and python can take care of file stream to bytes
, even if user is using Gmsh
in cpp, cpp also can take care of file stream to string.
gtests/test_nopython_io.cpp
Outdated
@@ -0,0 +1,350 @@ | |||
#include <modmesh/io/io.hpp> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Too long to review. I trust you have made comprehensive testing. If not, please speak up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have tested each cell type conversion between gmsh
and modmesh
. Additionally, I also tested if a user inputs a cell type that is not listed in GmshElementDef
. The expected behavior is that GmshElement::by_id
should return an empty GmshElementDef
object.
In this commit, I made the following additions and modifications: 1. Renamed cpp/modmesh/io to cpp/modmesh/inout to prevent unnecessary ambiguity. 2. Renamed the namespace IO to inout and removed the Gmsh namespace. 3. Renamed the struct ElementDef to GmshElementDef. 4. Moved non-template functions from gmsh.hpp to gmsh.cpp. 5. The Gmsh constructor now takes a string input as data, and the python wrapper also takes py::bytes as input, therefore file IO is now taken care of by python.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's quite close to completion. Only some minor formatting issues remain.
cpp/modmesh/inout/gmsh.hpp
Outdated
}; | ||
|
||
// Check the finite state machine state transition is valid or not to check msh file format is correct | ||
bool isValidTransition(const std::string s) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I forgot to remind that C++ function names should follow snake_case. You used snake_case in other functions. This looks like an overlook. Could you change it and review all in your PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed this in f7de14f
I changed isValidTransition
and toblock
to snake case in Gmsh
class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yet a minor mismatch. Should be a simple fix 🙂
[](const py::bytes & data) | ||
{ return std::make_shared<inout::Gmsh>(data); }), | ||
py::arg("data")) | ||
.def("toblock", &wrapped_type::to_block); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it's still an overlook here. It makes sense to align the function names between Python and C++.
Thanks a lot! |
In this commit added mesh file io for modmesh, it lets modmesh has capabilty to read third-party mesh generator generated file and convert the content to a data structure that allow modmesh can use it to do some calculation.
Currently mesh io only support Gmsh format.