Skip to content

Resolve unreachable code in cut kernel - #2121

Open
georghammerl wants to merge 2 commits into
4C-multiphysics:mainfrom
georghammerl:cut_kernel_flaw
Open

Resolve unreachable code in cut kernel#2121
georghammerl wants to merge 2 commits into
4C-multiphysics:mainfrom
georghammerl:cut_kernel_flaw

Conversation

@georghammerl

@georghammerl georghammerl commented Jul 9, 2026

Copy link
Copy Markdown
Member

Description and Context

The Intel compiler pointed me to this line in the cut kernel code

if (det < 1.0e-16 && det > 1.0e-16)

which evaluates always to false.

I am no expert of this piece of code. Please review my proposed solution.
The failing tests reveal that the proposed changes lead to different behavior. Tests with negative determinant seem to have passed in the past?!

Alternative: Delete the lines of code as they have never been reached in the past.

@maxfirmbach maxfirmbach left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@georghammerl I think the changes make a lot of sense. I would propose to go forward and fix the failing tests.

Comment thread src/cut/4C_cut_kernel.hpp Outdated
}

if (det < 1.0e-16 && det > 1.0e-16)
if (det < -1.0e-16)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we use a numerical limit here?

Comment thread src/cut/4C_cut_kernel.hpp
msg << "Determinant in compute position is negative: " << det;
FOUR_C_THROW("{}", msg.str());
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same applies here.

Comment thread src/cut/4C_cut_kernel.hpp
{
std::stringstream msg;
msg << "Determinant in compute position is negative: " << det;
FOUR_C_THROW("{}", msg.str());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

FOUR_C_THROW can format strings directly

Suggested change
FOUR_C_THROW("{}", msg.str());
FOUR_C_THROW("Determinant in compute position is negative: {}", det);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes and no.
A std::formatter<T> specialization is neccessary for every {} argument type. Since FloatType is a template parameter that can be instantiated with things like double, Sacado::Fad::DFad<double>, or Core::CLN::ClnWrapper, there is no generic formatter for it. To circumvent adding those at the moment, the workaround with the operator<< which is available for all template types.

@vryy

vryy commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

@georghammerl should we merge this soon? because I have the same problem in #1795

@georghammerl

Copy link
Copy Markdown
Member Author

I would like to merge, however the tests behave different and I have no clue on those details that matter in the cut code :-/

@vryy vryy mentioned this pull request Aug 5, 2026
@vryy

vryy commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Hi @georghammerl, I made the fix in #2161 and seems this check does not affect the test. I would suggest to merge #2161 and rebase this PR based on this for further adjustment. The only fix in #2161 is needed to continue with #1795.

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.

4 participants