-
Notifications
You must be signed in to change notification settings - Fork 247
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
[GeoMechanicsApplication] Format custom constitutive folder using clang format #12130
[GeoMechanicsApplication] Format custom constitutive folder using clang format #12130
Conversation
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.
@rfaasse
Thank you for the nice work on clang formatting.
The format of the code is improved a lot by clang.
I have few preferences in formatting the code. I commented some. However, it is matter of convention, agreement and discussion, which style to be prefered.
rConstitutiveMatrix(0, 0) = | ||
YieldStress / ((1.0 - DamageThreshold) * CriticalDisplacement) * | ||
((1.0 - mStateVariable) / mStateVariable - | ||
StrainVector[0] * StrainVector[0] / | ||
(CriticalDisplacement * CriticalDisplacement * mStateVariable * mStateVariable * mStateVariable)); | ||
rConstitutiveMatrix(1, 1) = | ||
YieldStress / ((1.0 - DamageThreshold) * CriticalDisplacement) * | ||
((1.0 - mStateVariable) / mStateVariable - | ||
StrainVector[1] * StrainVector[1] / | ||
(CriticalDisplacement * CriticalDisplacement * mStateVariable * mStateVariable * mStateVariable)); | ||
|
||
rConstitutiveMatrix(0, 1) = -YieldStress * StrainVector[0] * StrainVector[1] / | ||
((1.0 - DamageThreshold) * CriticalDisplacement * CriticalDisplacement * | ||
CriticalDisplacement * mStateVariable * mStateVariable * mStateVariable); | ||
rConstitutiveMatrix(1, 0) = rConstitutiveMatrix(0, 1); |
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.
In line 77 and 78: "YieldStress ...." is in the second line
Line 88: "-YieldStress ..." at the same line of "rConstitutiveMatrix(0, 1) ="
There is then inconsistency in formatting
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.
clang-format works with penalties, so it could always be a bit inconsistent, because it depends on the situation and there are always trade-offs (penalties can be conflicting, e.g. breaking a line has a certain penalty and going over the character limit has another penalty). However, now we don't have a penalty for breaking after assignment. Let's discuss in the team if we'd like to add it. When adding a (high) penalty for this, most cases will continue on the same line after an assignment.
rConstitutiveMatrix(0, 0) = | ||
YieldStress / ((1.0 - DamageThreshold) * CriticalDisplacement) * | ||
((1.0 - mStateVariable) / mStateVariable - | ||
StrainVector[0] * StrainVector[0] / | ||
(CriticalDisplacement * CriticalDisplacement * mStateVariable * mStateVariable * mStateVariable)); | ||
rConstitutiveMatrix(1, 1) = YoungModulus / (DamageThreshold * CriticalDisplacement); |
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.
Same as previous comment. Inconsistency in format
rConstitutiveMatrix(0, 1) = | ||
-YieldStress * StrainVector[0] * StrainVector[1] / | ||
((1.0 - DamageThreshold) * CriticalDisplacement * CriticalDisplacement * | ||
CriticalDisplacement * mStateVariable * mStateVariable * mStateVariable) - | ||
std::copysign(1.0, StrainVector[0]) * YoungModulus * FrictionCoefficient / | ||
(DamageThreshold * CriticalDisplacement); |
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.
Prefer to start them from the same column.
for example: line 118 starts from 4 spaces after line 117, but line 117 hasn't priority/hirarchy above line 118.
line 120, std:: hasn't extra priority on line 119
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 reason of the indent here, is because line 118 and 119 belong together, if that's not there it's hard to see where the parenthesis ends.
rConstitutiveMatrix(0, 0) = YieldStress / (CriticalDisplacement * mStateVariable) * | ||
(1.0 - mStateVariable) / (1.0 - DamageThreshold); |
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.
In my opinion, it is a good format, and the rest need to follow this formatting
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.
Yes and when the lines are not too long/complicated, this is what it will do. When it gets more complicated we'd need to introduce a penalty (see previous comment) for breaking a line after assignment
rStressVector[indexStress2DInterface::INDEX_2D_INTERFACE_ZZ] = | ||
YoungModulus / (DamageThreshold * CriticalDisplacement) * | ||
StrainVector[indexStress2DInterface::INDEX_2D_INTERFACE_ZZ]; |
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.
Prefer to have line 200 at the same line of 119, to keep consistency with the format of other parts
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.
If we make PenaltyBreakAssignment
high enough, this will be enforced (at cost of longer lines)
KRATOS_INFO("Error in loadUMATWindows") | ||
<< "cannot load function umat in the specified UMAT: " << rMaterialProperties[UDSM_NAME] | ||
<< std::endl; |
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.
Same as previous
} | ||
} else { | ||
for (unsigned int i = 0; i < VOIGT_SIZE_3D; i++) { | ||
for (unsigned int j = 0; j < VOIGT_SIZE_3D; j++) { |
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.
}
else {
...
}
{ | ||
if (rThisVariable == NUMBER_OF_UMAT_STATE_VARIABLES) rValue = static_cast<int>(mStateVariablesFinalized.size()); |
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.
if (rThisVariable == NUMBER_OF_UMAT_STATE_VARIABLES) {
rValue = static_cast(mStateVariablesFinalized.size());
}
if (rThisVariable == NUMBER_OF_UMAT_STATE_VARIABLES) | ||
rValue = static_cast<int>(mStateVariablesFinalized.size()); |
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.
use { }
} else if ((rThisVariable == CAUCHY_STRESS_VECTOR) && (rValue.size() == mStressVectorFinalized.size())) { | ||
std::copy(rValue.begin(), rValue.end(), mStressVectorFinalized.begin()); |
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.
}
else if ...
…stom-constitutive-using-clang-format
…stom-constitutive-using-clang-format
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.
Thank you for the thorough review and extensive comments @mnabideltares! I agree there are still improvement points and inconsistencies, which as discussed in the stand-up, I would like to take up point for point when all code is formatted:
- We should discuss in the team if the majority prefers else on the same or next line with respect to the closing '}' of the if-statement
- We can experiment and discuss about higher penalties on breaking after assignment operators (i.e. force a line to continue after '='.
- We can experiment and discuss the breaking after '<<', which in combination with the KRATOS_ERROR is not always consistent now.
- We can discuss how we want to handle indentation when breaking a line (remove it or keep it).
If you agree, I'd propose to tackle these 4 issues separately and merge this PR if there are no other blockers from your perspective.
if (Options.Is(ConstitutiveLaw::COMPUTE_CONSTITUTIVE_TENSOR)) { | ||
// COMPUTE_CONSTITUTIVE_TENSOR | ||
Matrix& rConstitutiveMatrix = rValues.GetConstitutiveMatrix(); | ||
|
||
if (EquivalentStrain >= mStateVariable) //Loading | ||
if (EquivalentStrain >= mStateVariable) // Loading | ||
{ | ||
this->ComputeConstitutiveMatrixLoading(rConstitutiveMatrix, | ||
rStrainVector, |
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 agree, the issue here though is the // Loading
comment. Because of the comment, clang-format cannot move the "{" to the same line. I would propose to keep it like this for the re-formatting (to not have a too large scope for this PR), but whenever we work on code that has these kinds of comments next to if-statements, we (re)move them
if (EquivalentStrain >= mStateVariable) // Loading | ||
{ | ||
this->ComputeConstitutiveMatrixContactLoading(rConstitutiveMatrix, |
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.
Same answer as previous, it's because of the comment
} else // Unloading | ||
{ | ||
this->ComputeConstitutiveMatrixContactUnloading(rConstitutiveMatrix, |
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.
We can discuss this in the team if we want to do the 'else' always on a new line. The "{ " on the same line is again an issue with the // Unloading
comment
rConstitutiveMatrix(0, 0) = | ||
YieldStress / ((1.0 - DamageThreshold) * CriticalDisplacement) * | ||
((1.0 - mStateVariable) / mStateVariable - | ||
StrainVector[0] * StrainVector[0] / | ||
(CriticalDisplacement * CriticalDisplacement * mStateVariable * mStateVariable * mStateVariable)); | ||
rConstitutiveMatrix(1, 1) = | ||
YieldStress / ((1.0 - DamageThreshold) * CriticalDisplacement) * | ||
((1.0 - mStateVariable) / mStateVariable - | ||
StrainVector[1] * StrainVector[1] / | ||
(CriticalDisplacement * CriticalDisplacement * mStateVariable * mStateVariable * mStateVariable)); | ||
|
||
rConstitutiveMatrix(0, 1) = -YieldStress * StrainVector[0] * StrainVector[1] / | ||
((1.0 - DamageThreshold) * CriticalDisplacement * CriticalDisplacement * | ||
CriticalDisplacement * mStateVariable * mStateVariable * mStateVariable); | ||
rConstitutiveMatrix(1, 0) = rConstitutiveMatrix(0, 1); |
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.
clang-format works with penalties, so it could always be a bit inconsistent, because it depends on the situation and there are always trade-offs (penalties can be conflicting, e.g. breaking a line has a certain penalty and going over the character limit has another penalty). However, now we don't have a penalty for breaking after assignment. Let's discuss in the team if we'd like to add it. When adding a (high) penalty for this, most cases will continue on the same line after an assignment.
rConstitutiveMatrix(0, 1) = | ||
-YieldStress * StrainVector[0] * StrainVector[1] / | ||
((1.0 - DamageThreshold) * CriticalDisplacement * CriticalDisplacement * | ||
CriticalDisplacement * mStateVariable * mStateVariable * mStateVariable) - | ||
std::copysign(1.0, StrainVector[0]) * YoungModulus * FrictionCoefficient / | ||
(DamageThreshold * CriticalDisplacement); |
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 reason of the indent here, is because line 118 and 119 belong together, if that's not there it's hard to see where the parenthesis ends.
if (rValue.size() != VoigtSize) rValue.resize(VoigtSize); | ||
|
||
rValue[INDEX_2D_INTERFACE_ZZ] = mStressVectorFinalized[INDEX_3D_ZZ]; | ||
rValue[INDEX_2D_INTERFACE_XZ] = mStressVectorFinalized[INDEX_3D_XZ]; |
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.
clang-format does not add {}
, so if we would like this we should do it ourselves. In the same way clang-format won't delete one blank line automatically (only if there are > 1, it will bring it back to 1 in our settings), there is still freedom to add these when needed.
I would propose to do these changes when we work in the code and encounter it (to limit the scope of this PR)
} else if ((rThisVariable == CAUCHY_STRESS_VECTOR) && (rValue.size() == VoigtSize)) { | ||
this->SetInternalStressVector(rValue); | ||
} |
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.
Let's discuss else
/else if
on a new line. I personally like to have it on the same to compact the code a bit, but let's see what the rest feels.
for (unsigned int i = 0; i < VOIGT_SIZE_3D; ++i) | ||
for (unsigned int j = 0; j < VOIGT_SIZE_3D; ++j) | ||
mMatrixD[i][j] = rOther.mMatrixD[i][j]; | ||
for (unsigned int i = 0; i < VOIGT_SIZE_3D; ++i) | ||
for (unsigned int j = 0; j < VOIGT_SIZE_3D; ++j) | ||
mMatrixD[i][j] = rOther.mMatrixD[i][j]; |
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.
Agreed, but as said before, clang-format won't add these automatically
int iAbort = 0; | ||
auto nSizeProjectDirectory = static_cast<int>(mProjectDirectory.size()); |
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.
They are for aligning the assignments and variables
if (!rMaterialProperties.Has(CRITICAL_DISPLACEMENT) || rMaterialProperties[CRITICAL_DISPLACEMENT] <= 0.0) | ||
KRATOS_ERROR << "CRITICAL_DISPLACEMENT has Key zero, is not defined or has an invalid " | ||
"value for property: " | ||
<< rMaterialProperties.Id() << std::endl; | ||
|
||
if (!rMaterialProperties.Has(YOUNG_MODULUS) || rMaterialProperties[YOUNG_MODULUS] <= 0.00) | ||
KRATOS_ERROR | ||
<< "YOUNG_MODULUS has Key zero, is not defined or has an invalid value for property" | ||
<< rMaterialProperties.Id() << std::endl; |
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 the KRATOS_ERROR <<, Wijtze Pieter and I tried several settings to make it as readable as possible when formatting the elements. We landed on the current settings due to other inconsistencies that arise when putting a higher or lower penalty on breaking after the first <<. I'd propose to keep it like it is for now and after we did all the formatting, experiment a bit more, keeping in mind the entire geomechanics code base.
@mnabideltares I tried to answer all your (unique) questions in the comments, please check if you agree! |
No description provided.