Skip to content

Commit

Permalink
fix assembly bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
PetrKryslUCSD committed Apr 18, 2023
1 parent e1d825c commit a063890
Show file tree
Hide file tree
Showing 4 changed files with 364 additions and 18 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 <pkrysl@ucsd.edu>"]
version = "6.0.13"
version = "6.0.14"

[deps]
ChunkSplitters = "ae650224-84b6-46f8-82ea-d812ca08434e"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ The package supports application packages, for instance:

## News

- 04/18/2023: Implement resizing of assembly buffers. Makematrix! resets pointers.
- 04/16/2023: Enabled creation of finite element sets from arbitrary arrays.
- 03/15/2023: Changed strategy when assembling into the COO format.
- 03/10/2023: Genericity of arguments enabled in the assembly module.
Expand Down
48 changes: 39 additions & 9 deletions src/AssemblyModule.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ mutable struct SysmatAssemblerSparse{IT, MBT, IBT} <: AbstractSysmatAssembler
ndofs_row::IT
ndofs_col::IT
nomatrixresult::Bool
force_init::Bool
end

"""
Expand Down Expand Up @@ -97,8 +98,8 @@ At this point all the buffers of the assembler have been cleared, and
`makematrix!(a) ` is no longer possible.
"""
function SysmatAssemblerSparse(z= zero(FFlt), nomatrixresult = false)
return SysmatAssemblerSparse(0, FFlt[z], FInt[0], FInt[0], 0, 0, 0, nomatrixresult)
function SysmatAssemblerSparse(z = zero(FFlt), nomatrixresult = false)
return SysmatAssemblerSparse(0, FFlt[z], FInt[0], FInt[0], 0, 0, 0, nomatrixresult, false)
end

"""
Expand Down Expand Up @@ -156,6 +157,7 @@ function startassembly!(
end
# Leave the buffers uninitialized, unless the user requests otherwise
if force_init
self.force_init = force_init
self.rowbuffer .= 1
self.colbuffer .= 1
self.matbuffer .= 0
Expand Down Expand Up @@ -186,7 +188,18 @@ function assemble!(
nrows = length(dofnums_row)
ncolumns = length(dofnums_col)
p = self.buffer_pointer
@assert p + ncolumns * nrows <= self.buffer_length + 1
if p + ncolumns * nrows >= self.buffer_length
new_buffer_length = self.buffer_length + ncolumns * nrows * 1000
resize!(self.rowbuffer, new_buffer_length)
resize!(self.colbuffer, new_buffer_length)
resize!(self.matbuffer, new_buffer_length)
if self.force_init
self.rowbuffer[self.buffer_length+1:end] .= 1
self.colbuffer[self.buffer_length+1:end] .= 1
self.matbuffer[self.buffer_length+1:end] .= 0
end
self.buffer_length = new_buffer_length
end
@assert size(mat) == (nrows, ncolumns)
@inbounds for j in 1:ncolumns
if 0 < dofnums_col[j] <= self.ndofs_col
Expand Down Expand Up @@ -243,7 +256,8 @@ function makematrix!(self::SysmatAssemblerSparse)
self.ndofs_row,
self.ndofs_col,
)
self = SysmatAssemblerSparse(zero(eltype(self.matbuffer)))# get rid of the buffers
# Get ready for more assembling
self.buffer_pointer = 1
return S
end

Expand All @@ -266,6 +280,7 @@ mutable struct SysmatAssemblerSparseSymm{IT, MBT, IBT} <: AbstractSysmatAssemble
buffer_pointer::IT
ndofs::IT
nomatrixresult::Bool
force_init::Bool
end

"""
Expand Down Expand Up @@ -296,7 +311,7 @@ This is how a symmetric sparse matrix is assembled from two square dense matrice
SysmatAssemblerSparse
"""
function SysmatAssemblerSparseSymm(z= zero(FFlt), nomatrixresult = false)
return SysmatAssemblerSparseSymm(0, FFlt[z], FInt[0], FInt[0], 0, 0, nomatrixresult)
return SysmatAssemblerSparseSymm(0, FFlt[z], FInt[0], FInt[0], 0, 0, nomatrixresult, false)
end

"""
Expand Down Expand Up @@ -356,6 +371,7 @@ function startassembly!(
self.rowbuffer .= 1
self.colbuffer .= 1
self.matbuffer .= 0
self.force_init = force_init
end
return self
end
Expand Down Expand Up @@ -385,7 +401,18 @@ function assemble!(
nrows = length(dofnums)
ncolumns = nrows
p = self.buffer_pointer
@assert p + ncolumns * nrows <= self.buffer_length + 1
if p + ncolumns * nrows >= self.buffer_length
new_buffer_length = self.buffer_length + ncolumns * nrows * 1000
resize!(self.rowbuffer, new_buffer_length)
resize!(self.colbuffer, new_buffer_length)
resize!(self.matbuffer, new_buffer_length)
if self.force_init
self.rowbuffer[self.buffer_length+1:end] .= 1
self.colbuffer[self.buffer_length+1:end] .= 1
self.matbuffer[self.buffer_length+1:end] .= 0
end
self.buffer_length = new_buffer_length
end
@assert size(mat) == (nrows, ncolumns)
@inbounds for j in 1:ncolumns
if 0 < dofnums[j] <= self.ndofs
Expand Down Expand Up @@ -448,7 +475,8 @@ function makematrix!(self::SysmatAssemblerSparseSymm)
@inbounds for j in axes(S, 1)
S[j, j] *= 0.5 # the diagonal is there twice; fix it;
end
self = SysmatAssemblerSparseSymm(zero(eltype(self.matbuffer))) # get rid of the buffers
# Get ready for more assembling
self.buffer_pointer = 1
return S
end

Expand Down Expand Up @@ -615,7 +643,8 @@ function makematrix!(self::SysmatAssemblerSparseDiag)
self.ndofs,
self.ndofs,
)
self = SysmatAssemblerSparseDiag(zero(eltype(self.matbuffer))) # get rid of the buffers
# Get ready for more assembling
self.buffer_pointer = 1
return S
end

Expand Down Expand Up @@ -945,7 +974,8 @@ function makematrix!(self::SysmatAssemblerSparseHRZLumpingSymm)
@inbounds for j in axes(S, 1)
S[j, j] /= 2.0 # the diagonal is there twice; fix it;
end
self = SysmatAssemblerSparseHRZLumpingSymm(zero(eltype(self.matbuffer)))# get rid of the buffers
# Get ready for more assembling
self.buffer_pointer = 1
return S
end

Expand Down
Loading

2 comments on commit a063890

@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/81856

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.14 -m "<description of version>" a063890702213b2ea984893905c6032ed368f5a3
git push origin v6.0.14

Please sign in to comment.