Skip to content

Commit

Permalink
change make matrix strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
PetrKryslUCSD committed Mar 15, 2023
1 parent 8f6483f commit bcd7ea8
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 141 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "FinEtools"
uuid = "91bb5406-6c9a-523d-811d-0644c4229550"
authors = ["Petr Krysl <[email protected]>"]
version = "6.0.9"
version = "6.0.10"

[deps]
ChunkSplitters = "ae650224-84b6-46f8-82ea-d812ca08434e"
Expand Down
186 changes: 90 additions & 96 deletions src/AssemblyModule.jl
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,17 @@ function assemble!(
p = self.buffer_pointer
@assert p + ncolumns * nrows <= self.buffer_length + 1
@assert size(mat) == (nrows, ncolumns)
@inbounds for j in 1:ncolumns, i in 1:nrows
self.matbuffer[p] = mat[i, j] # serialized matrix
self.rowbuffer[p] = dofnums_row[i]
self.colbuffer[p] = dofnums_col[j]
p = p + 1
@inbounds for j in 1:ncolumns
if 0 < dofnums_col[j] <= self.ndofs_col
for i in 1:nrows
if 0 < dofnums_row[i] <= self.ndofs_row
self.matbuffer[p] = mat[i, j] # serialized matrix
self.rowbuffer[p] = dofnums_row[i]
self.colbuffer[p] = dofnums_col[j]
p = p + 1
end
end
end
end
self.buffer_pointer = p
return self
Expand All @@ -204,28 +210,20 @@ end
Make a sparse matrix.
"""
function makematrix!(self::SysmatAssemblerSparse)
@assert length(self.rowbuffer) >= self.buffer_pointer - 1
@assert length(self.colbuffer) >= self.buffer_pointer - 1
# We have the option of retaining the assembled results, but not
# constructing the sparse matrix.
if self.nomatrixresult
# No actual sparse matrix is returned. The entire result of the assembly
# is preserved in the assembler buffers.
# is preserved in the assembler buffers. The ends of the buffers are
# filled with reasonable values, just in case someone wants to look at
# them.
self.rowbuffer[self.buffer_pointer:end] .= 1
self.colbuffer[self.buffer_pointer:end] .= 1
self.matbuffer[self.buffer_pointer:end] .= 0.0
return spzeros(self.ndofs_row, self.ndofs_col)
end
# Otherwise, we will accumulate the sparse matrix from the records in the
# buffers.
@assert length(self.rowbuffer) >= self.buffer_pointer - 1
@assert length(self.colbuffer) >= self.buffer_pointer - 1
# Here we will go through the rows and columns, and whenever the row or
# the column refer to indexes outside of the limits of the matrix, the
# corresponding value will be set to 0 and assembled to row and column 1.
@inbounds for j in 1:self.buffer_pointer-1
if (self.rowbuffer[j] > self.ndofs_row) || (self.rowbuffer[j] <= 0)
self.rowbuffer[j] = 1
self.matbuffer[j] = 0.0
end
if (self.colbuffer[j] > self.ndofs_col) || (self.colbuffer[j] <= 0)
self.colbuffer[j] = 1
self.matbuffer[j] = 0.0
end
end
# The sparse matrix is constructed and returned. The buffers used for
# the assembly are cleared.
S = sparse(
Expand Down Expand Up @@ -379,11 +377,17 @@ function assemble!(
p = self.buffer_pointer
@assert p + ncolumns * nrows <= self.buffer_length + 1
@assert size(mat) == (nrows, ncolumns)
@inbounds for j in 1:ncolumns, i in j:nrows
self.matbuffer[p] = mat[i, j] # serialized matrix
self.rowbuffer[p] = dofnums[i]
self.colbuffer[p] = dofnums[j]
p = p + 1
@inbounds for j in 1:ncolumns
if 0 < dofnums[j] <= self.ndofs
for i in j:nrows
if 0 < dofnums[i] <= self.ndofs
self.matbuffer[p] = mat[i, j] # serialized matrix
self.rowbuffer[p] = dofnums[i]
self.colbuffer[p] = dofnums[j]
p = p + 1
end
end
end
end
self.buffer_pointer = p
return self
Expand All @@ -395,28 +399,22 @@ end
Make a sparse symmetric square matrix.
"""
function makematrix!(self::SysmatAssemblerSparseSymm)
if self.nomatrixresult
# No actual sparse matrix is returned. The entire result of the assembly
# is preserved in the assembler buffers.
return spzeros(self.ndofs, self.ndofs)
end
# Otherwise, we will accumulate the sparse matrix from the records in the
# buffers.
@assert length(self.rowbuffer) >= self.buffer_pointer - 1
@assert length(self.colbuffer) >= self.buffer_pointer - 1
# Here we will go through the rows and columns, and whenever the row or
# the column refer to indexes outside of the limits of the matrix, the
# corresponding value will be set to 0 and assembled to row and column 1.
@inbounds for j in 1:self.buffer_pointer-1
if (self.rowbuffer[j] > self.ndofs) || (self.rowbuffer[j] <= 0)
self.rowbuffer[j] = 1
self.matbuffer[j] = 0.0
end
if (self.colbuffer[j] > self.ndofs) || (self.colbuffer[j] <= 0)
self.colbuffer[j] = 1
self.matbuffer[j] = 0.0
end
# We have the option of retaining the assembled results, but not
# constructing the sparse matrix.
if self.nomatrixresult
# No actual sparse matrix is returned. The entire result of the assembly
# is preserved in the assembler buffers. The ends of the buffers are
# filled with reasonable values, just in case someone wants to look at
# them.
self.rowbuffer[self.buffer_pointer:end] .= 1
self.colbuffer[self.buffer_pointer:end] .= 1
self.matbuffer[self.buffer_pointer:end] .= 0.0
return spzeros(self.ndofs_row, self.ndofs_col)
end
# The sparse matrix is constructed and returned. The buffers used for
# the assembly are cleared.
S = sparse(
self.rowbuffer[1:self.buffer_pointer-1],
self.colbuffer[1:self.buffer_pointer-1],
Expand Down Expand Up @@ -547,10 +545,12 @@ function assemble!(
@assert p + ncolumns <= self.buffer_length + 1
@assert size(mat) == (nrows, ncolumns)
@inbounds for j in 1:ncolumns
self.matbuffer[p] = mat[j, j] # serialized matrix
self.rowbuffer[p] = dofnums[j]
self.colbuffer[p] = dofnums[j]
p = p + 1
if 0 < dofnums[j] <= self.ndofs
self.matbuffer[p] = mat[j, j] # serialized matrix
self.rowbuffer[p] = dofnums[j]
self.colbuffer[p] = dofnums[j]
p = p + 1
end
end
self.buffer_pointer = p
return self
Expand All @@ -562,28 +562,22 @@ end
Make a sparse symmetric square diagonal matrix.
"""
function makematrix!(self::SysmatAssemblerSparseDiag)
if self.nomatrixresult
# No actual sparse matrix is returned. The entire result of the assembly
# is preserved in the assembler buffers.
return spzeros(self.ndofs, self.ndofs)
end
# Otherwise, we will accumulate the sparse matrix from the records in the
# buffers.
@assert length(self.rowbuffer) >= self.buffer_pointer - 1
@assert length(self.colbuffer) >= self.buffer_pointer - 1
# Here we will go through the rows and columns, and whenever the row or
# the column refer to indexes outside of the limits of the matrix, the
# corresponding value will be set to 0 and assembled to row and column 1.
@inbounds for j in 1:self.buffer_pointer-1
if (self.rowbuffer[j] > self.ndofs) || (self.rowbuffer[j] <= 0)
self.rowbuffer[j] = 1
self.matbuffer[j] = 0.0
end
if (self.colbuffer[j] > self.ndofs) || (self.colbuffer[j] <= 0)
self.colbuffer[j] = 1
self.matbuffer[j] = 0.0
end
# We have the option of retaining the assembled results, but not
# constructing the sparse matrix.
if self.nomatrixresult
# No actual sparse matrix is returned. The entire result of the assembly
# is preserved in the assembler buffers. The ends of the buffers are
# filled with reasonable values, just in case someone wants to look at
# them.
self.rowbuffer[self.buffer_pointer:end] .= 1
self.colbuffer[self.buffer_pointer:end] .= 1
self.matbuffer[self.buffer_pointer:end] .= 0.0
return spzeros(self.ndofs_row, self.ndofs_col)
end
# The sparse matrix is constructed and returned. The buffers used for
# the assembly are cleared.
S = sparse(
self.rowbuffer[1:self.buffer_pointer-1],
self.colbuffer[1:self.buffer_pointer-1],
Expand Down Expand Up @@ -840,16 +834,22 @@ function assemble!(
# Now comes the lumping procedure
em2 = sum(sum(mat, dims = 1)) # total mass times the number of space dimensions
dem2 = zero(eltype(mat)) # total mass on the diagonal times the number of space dimensions
for i in 1:nrows
@inbounds for i in 1:nrows
dem2 += mat[i, i]
end
ffactor = em2 / dem2 # total-element-mass compensation factor
@inbounds for j in 1:ncolumns, i in j:nrows
if i == j # only the diagonal elements are assembled
self.matbuffer[p] = mat[i, j] * ffactor # serialized matrix
self.rowbuffer[p] = dofnums[i]
self.colbuffer[p] = dofnums[j]
p = p + 1
@inbounds for j in 1:ncolumns
if 0 < dofnums[j] <= self.ndofs
for i in j:nrows
if i == j # only the diagonal elements are assembled
if 0 < dofnums[i] <= self.ndofs
self.matbuffer[p] = mat[i, j] * ffactor # serialized matrix
self.rowbuffer[p] = dofnums[i]
self.colbuffer[p] = dofnums[j]
p = p + 1
end
end
end
end
end
self.buffer_pointer = p
Expand Down Expand Up @@ -877,28 +877,22 @@ end
Make a sparse HRZ-lumped **symmetric square** matrix.
"""
function makematrix!(self::SysmatAssemblerSparseHRZLumpingSymm)
if self.nomatrixresult
# No actual sparse matrix is returned. The entire result of the assembly
# is preserved in the assembler buffers.
return spzeros(self.ndofs, self.ndofs)
end
# Otherwise, we will accumulate the sparse matrix from the records in the
# buffers.
@assert length(self.rowbuffer) >= self.buffer_pointer - 1
@assert length(self.colbuffer) >= self.buffer_pointer - 1
# Here we will go through the rows and columns, and whenever the row or
# the column refer to indexes outside of the limits of the matrix, the
# corresponding value will be set to 0 and assembled to row and column 1.
@inbounds for j in 1:self.buffer_pointer-1
if (self.rowbuffer[j] > self.ndofs) || (self.rowbuffer[j] <= 0)
self.rowbuffer[j] = 1
self.matbuffer[j] = 0.0
end
if (self.colbuffer[j] > self.ndofs) || (self.colbuffer[j] <= 0)
self.colbuffer[j] = 1
self.matbuffer[j] = 0.0
end
# We have the option of retaining the assembled results, but not
# constructing the sparse matrix.
if self.nomatrixresult
# No actual sparse matrix is returned. The entire result of the assembly
# is preserved in the assembler buffers. The ends of the buffers are
# filled with reasonable values, just in case someone wants to look at
# them.
self.rowbuffer[self.buffer_pointer:end] .= 1
self.colbuffer[self.buffer_pointer:end] .= 1
self.matbuffer[self.buffer_pointer:end] .= 0.0
return spzeros(self.ndofs_row, self.ndofs_col)
end
# The sparse matrix is constructed and returned. The buffers used for
# the assembly are cleared.
S = sparse(
self.rowbuffer[1:self.buffer_pointer-1],
self.colbuffer[1:self.buffer_pointer-1],
Expand Down
Loading

4 comments on commit bcd7ea8

@PetrKryslUCSD
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/79641

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v6.0.10 -m "<description of version>" bcd7ea8917e84a06f966b856199eedbda91ec046
git push origin v6.0.10

@PetrKryslUCSD
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error while trying to register: Version 6.0.10 already exists

Please sign in to comment.