Solve the problem. This method updates the solution function ``u`` stored in the problem instance. Returns: The solution function.
(self)
| 133 | self._superlu_dist_options = superlu_dist_options |
| 134 | |
| 135 | def solve(self) -> Function: |
| 136 | """Solve the problem. |
| 137 | |
| 138 | This method updates the solution function ``u`` stored in the |
| 139 | problem instance. |
| 140 | |
| 141 | Returns: |
| 142 | The solution function. |
| 143 | """ |
| 144 | # Assemble lhs |
| 145 | self.A.set_value(self.A.data.dtype.type(0.0)) |
| 146 | assemble_matrix(self.A, self.a, bcs=self.bcs) # type: ignore[arg-type, misc] |
| 147 | self.A.scatter_reverse() |
| 148 | |
| 149 | # SuperLU_DIST solves in-place, so a deep copy of A is required. |
| 150 | A_superlu_dist = superlu_dist_matrix(self.A) |
| 151 | solver = superlu_dist_solver(A_superlu_dist) |
| 152 | if self._superlu_dist_options is not None: |
| 153 | for option, value in self._superlu_dist_options.items(): |
| 154 | solver.set_option(option, value) |
| 155 | |
| 156 | # Assemble rhs |
| 157 | self.b.array[:] = 0.0 |
| 158 | assemble_vector(self.b.array, self.L) # type: ignore[arg-type] |
| 159 | |
| 160 | # Apply boundary conditions to the rhs |
| 161 | if self.bcs: |
| 162 | apply_lifting(self.b.array, [self.a], bcs=[self.bcs]) |
| 163 | self.b.scatter_reverse(InsertMode.add) |
| 164 | for bc in self.bcs: |
| 165 | bc.set(self.b.array) |
| 166 | else: |
| 167 | self.b.scatter_reverse(InsertMode.add) |
| 168 | |
| 169 | # Solve linear system and update ghost values in the solution |
| 170 | error = solver.solve(self.b, self.x) |
| 171 | if error > 0: |
| 172 | raise RuntimeError(f"SuperLU_DIST returned non-zero error code: {error}") |
| 173 | self.x.scatter_forward() |
| 174 | self.u.x.array[:] = self.x.array |
| 175 | return self.u |
| 176 | |
| 177 | @property |
| 178 | def L(self) -> Form: |
nothing calls this directly
no test coverage detected