Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tnl-dev
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
TNL
tnl-dev
Commits
b9f067c5
There was an error fetching the commit references. Please try again later.
Commit
b9f067c5
authored
6 years ago
by
Tomáš Oberhuber
Browse files
Options
Downloads
Patches
Plain Diff
Linear Jacobi solver refactoring.
parent
f52140d2
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
src/TNL/Solvers/Linear/tnlJacobiSolver.h
+126
-0
126 additions, 0 deletions
src/TNL/Solvers/Linear/tnlJacobiSolver.h
with
126 additions
and
0 deletions
src/TNL/
Problem
s/
l
inear/
stationary/
tnlJacobiSolver.h
→
src/TNL/
Solver
s/
L
inear/tnlJacobiSolver.h
+
126
−
0
View file @
b9f067c5
/***************************************************************************
tnlSORSolver
.h - description
Jacobi
.h - description
-------------------
begin :
2007/07/30
begin :
Jul 30, 2007
copyright : (C) 2007 by Tomas Oberhuber
email : tomas.oberhuber@fjfi.cvut.cz
***************************************************************************/
...
...
@@ -15,47 +15,52 @@
* *
***************************************************************************/
#ifndef tnlJacobiSolverH
#define tnlJacobiSolverH
#pragma once
#include
<math.h>
#include
<
core/tnl
Object.h>
#include
<
s
olvers/
p
reconditioners/
tnl
Dummy
Preconditioner
.h>
#include
<
s
olvers/
tnl
IterativeSolver.h>
#include
<
s
olvers/
l
inear/
tnl
LinearResidueGetter.h>
#include
<
TNL/
Object.h>
#include
<
TNL/S
olvers/
P
reconditioners/Dummy.h>
#include
<
TNL/S
olvers/IterativeSolver.h>
#include
<
TNL/S
olvers/
L
inear/LinearResidueGetter.h>
namespace
TNL
{
namespace
Solvers
{
namespace
Linear
{
template
<
typename
Matrix
,
typename
Preconditioner
=
tnl
DummyPreconditioner
<
typename
Matrix
::
RealType
,
typename
Matrix
::
DeviceType
,
typename
Matrix
::
IndexType
>
>
class
tnl
Jacobi
Solver
:
public
tnl
Object
,
public
tnl
IterativeSolver
<
typename
Matrix
::
RealType
,
typename
Matrix
::
IndexType
>
typename
Preconditioner
=
DummyPreconditioner
<
typename
Matrix
::
RealType
,
typename
Matrix
::
DeviceType
,
typename
Matrix
::
IndexType
>
>
class
Jacobi
:
public
Object
,
public
IterativeSolver
<
typename
Matrix
::
RealType
,
typename
Matrix
::
IndexType
>
{
public:
typedef
typename
Matrix
::
RealType
RealType
;
typedef
typename
Matrix
::
IndexType
IndexType
;
typedef
typename
Matrix
::
DeviceType
DeviceType
;
typedef
typename
Matrix
::
RealType
RealType
;
typedef
typename
Matrix
::
IndexType
IndexType
;
typedef
typename
Matrix
::
DeviceType
DeviceType
;
typedef
Matrix
MatrixType
;
typedef
Preconditioner
PreconditionerType
;
tnl
Jacobi
Solver
()
:
omega
(
0
){}
Jacobi
()
:
omega
(
0
){}
tnl
String
getType
()
const
String
getType
()
const
{
return
tnl
String
(
"
tnl
Jacobi
Solver
< "
)
+
this
->
matrix
->
getType
()
+
", "
+
this
->
preconditioner
->
getType
()
+
" >"
;
return
String
(
"Jacobi< "
)
+
this
->
matrix
->
getType
()
+
", "
+
this
->
preconditioner
->
getType
()
+
" >"
;
}
static
void
configSetup
(
tnlConfigDescription
&
config
,
const
tnlString
&
prefix
=
""
)
{
config
.
addEntry
<
double
>
(
prefix
+
"jacobi-omega"
,
"Relaxation parameter of the weighted/damped Jacobi method."
,
1.0
);}
const
String
&
prefix
=
""
)
{
config
.
addEntry
<
double
>
(
prefix
+
"jacobi-omega"
,
"Relaxation parameter of the weighted/damped Jacobi method."
,
1.0
);
}
bool
setup
(
const
tnl
ParameterContainer
&
parameters
,
const
tnl
String
&
prefix
=
""
)
bool
setup
(
const
Config
::
ParameterContainer
&
parameters
,
const
String
&
prefix
=
""
)
{
tnl
IterativeSolver
<
RealType
,
IndexType
>::
setup
(
parameters
,
prefix
);
IterativeSolver
<
RealType
,
IndexType
>::
setup
(
parameters
,
prefix
);
this
->
setOmega
(
parameters
.
getParameter
<
double
>
(
prefix
+
"jacobi-omega"
)
);
if
(
this
->
omega
<=
0.0
||
this
->
omega
>
2.0
)
{
...
...
@@ -64,49 +69,58 @@ class tnlJacobiSolver : public tnlObject,
return
true
;
}
void
setOmega
(
const
RealType
&
omega
)
{
this
->
omega
=
omega
;}
const
RealType
&
getOmega
()
const
{
return
omega
;}
void
setOmega
(
const
RealType
&
omega
)
{
this
->
omega
=
omega
;
}
const
RealType
&
getOmega
()
const
{
return
omega
;
}
void
setMatrix
(
const
MatrixType
&
matrix
){
this
->
matrix
=
&
matrix
;}
void
setPreconditioner
(
const
Preconditioner
&
preconditioner
){
this
->
preconditioner
=
&
preconditioner
;}
void
setMatrix
(
const
MatrixType
&
matrix
)
{
this
->
matrix
=
&
matrix
;
}
void
setPreconditioner
(
const
Preconditioner
&
preconditioner
)
{
this
->
preconditioner
=
&
preconditioner
;
}
#ifdef HAVE_NOT_CXX11
template
<
typename
Vector
,
typename
ResidueGetter
>
bool
solve
(
const
Vector
&
b
,
Vector
&
x
)
#else
template
<
typename
Vector
,
typename
ResidueGetter
=
tnl
LinearResidueGetter
<
Matrix
,
Vector
>
>
typename
ResidueGetter
=
LinearResidueGetter
<
Matrix
,
Vector
>
>
bool
solve
(
const
Vector
&
b
,
Vector
&
x
,
Vector
&
aux
)
#endif
{
const
IndexType
size
=
matrix
->
getRows
();
this
->
resetIterations
();
this
->
setResidue
(
this
->
getConvergenceResidue
()
+
1.0
);
RealType
bNorm
=
b
.
lpNorm
(
(
RealType
)
2.0
);
aux
=
x
;
while
(
this
->
nextIteration
()
)
{
for
(
IndexType
row
=
0
;
row
<
size
;
row
++
)
matrix
->
performJacobiIteration
(
b
,
row
,
x
,
aux
,
this
->
getOmega
()
);
for
(
IndexType
row
=
0
;
row
<
size
;
row
++
)
matrix
->
performJacobiIteration
(
b
,
row
,
aux
,
x
,
this
->
getOmega
()
);
const
IndexType
size
=
matrix
->
getRows
();
this
->
resetIterations
();
this
->
setResidue
(
this
->
getConvergenceResidue
()
+
1.0
);
RealType
bNorm
=
b
.
lpNorm
(
(
RealType
)
2.0
);
aux
=
x
;
while
(
this
->
nextIteration
()
)
{
for
(
IndexType
row
=
0
;
row
<
size
;
row
++
)
matrix
->
performJacobiIteration
(
b
,
row
,
x
,
aux
,
this
->
getOmega
()
);
for
(
IndexType
row
=
0
;
row
<
size
;
row
++
)
matrix
->
performJacobiIteration
(
b
,
row
,
aux
,
x
,
this
->
getOmega
()
);
this
->
setResidue
(
ResidueGetter
::
getResidue
(
*
matrix
,
x
,
b
,
bNorm
)
);
}
this
->
setResidue
(
ResidueGetter
::
getResidue
(
*
matrix
,
x
,
b
,
bNorm
)
);
}
this
->
setResidue
(
ResidueGetter
::
getResidue
(
*
matrix
,
x
,
b
,
bNorm
)
);
this
->
refreshSolverMonitor
();
return
this
->
checkConvergence
();
this
->
refreshSolverMonitor
();
return
this
->
checkConvergence
();
}
protected
:
RealType
omega
;
const
MatrixType
*
matrix
;
const
PreconditionerType
*
preconditioner
;
RealType
omega
;
const
MatrixType
*
matrix
;
const
PreconditionerType
*
preconditioner
;
};
#endif
}
// namespace Linear
}
// namespace Solvers
}
// namespace TNL
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