***
Wartungsfenster jeden ersten Mittwoch vormittag im Monat
***
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
COMMICS
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ASC
Praetorius
COMMICS
Commits
e99ecc55
Commit
e99ecc55
authored
6 years ago
by
Carl-Martin Pfeiler
Browse files
Options
Downloads
Patches
Plain Diff
Precond: stationary not as real inverse
parent
5f49e158
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
integrators/_details/interfaces/tpsPreconditioner.py
+64
-31
64 additions, 31 deletions
integrators/_details/interfaces/tpsPreconditioner.py
with
64 additions
and
31 deletions
integrators/_details/interfaces/tpsPreconditioner.py
+
64
−
31
View file @
e99ecc55
...
...
@@ -159,6 +159,7 @@ class TPSPreconditioner(_preconditionerInterface._PreconditionerInterface):
import
scipy.sparse.linalg
import
scipy.sparse
as
sp
import
numpy
as
np
import
pyamg
if
(
self
.
parameters
.
alphaPreconditioner
==
None
):
A
=
self
.
_A_stat
[:
self
.
_A_stat
.
shape
[
0
]
//
3
,
:
self
.
_A_stat
.
shape
[
0
]
//
3
]
...
...
@@ -166,40 +167,72 @@ class TPSPreconditioner(_preconditionerInterface._PreconditionerInterface):
A
=
self
.
_A_stat_precond
[:
self
.
_A_stat_precond
.
shape
[
0
]
//
3
\
,
:
self
.
_A_stat_precond
.
shape
[
0
]
//
3
]
Ainv
=
np
.
zeros
(
A
.
shape
,
dtype
=
float
)
e
=
np
.
zeros
(
A
.
shape
[
0
],
dtype
=
float
)
e
[
0
]
=
1.0
print
(
"
Inverting matrix for stationary preconditioner
"
)
sol
,
succ
=
scipy
.
sparse
.
linalg
.
cg
(
A
,
e
\
,
tol
=
self
.
_solvetol
,
maxiter
=
4000
)
idx
=
(
abs
(
sol
)
>
self
.
_solvetol
)
Ainv
[
idx
,
0
]
=
sol
[
idx
]
for
j
in
range
(
1
,
A
.
shape
[
0
]):
e
[
j
-
1
]
=
0.0
e
[
j
]
=
1.0
sol
,
succ
=
scipy
.
sparse
.
linalg
.
cg
(
A
,
e
,
tol
=
self
.
_solvetol
,
maxiter
=
4000
)
idx
=
(
abs
(
sol
)
>
self
.
_solvetol
)
Ainv
[
idx
,
j
]
=
sol
[
idx
]
if
(
j
%
100
==
0
):
print
(
"
Finished
"
,
j
,
"
out of
"
,
A
.
shape
[
0
]
\
,
"
cols of stationary preconditioner
"
)
N
=
A
.
shape
[
0
]
cooAinv
=
sp
.
coo_matrix
(
Ainv
)
self
.
_preStationary
=
sp
.
csr_matrix
((
\
np
.
append
(
cooAinv
.
data
,
cooAinv
.
data
),
(
\
np
.
append
(
2
*
cooAinv
.
row
,
2
*
cooAinv
.
row
+
1
),
\
np
.
append
(
2
*
cooAinv
.
col
,
2
*
cooAinv
.
col
+
1
)
)))
# trying AMG, SPLU, CG preconditioner, CG as default.
# way faster than true inverse, especially for large NV
opt
=
"
cg
"
# "ml", "splu"
if
opt
==
"
ml
"
:
ml
=
pyamg
.
ruge_stuben_solver
(
A
)
pre
=
ml
.
aspreconditioner
()
self
.
_preStationary
.
eliminate_zeros
()
stationary
=
lambda
x
:
self
.
_preStationary
.
dot
(
x
)
Pre
=
lambda
x
:
np
.
vstack
(
\
(
pre
*
x
[
0
::
2
],
pre
*
x
[
1
::
2
])).
reshape
((
-
1
,),
order
=
'
F
'
)
elif
opt
==
"
splu
"
:
cgs
=
pyamg
.
coarse_grid_solver
(
"
splu
"
)
Pre
=
lambda
x
:
np
.
vstack
(
\
(
cgs
(
A
,
x
[
0
::
2
]),
cgs
(
A
,
x
[
1
::
2
]))).
reshape
((
-
1
,),
order
=
'
F
'
)
elif
opt
==
"
cg
"
:
metaPre
=
1.0
/
A
.
diagonal
()
MetaPre
=
lambda
x
:
metaPre
*
x
P
=
scipy
.
sparse
.
linalg
.
LinearOperator
(
A
.
shape
,
matvec
=
MetaPre
)
Pre
=
lambda
x
:
np
.
vstack
((
scipy
.
sparse
.
linalg
.
cg
(
A
,
x
[
0
::
2
],
tol
=
self
.
_solvetol
/
10
,
M
=
P
)[
0
],
\
scipy
.
sparse
.
linalg
.
cg
(
A
,
x
[
1
::
2
],
tol
=
self
.
_solvetol
/
10
,
M
=
P
)[
0
]))
\
.
reshape
((
-
1
,),
order
=
'
F
'
)
self
.
_preconditioner
=
scipy
.
sparse
.
linalg
.
LinearOperator
(
\
self
.
_preStationary
.
shape
,
matvec
=
stationary
)
(
A
.
shape
[
0
]
*
2
,
A
.
shape
[
0
]
*
2
),
matvec
=
Pre
)
# Ainv = np.zeros(A.shape, dtype=float)
#
# e = np.zeros(A.shape[0], dtype=float)
# e[0] = 1.0
#
# print("Inverting matrix for stationary preconditioner")
# sol, succ = scipy.sparse.linalg.cg(A, e \
# , tol=self._solvetol, maxiter=4000)
# idx = (abs(sol) > self._solvetol)
# Ainv[idx,0] = sol[idx]
# for j in range(1, A.shape[0]):
# e[j-1] = 0.0
# e[j] = 1.0
# sol, succ = scipy.sparse.linalg.cg(A, e, tol=self._solvetol, maxiter=4000)
# idx = (abs(sol) > self._solvetol)
# Ainv[idx, j] = sol[idx]
# if (j % 100 == 0):
# print("Finished ", j, "out of ", A.shape[0] \
# , "cols of stationary preconditioner")
#
# N = A.shape[0]
#
# csrAinv = sp.csr_matrix(Ainv)
## cooAinv = sp.coo_matrix(Ainv)
## self._preStationary = sp.csr_matrix(( \
## np.append(cooAinv.data, cooAinv.data), ( \
## np.append(2*cooAinv.row, 2*cooAinv.row+1), \
## np.append(2*cooAinv.col, 2*cooAinv.col+1) )))
#
## self._preStationary.eliminate_zeros()
#
### stationary = lambda x: np.concatenate(( \
### csrAinv.dot(x[:x.size//2]), csrAinv.dot(x[x.size//2:])))
# # TODO THIS solves the above problem, saves memory also. TODO adapt to solving stuff
# stationary = lambda x: np.vstack((csrAinv.dot(x[0::2]),csrAinv.dot(x[1::2]))).reshape((-1,),order='F')
## stationary = lambda x: self._preStationary.dot(x)
#
# self._preconditioner = scipy.sparse.linalg.LinearOperator( \
# (2*csrAinv.shape[0], 2*csrAinv.shape[1]), matvec=stationary)
## self._preStationary.shape, matvec=stationary)
#------------------------------------------------------------------------------#
...
...
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