Skip to content

Commit 3fb2f83

Browse files
committed
bug fix
1 parent 36edd77 commit 3fb2f83

File tree

1 file changed

+55
-33
lines changed

1 file changed

+55
-33
lines changed

src/Commons/MatrixCreation.jl

Lines changed: 55 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,16 @@ function allocate_all_matrices_vectors(u_adv, params, simcase)
116116
@unpack Utn1, Ptn1, tests = params
117117
V, Q = tests
118118

119-
Mat_Tuu, _ = assemble_matrix_and_vector(Tuu, rhs, Utn1, V)
120-
Mat_Tpu, _ = assemble_matrix_and_vector(Tpu, rhs, Utn1, Q)
119+
Mat_Tuu = allocate_matrix(Tuu, rhs, Utn1, V)
120+
Mat_Tpu = allocate_matrix(Tpu, rhs, Utn1, Q)
121121

122-
Mat_Auu, Vec_Auu = assemble_matrix_and_vector(Auu, rhs, Utn1, V)
123-
Mat_Aup, Vec_Aup = assemble_matrix_and_vector(Aup, rhs, Ptn1, V)
124-
Mat_Apu, Vec_Apu = assemble_matrix_and_vector(Apu, rhs, Utn1, Q)
125-
Mat_App, Vec_App = assemble_matrix_and_vector(App, rhs, Ptn1, Q)
122+
Mat_Auu, Vec_Auu = allocate_matrix_and_vector(Auu, rhs, Utn1, V)
123+
Mat_Aup, Vec_Aup = allocate_matrix_and_vector(Aup, rhs, Ptn1, V)
124+
Mat_Apu, Vec_Apu = allocate_matrix_and_vector(Apu, rhs, Utn1, Q)
125+
Mat_App, Vec_App = allocate_matrix_and_vector(App, rhs, Ptn1, Q)
126126

127-
Mat_ML, _ = assemble_matrix_and_vector(ML, rhs, Utn1, V)
128-
Mat_S, _ = assemble_matrix_and_vector(S, rhs, Ptn1, Q)
127+
Mat_ML= allocate_matrix(ML, rhs, Utn1, V)
128+
Mat_S = allocate_matrix(S, rhs, Ptn1, Q)
129129

130130
Mat_inv_ML = allocate_Mat_inv_ML(Mat_ML)
131131
Vec_Ap = Vec_Apu + Vec_App
@@ -134,6 +134,21 @@ function allocate_all_matrices_vectors(u_adv, params, simcase)
134134
return Mat_Tuu, Mat_Tpu, Mat_Auu, Mat_Aup, Mat_Apu, Mat_App, Mat_ML, Mat_inv_ML, Mat_S, Vec_Auu, Vec_Aup, Vec_Apu, Vec_App, Vec_Au, Vec_Ap
135135
end
136136

137+
138+
function allocate_matrix(a::Function,rhs::Function,U,V )
139+
feop1 = AffineFEOperator(a,rhs,U,V)
140+
Mat = get_matrix(feop1)
141+
return Mat
142+
end
143+
144+
function allocate_matrix_and_vector(a::Function,rhs::Function,U,V )
145+
feop1 = AffineFEOperator(a,rhs,U,V)
146+
Mat = get_matrix(feop1)
147+
Vec = get_vector(feop1)
148+
return Mat, Vec
149+
end
150+
151+
137152
function update_all_matrices_vectors!(matrices::Tuple, u_adv, params, simcase)
138153

139154
Mat_Tuu, Mat_Tpu, Mat_Auu, Mat_Aup, Mat_Apu, Mat_App, Mat_ML, Mat_inv_ML, Mat_S, Vec_Auu, Vec_Aup, Vec_Apu, Vec_App, Vec_Au, Vec_Ap = matrices
@@ -144,16 +159,22 @@ function update_all_matrices_vectors!(matrices::Tuple, u_adv, params, simcase)
144159
Tuu, Tpu, Auu, Aup, Apu, App, ML, S, rhs = segregated_equations(u_adv, params, simcase)
145160

146161

147-
assemble_matrix!(Tuu,Mat_Tuu,Utn1, V)
148-
assemble_matrix!(Tpu, Mat_Tpu, Utn1, Q)
162+
update_matrix!(Tuu,Mat_Tuu,Utn1, V)
163+
update_matrix!(Tpu, Mat_Tpu, Utn1, Q)
164+
165+
# update_matrix_vector!(Auu,Mat_Auu,Vec_Auu,Utn1,V)
166+
# update_matrix_vector!(Aup,Mat_Aup,Vec_Aup,Ptn1,V)
167+
# update_matrix_vector!(Apu,Mat_Apu,Vec_Apu,Utn1,Q)
168+
# update_matrix_vector!(App,Mat_App,Vec_App,Ptn1,Q)
149169

150-
assemble_matrix_and_vector!(Auu,rhs,Mat_Auu,Vec_Auu,Utn1,V)
151-
assemble_matrix_and_vector!(Aup,rhs,Mat_Aup,Vec_Auu,Ptn1,V)
152-
assemble_matrix_and_vector!(Apu,rhs,Mat_Apu,Vec_Apu,Utn1,Q)
153-
assemble_matrix_and_vector!(App,rhs,Mat_App,Vec_App,Ptn1,Q)
154170

155-
assemble_matrix!(ML,Mat_ML,Utn1, V)
156-
assemble_matrix!(S,Mat_S,Ptn1, Q)
171+
172+
println("norm Vec_App = $(norm(Vec_App))")
173+
update_matrix_vector!(App,Mat_App,Vec_App,Ptn1,Q)
174+
println("norm Vec_App = $(norm(Vec_App))")
175+
176+
update_matrix!(ML,Mat_ML,Utn1, V)
177+
update_matrix!(S,Mat_S,Ptn1, Q)
157178

158179

159180
Mat_inv_ML = allocate_Mat_inv_ML(Mat_ML)
@@ -165,27 +186,28 @@ function update_all_matrices_vectors!(matrices::Tuple, u_adv, params, simcase)
165186
end
166187

167188

168-
# function update_matrix_vector!(A::AbstractMatrix, b::AbstractVector, a::Function, U, V)
169-
# dv = get_fe_basis(V)
170-
# du = get_trial_fe_basis(U)
189+
function update_matrix_vector!( a::Function, A::AbstractMatrix, b::AbstractVector, U, V)
190+
dv = get_fe_basis(V)
191+
du = get_trial_fe_basis(U)
171192

172-
# mat_contribs = a(du, dv)
173-
# uhd = zero(U)
174-
# data = collect_cell_matrix_and_vector(U, V, mat_contribs, 0.0, uhd)
175-
# assembler = SparseMatrixAssembler(U, V)
176-
# assemble_matrix_and_vector!(A, b, assembler, data)
177-
# end
193+
mat_contribs = a(du, dv)
178194

179-
# function update_matrix!(A::AbstractMatrix, a::Function, U, V)
180-
# dv = get_fe_basis(V)
181-
# du = get_trial_fe_basis(U)
195+
uhd = zero(U)
196+
data = collect_cell_matrix_and_vector(U, V, mat_contribs, 0.0, uhd)
197+
assembler = SparseMatrixAssembler(U, V)
198+
assemble_matrix_and_vector!(A, b, assembler, data)
199+
end
182200

183-
# mat_contribs = a(du, dv)
184-
# data = collect_cell_matrix(U, V, mat_contribs)
201+
function update_matrix!(a::Function, A::AbstractMatrix, U, V)
202+
dv = get_fe_basis(V)
203+
du = get_trial_fe_basis(U)
185204

186-
# assembler = SparseMatrixAssembler(U, V)
187-
# assemble_matrix!(A, assembler, data)
188-
# end
205+
mat_contribs = a(du, dv)
206+
data = collect_cell_matrix(U, V, mat_contribs)
207+
208+
assembler = SparseMatrixAssembler(U, V)
209+
assemble_matrix!(A, assembler, data)
210+
end
189211

190212

191213
end

0 commit comments

Comments
 (0)