-
Notifications
You must be signed in to change notification settings - Fork 45
Add Ferrari-Cardano algorithm and general Quartic Solver test suite #2010
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
Open
osanstrong
wants to merge
73
commits into
celeritas-project:develop
Choose a base branch
from
osanstrong:ferrari
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 47 commits
Commits
Show all changes
73 commits
Select commit
Hold shift + click to select a range
6c7d2ec
Started exploring what a test file would look like
osanstrong f3bf765
Merge branch 'celeritas-project:develop' into ferrari
osanstrong b6c3db4
Enumerated certain test cases for ferrari solver
osanstrong 77c9964
Refined set of test case decsriptions, should be ready to actually de…
osanstrong db6f40b
Added harness class to FerrariSolver test, to hopefully streamline pr…
osanstrong feba8db
started adding tests using harness
osanstrong 5776732
Added test cases for quartic solver and dominant cubic solver
osanstrong 4b93605
Added Ferrari Solver
osanstrong 483794c
Added ferrari test file to celeritas test lists
osanstrong 261f9aa
Started fixing bugs in ferrari solver
osanstrong 4f5ebeb
Added missing semicolon, comma
osanstrong f89b787
fixed syntax issues, added temporary debugging statements
osanstrong 4affdce
fixed two flipped signs on test polynomials, and one which worked but…
osanstrong 7a5f923
Added separate quadratic solver to also provide negative real roots, …
osanstrong a82f53d
Removed hacky print statements for debugging
osanstrong 49504b1
corrected typo saying 'two solutions' to a quartic instead of four
osanstrong fa5d229
Generalized quartic solver harness and made ferrari solver test harne…
osanstrong 7213cf8
Renamed FerrariSolver to QuarticSolver
osanstrong bbdf205
Merge branch 'celeritas-project:develop' into ferrari
osanstrong 94c6673
Merge branch 'ferrari' of github.com:osanstrong/celeritas into ferrari
osanstrong 9b56efe
Added precommit file format checks
osanstrong 01cae24
Removed unused field for e/a
osanstrong bdcff63
Removed accidentally created/misnamed bcmake config file
osanstrong d567eb7
Switched special case equality/zero checks to use SoftZero instead of…
osanstrong 7fba091
Removed redundant zero-e operator definition
osanstrong 63918fd
Added citation for Algorithm 1010
osanstrong 4079736
Renamed Roots2 alias to Real2 for consistency with other project files
osanstrong a7fbc4c
Moved logic for special biquadratic case to helper function
osanstrong d17c83b
Adjusted formatting of equations in documentation
osanstrong 7540c6b
Removed unnecessary TODO statements
osanstrong 2420744
Replaced self-square notation with ipow<2>
osanstrong 0acf806
Replaced method to add in sorted list iwth method to add, and subsequ…
osanstrong f7bf2fa
Started adding typed testing to replace individually declared tests i…
osanstrong 9f42f7e
Changed quartic unit tests to a templated test framework to use TYPED…
osanstrong 1a4b6a2
Replaced cubic helper function tests with quartic tests which ensure …
osanstrong 52e241c
Privatized helper functions in FerrariSolver
osanstrong dc23441
Added real_type wrappers to avoid potential double casting issues for…
osanstrong 7b3b886
Cleaned up definition docstrings
osanstrong 08f6a8e
Replaced manual lists of no_intersection() with lists of valid inters…
osanstrong 9232367
Removed unused qb squared variable
osanstrong 90f4eb6
Replaced x**n with x^n for readability
osanstrong 0302df9
Updated docstrings for consistency
osanstrong 21bc819
Fix manual placement indexing to work as described
osanstrong 5cfa4e3
Added citation to Ferrari-Cardano method from mathematical handbook
osanstrong 21edada
Removed odd spacing from equations
osanstrong 624e2db
Refactored FerrariSolver to be constructed with tolerance and take ab…
osanstrong 5c6dbdf
Renamed vague 'TestTypes' to specifically 'QuarticSolver' for clarity…
osanstrong 6dd516f
Shifted certain unit tests which were moreso testing precision, chang…
osanstrong 68d750a
Changed ferrari solver to use Numeric Recipes cubic solver to match A…
osanstrong 0e54a60
Refactored FerrariSolver to use operator with option to specify surfa…
osanstrong a97c130
Refactored QuarticSolver test for clarity
osanstrong 181397e
Made internal functions and tolerance member functions/data for each …
osanstrong 957773e
Fix typo of description of surface three root test
osanstrong 12c8c53
Fixed soft zero to be definitively constructed as member data
osanstrong 00fa4d8
Removed unwise tolerance for cases near tangential intersections in s…
osanstrong de5dc0f
Nudged certain unit tests away from edges, where they were more actin…
osanstrong 8ceafa7
Refactored if possible, or removed if not, surface unit tests which t…
osanstrong 860902b
Removed Cardano from name of Ferrari solver, as it does not exclusive…
osanstrong 21f6f86
Moved surface solution implementation to surface solution operator, a…
osanstrong dd90f38
Added expectation that a is not zero, as cubic special case makes e z…
osanstrong a7fe938
Removed sorting from FerrariSolver, added sorter to quartic tests for…
osanstrong cd455cc
Removed surface state argument in general solver case; expectation wi…
osanstrong 1c5498f
Removed unused iostream include
osanstrong 46d079b
Renamed UTIL section to HELPER FUNCTIONS
osanstrong dbef116
Removed separator between ININE DEFINITIONS section and the first fun…
osanstrong bc1272d
Moved separator bar to after TYPED_TEST_SUITE call
osanstrong c538234
Merge branch 'celeritas-project:develop' into ferrari
osanstrong e487c26
Merge remote-tracking branch 'upstream/develop' into ferrari
sethrj be90c5c
Remove orange specific code
sethrj 4dd5fe3
Move quartic solver to corecel/math
sethrj 535aa29
Add doc
sethrj 3164480
Fix docs
sethrj 58bf4c5
Revert "Fix docs"
sethrj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,347 @@ | ||||||||||
| //------------------------------- -*- C++ -*- -------------------------------// | ||||||||||
| // Copyright Celeritas contributors: see top-level COPYRIGHT file for details | ||||||||||
| // SPDX-License-Identifier: (Apache-2.0 OR MIT) | ||||||||||
| //---------------------------------------------------------------------------// | ||||||||||
| //! \file orange/surf/detail/FerrariSolver.hh | ||||||||||
| //---------------------------------------------------------------------------// | ||||||||||
| #pragma once | ||||||||||
|
|
||||||||||
| #include <cmath> | ||||||||||
| #include <iostream> | ||||||||||
|
|
||||||||||
| #include "corecel/Types.hh" | ||||||||||
| #include "corecel/cont/Array.hh" | ||||||||||
| #include "corecel/math/Algorithms.hh" | ||||||||||
| #include "corecel/math/PolyEvaluator.hh" | ||||||||||
| #include "corecel/math/SoftEqual.hh" | ||||||||||
| #include "orange/OrangeTypes.hh" | ||||||||||
| #include "orange/surf/detail/QuadraticSolver.hh" | ||||||||||
|
|
||||||||||
| namespace celeritas | ||||||||||
| { | ||||||||||
| namespace detail | ||||||||||
| { | ||||||||||
| //---------------------------------------------------------------------------// | ||||||||||
| /*! | ||||||||||
| * Find positive, real, non-zero roots for quartic functions using the | ||||||||||
| * Ferrari-Cardano method\citet{polyanin-ferrari-2007, | ||||||||||
osanstrong marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||
| * https://doi.org/10.1201/9781420010510}. | ||||||||||
| * | ||||||||||
| * The quartic equation | ||||||||||
| * \f[ | ||||||||||
| a x^4 + b x^3 + c x^2 + d x + e = 0 | ||||||||||
| * \f] | ||||||||||
| * has four solutions mathematically, but we only require solutions which are | ||||||||||
| * both real and positive. This equation is also subject to multiple cases of | ||||||||||
| * catastrophic precision-limitation-based error both fundamentally and as a | ||||||||||
| * consequence of the particular algorithm chosen. This solver implements the | ||||||||||
| * Ferrari-Cardano method, which is well-established and simple, but more | ||||||||||
| * prone to numerical error than contemporary methods to be explored such as | ||||||||||
| * Algorithm 1010\citet{orellana-alg1010-2020, | ||||||||||
| * https://doi.org/10.1145/3386241}. | ||||||||||
| * | ||||||||||
| * \return An Intersections array where each item is either a positive valid | ||||||||||
sethrj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||
| * intersection or the sentinel result \c no_intersection(). | ||||||||||
| */ | ||||||||||
| class FerrariSolver | ||||||||||
| { | ||||||||||
| public: | ||||||||||
| //!@{ | ||||||||||
| //! \name Type aliases | ||||||||||
| using Intersections = Array<real_type, 4>; | ||||||||||
| using Real2 = Array<real_type, 2>; | ||||||||||
| using Real5 = Array<real_type, 5>; | ||||||||||
| //!@} | ||||||||||
|
|
||||||||||
| // Solve with manually specified surface state | ||||||||||
| static inline CELER_FUNCTION Intersections solve_general( | ||||||||||
| Real5 abcde, | ||||||||||
| SurfaceState on_surface, | ||||||||||
| real_type tolerance = Tolerance<real_type>::sqrt_quadratic()); | ||||||||||
osanstrong marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||
|
|
||||||||||
| public: | ||||||||||
| // Construct w/ given tolerance. Uses quadratic tolerance by default. | ||||||||||
| inline CELER_FUNCTION | ||||||||||
| FerrariSolver(real_type tolerance = Tolerance<real_type>::sqrt_quadratic()); | ||||||||||
|
|
||||||||||
| // Solver for fully general case | ||||||||||
| inline CELER_FUNCTION Intersections operator()(Real5 abcde) const; | ||||||||||
|
|
||||||||||
| private: | ||||||||||
| //// DATA //// | ||||||||||
| // Soft zero for biquadratic and degenerate cubic detection | ||||||||||
| static inline SoftZero<real_type> const soft_zero_; | ||||||||||
|
||||||||||
| static inline SoftZero<real_type> const soft_zero_; | |
| SoftZero<real_type> const soft_zero_; |
osanstrong marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
osanstrong marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
osanstrong marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
osanstrong marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
osanstrong marked this conversation as resolved.
Show resolved
Hide resolved
osanstrong marked this conversation as resolved.
Show resolved
Hide resolved
osanstrong marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
osanstrong marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
Member
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.
To construct as member data:
Suggested change
| SoftZero soft_zero_{tolerance}; | |
| FerrariSolver::FerrariSolver(real_type tolerance) | |
| : soft_zero_{tolerance} | |
| { |
osanstrong marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
osanstrong marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
sethrj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
sethrj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
osanstrong marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
osanstrong marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
sethrj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
sethrj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.