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

moved long function definitions out of Gmsh class declaration and header file #429

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

meng5113
Copy link

@meng5113 meng5113 commented Oct 5, 2024

The PR is to move long function definitions out of Gmsh class declaration and header file in issue #425.

@yungyuc yungyuc requested a review from j8xixo12 October 5, 2024 12:46
@yungyuc
Copy link
Member

yungyuc commented Oct 5, 2024

@j8xixo12 could you please help take a look too?

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, @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)
Copy link
Member

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.

@yungyuc yungyuc added refactor Change code without changing tests mesh Spatial mesh labels Oct 5, 2024
{
return s == "$MeshFormat";
}
else if (last_fmt_state == FormatState::META_END || last_fmt_state == FormatState::PYHSICAL_NAME_END)
Copy link
Collaborator

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?

Copy link
Collaborator

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)
Copy link
Collaborator

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)
Copy link
Collaborator

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.

Copy link
Collaborator

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 ?

Copy link
Member

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.

Copy link
Member

@yungyuc yungyuc Oct 6, 2024

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"))
Copy link
Collaborator

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});
Copy link
Collaborator

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);
Copy link
Collaborator

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.

@yungyuc yungyuc mentioned this pull request Oct 6, 2024
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mesh Spatial mesh refactor Change code without changing tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants