Move invert3x3 out of general purpose utils.hxx header#3018
Conversation
Only used in `Coordinates`, so make private implementation detail
dschwoerer
left a comment
There was a problem hiding this comment.
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.
| // 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.
| /// 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.
| 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.
| 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.
| 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
dschwoerer
left a comment
There was a problem hiding this comment.
Looks good, thanks @ZedThree
This works for 2D and 3D fields (and is also shorter code)
Only used in
Coordinates, so make private implementation detailAlso return
boolinstead ofint