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
Dmitri Naumov
ogs
Commits
fddf37b8
Commit
fddf37b8
authored
9 years ago
by
Norihiro Watanabe
Browse files
Options
Downloads
Patches
Plain Diff
improved error messages
parent
09936a4f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
MathLib/LinAlg/Eigen/EigenLinearSolver.cpp
+22
-20
22 additions, 20 deletions
MathLib/LinAlg/Eigen/EigenLinearSolver.cpp
with
22 additions
and
20 deletions
MathLib/LinAlg/Eigen/EigenLinearSolver.cpp
+
22
−
20
View file @
fddf37b8
...
...
@@ -24,30 +24,31 @@ using boost::property_tree::ptree;
namespace
details
{
/// Template class for Eigen direct linear solvers
template
<
class
T_SOLVER
>
class
EigenDirectSolver
:
public
EigenLinearSolver
::
IEigenSolver
class
EigenDirect
Linear
Solver
:
public
EigenLinearSolver
::
IEigenSolver
{
public:
EigenDirectSolver
(
EigenMatrix
::
RawMatrixType
&
A
)
:
_A
(
A
)
explicit
EigenDirect
Linear
Solver
(
EigenMatrix
::
RawMatrixType
&
A
)
:
_A
(
A
)
{
// fill A and b;
// Compute the ordering permutation vector from the structural pattern of A
_solver
.
analyzePattern
(
A
);
// Compute the numerical factorization
_solver
.
factorize
(
A
);
INFO
(
"-> initialize with the coefficient matrix"
);
_solver
.
compute
(
A
);
if
(
_solver
.
info
()
!=
Eigen
::
Success
)
{
ERR
(
"
The numerical factorization failed in Eige
n"
);
ERR
(
"
Failed during Eigen linear solver initializatio
n"
);
return
;
}
}
virtual
~
EigenDirectSolver
()
{}
virtual
~
EigenDirect
Linear
Solver
()
{}
void
solve
(
EigenVector
::
RawVectorType
&
b
,
EigenVector
::
RawVectorType
&
x
,
EigenOption
&
)
override
void
solve
(
EigenVector
::
RawVectorType
&
b
,
EigenVector
::
RawVectorType
&
x
,
EigenOption
&
/*opt*/
)
override
{
//Use the factors to solve the linear system
INFO
(
"-> solve"
);
x
=
_solver
.
solve
(
b
);
if
(
_solver
.
info
()
!=
Eigen
::
Success
)
{
ERR
(
"Failed during Eigen linear solve"
);
return
;
}
}
private
:
...
...
@@ -55,21 +56,22 @@ private:
EigenMatrix
::
RawMatrixType
&
_A
;
};
/// Template class for Eigen iterative linear solvers
template
<
class
T_SOLVER
>
class
EigenIterativeSolver
:
public
EigenLinearSolver
::
IEigenSolver
class
EigenIterative
Linear
Solver
:
public
EigenLinearSolver
::
IEigenSolver
{
public:
EigenIterativeSolver
(
EigenMatrix
::
RawMatrixType
&
A
)
:
_A
(
A
)
explicit
EigenIterative
Linear
Solver
(
EigenMatrix
::
RawMatrixType
&
A
)
:
_A
(
A
)
{
INFO
(
"-> initialize with the coefficient matrix"
);
_solver
.
compute
(
A
);
if
(
_solver
.
info
()
!=
Eigen
::
Success
)
{
INFO
(
"
\t
failed
"
);
ERR
(
"Failed during Eigen linear solver initialization
"
);
return
;
}
}
virtual
~
EigenIterativeSolver
()
{}
virtual
~
EigenIterative
Linear
Solver
()
{}
void
solve
(
EigenVector
::
RawVectorType
&
b
,
EigenVector
::
RawVectorType
&
x
,
EigenOption
&
opt
)
override
{
...
...
@@ -78,8 +80,8 @@ public:
_solver
.
setMaxIterations
(
opt
.
max_iterations
);
x
=
_solver
.
solveWithGuess
(
b
,
x
);
if
(
_solver
.
info
()
!=
Eigen
::
Success
)
{
INFO
(
"
\t
solving failed
"
);
return
;
ERR
(
"Failed during Eigen linear solve
"
);
return
;
}
INFO
(
"
\t
iteration: %d/%ld"
,
_solver
.
iterations
(),
opt
.
max_iterations
);
INFO
(
"
\t
residual: %e
\n
"
,
_solver
.
error
());
...
...
@@ -100,13 +102,13 @@ EigenLinearSolver::EigenLinearSolver(EigenMatrix &A, ptree const*const option)
A
.
getRawMatrix
().
makeCompressed
();
if
(
_option
.
solver_type
==
EigenOption
::
SolverType
::
SparseLU
)
{
typedef
Eigen
::
SparseLU
<
EigenMatrix
::
RawMatrixType
,
Eigen
::
COLAMDOrdering
<
int
>
>
SolverType
;
_solver
=
new
details
::
EigenDirectSolver
<
SolverType
>
(
A
.
getRawMatrix
());
_solver
=
new
details
::
EigenDirect
Linear
Solver
<
SolverType
>
(
A
.
getRawMatrix
());
}
else
if
(
_option
.
solver_type
==
EigenOption
::
SolverType
::
BiCGSTAB
)
{
typedef
Eigen
::
BiCGSTAB
<
EigenMatrix
::
RawMatrixType
,
Eigen
::
DiagonalPreconditioner
<
double
>>
SolverType
;
_solver
=
new
details
::
EigenIterativeSolver
<
SolverType
>
(
A
.
getRawMatrix
());
_solver
=
new
details
::
EigenIterative
Linear
Solver
<
SolverType
>
(
A
.
getRawMatrix
());
}
else
if
(
_option
.
solver_type
==
EigenOption
::
SolverType
::
CG
)
{
typedef
Eigen
::
ConjugateGradient
<
EigenMatrix
::
RawMatrixType
,
Eigen
::
Lower
,
Eigen
::
DiagonalPreconditioner
<
double
>>
SolverType
;
_solver
=
new
details
::
EigenIterativeSolver
<
SolverType
>
(
A
.
getRawMatrix
());
_solver
=
new
details
::
EigenIterative
Linear
Solver
<
SolverType
>
(
A
.
getRawMatrix
());
}
}
...
...
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