Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions demo/assembly_bcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def f(x):

# Add convection term
start_lhs = time.perf_counter()
dolfinx.fem.petsc.assemble_matrix(A, convection_form)
dolfinx.fem.petsc.assemble_matrix(A, convection_form) # type: ignore
A.assemble()
A.scale(-0.5)
A.axpy(1.0 / dt, M, PETSc.Mat.Structure.SUBSET_NONZERO_PATTERN) # type: ignore
Expand Down Expand Up @@ -182,7 +182,7 @@ def f(x):

# Add convection term
start_lhs_new = time.perf_counter()
dolfinx.fem.petsc.assemble_matrix(Ax, convection_form)
dolfinx.fem.petsc.assemble_matrix(Ax, convection_form) # type: ignore
Ax.assemble()
Ax.scale(0.5)
Ax.axpy(1.0 / dt, M, PETSc.Mat.Structure.SUBSET_NONZERO_PATTERN) # type: ignore
Expand Down
7 changes: 3 additions & 4 deletions demo/taylor_green.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ def eval_y(self, x: npt.NDArray[np.float64]) -> npt.NDArray[np.float64]:
options = {"low_memory_version": inputs.lm}

solver_options = {
"tentative": {"ksp_type": "preonly", "pc_type": "lu"},
"pressure": {"ksp_type": "preonly", "pc_type": "lu"},
"scalar": {"ksp_type": "preonly", "pc_type": "lu"},
"tentative": {"ksp_type": "preonly", "pc_type": "lu", "error_if_not_converged": True},
"pressure": {"ksp_type": "preonly", "pc_type": "lu", "error_if_not_converged": True},
"scalar": {"ksp_type": "preonly", "pc_type": "lu", "error_if_not_converged": True},
}

space_errors = np.zeros((2, len(inputs.Ns)), dtype=np.float64)
Expand Down Expand Up @@ -199,7 +199,6 @@ def eval_y(self, x: npt.NDArray[np.float64]) -> npt.NDArray[np.float64]:
for i in range(num_steps):
u_time.value += dt
p_time.value += dt

solver.solve(dt, nu, max_iter=1)
L2_u_loc = dolfinx.fem.assemble_scalar(L2_u)
error_u = mesh.comm.allreduce(L2_u_loc, op=MPI.SUM)
Expand Down
29 changes: 15 additions & 14 deletions docs/splitting_schemes.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,26 +252,26 @@ for i in range(num_time_steps):
# Compute convecting velocity for C
for j in range(components):
bar_u[j][:] = 0
bar_u[j]+= 1.5 * u_1[j]
bar_u[j]+= -0.5 * u_2[j]
bar_u[j] += 1.5 * u_1[j]
bar_u[j] += -0.5 * u_2[j]
# Compute 0.5C
A = assemble_C_matrix()
A.scale(0.5)
# Add mass matrix
A.axpy(1/dt, M)
A.axpy(1 / dt, M)

#Add stiffness matrix
A.axpy(-0.5*nu, K)
# Add stiffness matrix
A.axpy(-0.5 * nu, K)

# Compute matrix vector product and add to RHS
for j in range(components):
b[j] = body_forces
b_tmp[j] = A * u_1[j]
b[j]+= b_tmp[j]
b[j] += b_tmp[j]

# Reset A for LHS
A.scale(-1)
A.xpy(2/dt, M)
A.xpy(2 / dt, M)

#
```
Expand All @@ -289,22 +289,23 @@ for i in range(num_time_steps):
# Compute convecting veloctiy for C
for j in range(components):
bar_u[j][:] = 0
bar_u[j]+= 1.5 * u_1[j]
bar_u[j]+= -0.5 * u_2[j]
bar_u[j] += 1.5 * u_1[j]
bar_u[j] += -0.5 * u_2[j]

# Assemble RHS
for j in range(components):
b[j] = assemble_vector(body_forces[j] + mass_terms[j] \
+ stiffness_terms[j] + convective_terms[j])
b[j] = assemble_vector(
body_forces[j] + mass_terms[j] + stiffness_terms[j] + convective_terms[j]
)

# Compute -0.5C
A = assemble_C_matrix()
A.scale(-0.5)
# Add mass matrix
A.axpy(-1/dt, M)
A.axpy(-1 / dt, M)

#Add stiffness matrix
A.axpy(0.5*nu, K)
# Add stiffness matrix
A.axpy(0.5 * nu, K)
```

In the next section, we will consider the performance differences for these two strategies
Expand Down
4 changes: 3 additions & 1 deletion test/test_tentative_velocity.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def gather_PETScMatrix(
A: PETSc.Mat, # type: ignore
comm: MPI.Comm,
root: int = 0,
) -> scipy.sparse.csr_matrix:
) -> scipy.sparse.csr_matrix | None:
"""
Given a distributed PETSc matrix, gather in on process 'root' in
a scipy CSR matrix
Expand All @@ -38,6 +38,8 @@ def gather_PETScMatrix(
(np.hstack(av_all), np.hstack(aj_all), ai_cum), # type: ignore
shape=A.getSize(),
)
else:
return None


def create_tentative_forms(
Expand Down