-
Notifications
You must be signed in to change notification settings - Fork 95
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
Move invert3x3
out of general purpose utils.hxx
header
#3018
base: next
Are you sure you want to change the base?
Conversation
Only used in `Coordinates`, so make private implementation detail
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 negative small value is only used in tests.
As this is private, we can remove this usage.
Then the checks on the caller can be removed, making the code cleaner. Unfortunately I cannot suggest this, so I can push a commit if you agree, @ZedThree
tests/unit/mesh/test_invert3x3.cxx
Outdated
|
||
// Non-default small | ||
input = 0.; | ||
input(0, 0) = 1.0e-12; | ||
input(1, 1) = 1.0; | ||
input(2, 2) = 1.0; | ||
EXPECT_NO_THROW(invert3x3(input, -1.0e-10)); |
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.
// Non-default small | |
input = 0.; | |
input(0, 0) = 1.0e-12; | |
input(1, 1) = 1.0; | |
input(2, 2) = 1.0; | |
EXPECT_NO_THROW(invert3x3(input, -1.0e-10)); |
src/mesh/invert3x3.hxx
Outdated
/// If small is less than zero then instead of throwing we return false. | ||
/// This is ugly but can be used to support some use cases. |
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 small is less than zero then instead of throwing we return false. | |
/// This is ugly but can be used to support some use cases. |
src/mesh/invert3x3.hxx
Outdated
if (small >= 0) { | ||
throw BoutException("Determinant of matrix < {:e} --> Poorly conditioned", small); | ||
} | ||
return false; |
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 (small >= 0) { | |
throw BoutException("Determinant of matrix < {:e} --> Poorly conditioned", small); | |
} | |
return false; | |
throw BoutException("Determinant of metric component {:e} < {:e} --> Poorly conditioned", std::abs(det), small); |
src/mesh/invert3x3.hxx
Outdated
/// If small is less than zero then instead of throwing we return false. | ||
/// This is ugly but can be used to support some use cases. | ||
template <typename T> | ||
bool invert3x3(Matrix<T>& a, T small = 1.0e-15) { |
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.
bool invert3x3(Matrix<T>& a, T small = 1.0e-15) { | |
void invert3x3(Matrix<T>& a, T small = 1.0e-15) { |
src/mesh/invert3x3.hxx
Outdated
|
||
return true; |
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.
return true; |
Yes, I was tempted to do the same thing, although I realised the error message in So maybe we just remove the |
Right now the error is thrown from We can throw a more specific error, as it is only used to invert the metric tensor. |
Yes, exactly |
Introduce a new |
Allows throwing more specific error in coordinates
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.
Looks good, thanks @ZedThree
"\tERROR: metric tensor is singular at ({:d}, {:d}), determinant: {:d}\n", | ||
i.x(), i.y(), det.value()); |
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 could be 3D compatible:
"\tERROR: metric tensor is singular at ({:d}, {:d}), determinant: {:d}\n", | |
i.x(), i.y(), det.value()); | |
"\tERROR: metric tensor is singular at {}, determinant: {:d}\n", | |
i, det.value()); |
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.
Nice, good catch, thanks!
"\tERROR: metric tensor is singular at ({:d}, {:d}), determinant: {:d}\n", | ||
i.x(), i.y(), det.value()); |
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:
"\tERROR: metric tensor is singular at ({:d}, {:d}), determinant: {:d}\n", | |
i.x(), i.y(), det.value()); | |
"\tERROR: metric tensor is singular at {}, determinant: {:d}\n", | |
i, det.value()); |
throw BoutException("Determinant of matrix < {:e} --> Poorly conditioned", small); | ||
} | ||
return false; | ||
return std::optional<BoutReal>{det}; |
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.
Is the explicit constructor really needed? Could this not be:
return std::optional<BoutReal>{det}; | |
return det; |
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.
Not sure, will check
Only used in
Coordinates
, so make private implementation detailAlso return
bool
instead ofint