Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
ogs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Chaofan Chen
ogs
Commits
65f1570c
Commit
65f1570c
authored
6 months ago
by
Norbert Grunwald
Committed by
Dmitri Naumov
6 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Cubic root solver interface class
parent
a4b957f3
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
MathLib/CMakeLists.txt
+1
-0
1 addition, 0 deletions
MathLib/CMakeLists.txt
MathLib/Nonlinear/CubicRoots.h
+81
-0
81 additions, 0 deletions
MathLib/Nonlinear/CubicRoots.h
with
82 additions
and
0 deletions
MathLib/CMakeLists.txt
+
1
−
0
View file @
65f1570c
...
@@ -34,6 +34,7 @@ target_link_libraries(
...
@@ -34,6 +34,7 @@ target_link_libraries(
$<$<BOOL:
${
OGS_USE_CVODE
}
>:CVODE::CVODE>
$<$<BOOL:
${
OGS_USE_CVODE
}
>:CVODE::CVODE>
$<$<BOOL:
${
OGS_USE_PETSC
}
>:PkgConfig::PETSC>
$<$<BOOL:
${
OGS_USE_PETSC
}
>:PkgConfig::PETSC>
Eigen3::Eigen
Eigen3::Eigen
Boost::math
$<$<AND:$<TARGET_EXISTS:OpenMP::OpenMP_CXX>,$<BOOL:$<STREQUAL:
${
OGS_EIGEN_PARALLEL_BACKEND
}
,OpenMP>>>:OpenMP::OpenMP_CXX>
$<$<AND:$<TARGET_EXISTS:OpenMP::OpenMP_CXX>,$<BOOL:$<STREQUAL:
${
OGS_EIGEN_PARALLEL_BACKEND
}
,OpenMP>>>:OpenMP::OpenMP_CXX>
PRIVATE $<$<BOOL:
${
OGS_USE_MKL
}
>:MKL::MKL>
PRIVATE $<$<BOOL:
${
OGS_USE_MKL
}
>:MKL::MKL>
)
)
...
...
This diff is collapsed.
Click to expand it.
MathLib/Nonlinear/CubicRoots.h
0 → 100644
+
81
−
0
View file @
65f1570c
/**
* \file
* \copyright
* Copyright (c) 2012-2024, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*/
#pragma once
#include
<algorithm>
#include
<limits>
#include
<vector>
#include
"BaseLib/Error.h"
#include
"cubic_roots.hpp"
namespace
MathLib
{
class
CubicSolver
{
public:
CubicSolver
(
const
double
a
,
const
double
b
,
const
double
c
,
const
double
d
)
:
a_
(
a
),
b_
(
b
),
c_
(
c
),
d_
(
d
)
{
if
(
std
::
abs
(
a_
)
<
1e-9
)
{
OGS_FATAL
(
"'a' must be non-zero for a cubic equation."
);
}
}
// Method to solve the cubic equation using Boost
std
::
vector
<
double
>
solve
()
{
// Solve using Boost's cubic_roots
auto
roots
=
boost
::
math
::
tools
::
cubic_roots
<
double
>
(
a_
,
b_
,
c_
,
d_
);
// Sort array
std
::
sort
(
roots
.
begin
(),
roots
.
end
());
std
::
vector
<
double
>
roots_vector
;
for
(
const
auto
&
root
:
roots
)
{
if
(
!
std
::
isnan
(
root
))
{
roots_vector
.
push_back
(
root
);
}
}
return
roots_vector
;
}
// Method that returns the smallest positive real root
double
smallestPositiveRealRoot
()
{
auto
roots
=
solve
();
double
min_positive_root
=
std
::
numeric_limits
<
double
>::
infinity
();
// Find the smallest positive real root
for
(
const
auto
&
root
:
roots
)
{
if
(
root
>
0
&&
root
<
min_positive_root
)
{
min_positive_root
=
root
;
}
}
// If no positive root was found, return NaN
if
(
min_positive_root
==
std
::
numeric_limits
<
double
>::
infinity
())
{
return
std
::
numeric_limits
<
double
>::
quiet_NaN
();
}
return
min_positive_root
;
}
private
:
double
a_
,
b_
,
c_
,
d_
;
// Coefficients of the cubic equation
};
}
// namespace MathLib
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment