Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
fluidparticles
MigFlow
Commits
0127284b
Commit
0127284b
authored
Oct 11, 2021
by
Jonathan Lambrechts
Browse files
missing files
parent
6aced34c
Pipeline
#9831
failed with stages
in 7 minutes
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
python/csr.py
0 → 100644
View file @
0127284b
import
numpy
as
np
class
CSR
:
def
__init__
(
self
,
idx
,
rhsidx
,
constraints
):
pairs
=
np
.
ndarray
([
idx
.
shape
[
0
],
idx
.
shape
[
1
],
idx
.
shape
[
1
]],
dtype
=
([(
'i0'
,
np
.
int32
),(
'i1'
,
np
.
int32
)]))
pairs
[
'i0'
][:,:,:]
=
idx
[:,:,
None
]
pairs
[
'i1'
][:,:,:]
=
idx
[:,
None
,:]
pairs
=
pairs
.
reshape
([
-
1
])
allpairs
=
[
pairs
.
reshape
([
-
1
])]
num
=
np
.
max
(
idx
)
self
.
ndof
=
num
+
1
self
.
constraints
=
constraints
for
c
in
constraints
:
num
+=
1
pairs
=
np
.
ndarray
([
c
.
size
*
2
+
1
],
dtype
=
([(
'i0'
,
np
.
int32
),(
'i1'
,
np
.
int32
)]))
pairs
[
'i0'
][:
c
.
size
]
=
c
pairs
[
'i1'
][:
c
.
size
]
=
num
pairs
[
'i0'
][
c
.
size
:
c
.
size
*
2
]
=
num
pairs
[
'i1'
][
c
.
size
:
c
.
size
*
2
]
=
c
pairs
[
'i0'
][
c
.
size
*
2
]
=
num
pairs
[
'i1'
][
c
.
size
*
2
]
=
num
allpairs
.
append
(
pairs
)
pairs
=
np
.
concatenate
(
allpairs
)
pairs
,
pmap
=
np
.
unique
(
pairs
,
return_inverse
=
True
)
self
.
map
=
[]
count
=
0
for
p
in
allpairs
:
self
.
map
.
append
(
pmap
[
count
:
count
+
p
.
size
])
count
+=
p
.
size
self
.
row
=
np
.
hstack
([
np
.
array
([
0
],
dtype
=
np
.
int32
),
np
.
cumsum
(
np
.
bincount
(
pairs
[
"i0"
]),
dtype
=
np
.
int32
)])
self
.
col
=
pairs
[
'i1'
].
copy
()
self
.
size
=
self
.
row
.
size
-
1
self
.
rhsidx
=
rhsidx
def
assemble_rhs
(
self
,
localv
,
u
,
constraints_value
)
:
rhs
=
np
.
bincount
(
self
.
rhsidx
,
localv
,
self
.
size
)
for
i
,
(
c
,
cv
)
in
enumerate
(
zip
(
self
.
constraints
,
constraints_value
)):
rhs
[
i
+
self
.
ndof
]
=
cv
[
1
]
+
np
.
sum
(
u
[
c
]
*
cv
[
0
])
return
rhs
def
assemble_mat
(
self
,
localm
,
constraints_value
,
v
)
:
v
[:]
=
np
.
bincount
(
self
.
map
[
0
],
localm
,
self
.
col
.
size
)
for
cmap
,
cv
in
zip
(
self
.
map
[
1
:],
constraints_value
)
:
v
+=
np
.
bincount
(
cmap
,
np
.
concatenate
((
cv
[
0
],
cv
[
0
],[
0
])),
self
.
col
.
size
)
Jonathan Lambrechts
@jlambrechts
mentioned in commit
0659028d
·
Oct 12, 2021
mentioned in commit
0659028d
mentioned in commit 0659028de0deee8acf9a0a55ba89628436c18ff6
Toggle commit list
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment