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

add Gmsh mesh file parser #233

Merged
merged 5 commits into from
Jul 30, 2023
Merged

add Gmsh mesh file parser #233

merged 5 commits into from
Jul 30, 2023

Conversation

j8xixo12
Copy link
Collaborator

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.

@@ -83,6 +83,25 @@ def help_other(set_command=False):
view.mgr.pycon.command = cmd.strip()


def help_mesh_viewer(path, set_command=False):
Copy link
Collaborator Author

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.

@j8xixo12 j8xixo12 force-pushed the gmsh_support branch 2 times, most recently from 82b1843 to a4610de Compare July 22, 2023 06:57
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.
@yungyuc
Copy link
Member

yungyuc commented Jul 22, 2023

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.

Copy link
Member

@yungyuc yungyuc left a 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',
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 class and should be put before constants, ordered in the same convention as other classes or functions.

@@ -0,0 +1,23 @@

Copy link
Member

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.

Copy link
Collaborator Author

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

Copy link
Member

Choose a reason for hiding this comment

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

Thanks


namespace modmesh
{
namespace IO
Copy link
Member

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.

Copy link
Collaborator Author

@j8xixo12 j8xixo12 Jul 26, 2023

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.

{
namespace IO
{
namespace Gmsh
Copy link
Member

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.

Copy link
Collaborator Author

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

{
namespace Gmsh
{
struct ElementDef
Copy link
Member

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?

Copy link
Collaborator Author

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

inline ElementDef ElementDef::by_id(uint16_t id)
{
#define VEC(...) __VA_ARGS__
#define MM_DECL_SWITCH_ELEMENT_TYPE(ID, NDIM, NNDS, MMTPN, MMCL) \
Copy link
Member

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.

explicit Gmsh(const std::string & file_path)
{
bool meta_enter = false, node_enter = false, element_enter = false;
// clang-format off
Copy link
Member

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!!

};

// Check the finite state machine state transition is valid or not to check msh file format is correct
bool _isValidTransition(const std::string s)
Copy link
Member

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.

Copy link
Collaborator Author

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.

using real_type = typename number_base::real_type;

public:
explicit Gmsh(const std::string & file_path)
Copy link
Member

@yungyuc yungyuc Jul 22, 2023

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.

Copy link
Collaborator Author

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.

@@ -0,0 +1,350 @@
#include <modmesh/io/io.hpp>
Copy link
Member

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.

Copy link
Collaborator Author

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.
Copy link
Member

@yungyuc yungyuc left a 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.

};

// Check the finite state machine state transition is valid or not to check msh file format is correct
bool isValidTransition(const std::string s)
Copy link
Member

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?

Copy link
Collaborator Author

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

Copy link
Member

@yungyuc yungyuc left a 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);
Copy link
Member

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++.

@yungyuc yungyuc merged commit ecbffcc into solvcon:master Jul 30, 2023
11 checks passed
@yungyuc
Copy link
Member

yungyuc commented Jul 30, 2023

Thanks a lot!

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