-
Notifications
You must be signed in to change notification settings - Fork 44
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
moved long function definitions out of Gmsh class declaration and header file #429
base: master
Are you sure you want to change the base?
Conversation
@j8xixo12 could you please help take a look too? |
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, @meng5113 . Please follow the directives of the linter to fix the issues: https://github.com/solvcon/modmesh/actions/runs/11191984882/job/31118518269?pr=429#step:11:389 . You can turn on Github Actions in your forked repository to get the same results.
@@ -94,6 +94,159 @@ void Gmsh::build_interior(const std::shared_ptr<StaticMesh> & blk) | |||
blk->build_boundary(); | |||
blk->build_ghost(); | |||
} | |||
|
|||
// Check the finite state machine state transition is valid or not to check msh file format is correct | |||
bool Gmsh::is_valid_transition(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.
Could you please help change the argument to be a const reference? It's a simple change but needs to be applied in both the declaration (in header file) and the definition (here).
To be specific, it is to change
bool Gmsh::is_valid_transition(const std::string s)
with
bool Gmsh::is_valid_transition(const std::string & s)
That is, change the argument of the function from const std::string s
to const std::string & s
.
The change will speed up the code by saving unnecessary string copying.
{ | ||
return s == "$MeshFormat"; | ||
} | ||
else if (last_fmt_state == FormatState::META_END || last_fmt_state == FormatState::PYHSICAL_NAME_END) |
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 looks odd to me that you use "or" here. Why not split them into two else if
?
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 my bad, I have checked the gmsh manual section 10.3.1.
According to the manual, after MeshFormat
, which is the META_END
state, it can either be followed by $PhysicalNames
or $Nodes
. That is why the function returns an "or" expression. However the problem is that after physical name section, it only can be followed by Node
. Therefore this code should be changed to
...
else if (last_fmt_state == FormatState::META_END)
{
return s == "$PhysicalNames" || s == "$Nodes";
}
else if (last_fmt_state == FormatState::PYHSICAL_NAME_END)
{
return s == "$Nodes";
}
...
Thanks @tigercosmos to point out this problem.
I think we can use another PR to fix this problem, it should add some test case to make sure this logic is correct!
I will file an issue to track this.
return false; | ||
} | ||
|
||
void Gmsh::load_meta(void) |
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.
Gmsh::load_meta()
?
msh_ver = std::stod(tokens[0]); | ||
|
||
// The parse only support ver 2.2 msh file. | ||
if (msh_ver != 2.2) |
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 will choose to use constexpr
for the number.
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.
Why not just use a macro ?
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.
Macro does not allow compilers to check type. When macros and constexpr both work, choose constexpr.
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.
For version number, integer should be used. Floating could be inexact and should be avoided.
m_nds(std::stoul(tokens[0]) - 1, 2) = std::stod(tokens[3]); | ||
} | ||
|
||
if (!line.compare("$EndNodes")) |
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 think you should maintain a table to keep these token strings.
} | ||
usnds.insert(usnds.end(), nds_temp.begin() + 1, nds_temp.end()); | ||
nds_temp[0] = mmcl.size(); | ||
m_elems.insert(std::pair{idx, nds_temp}); |
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 think emplace
will be better?
} | ||
|
||
bool is_valid_transition(const std::string s); | ||
void load_meta(void); |
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.
No need to have void
in the argument.
The PR is to move long function definitions out of Gmsh class declaration and header file in issue #425.