Hello
If I have the following terms
f = Coefficient(V)
v = Testfunction(V)
a = f * v * dx
then if I assemble the form, I will get a vector, but if it possible to keep it as a matrix, like the mass matrix, but here I want to keep the function f be something that I can input myself, so I didn’t define it as a Trial function.
dokken
November 8, 2024, 3:24pm
2
What do you mean by input yourself?
You can just make the mass matrix with a trial function, and then use matrix-vector multiplication at a later stage if you want to re-use the data.
I need to change the function f
frequently, and I need to do operation on the element of this matrix.
dokken
November 8, 2024, 3:28pm
4
Then create he mass matrix (using a trial function), and then do MatVec
operations internally.
I for instance do this in Python within oasisx:
# Add convection term
dolfinx.fem.petsc.assemble_matrix(A, convection_form)
A.assemble()
# Do mat-vec operations
with dolfinx.common.Timer(f"~{P} {i} {N} Matvec strategy") as _:
A.scale(-0.5)
A.axpy(1.0 / dt, M)
A.axpy(-0.5 * nu, K)
A.mult(u_1.x.petsc_vec, b.x.petsc_vec)
b.x.scatter_forward()
# Compute the vector without using pre-generated matrices
b_d = dolfinx.fem.Function(V)
with dolfinx.common.Timer(f"~{P} {i} {N} Action strategy"):
dolfinx.fem.petsc.assemble_vector(b_d.x.petsc_vec, lhs)
b_d.x.scatter_reverse(dolfinx.la.InsertMode.add)
b_d.x.scatter_forward()
# Compare results
assert np.allclose(b.x.array, b_d.x.array)
using MatMult — PETSc 3.22.1 documentation
1 Like