MCPcopy Create free account
hub / github.com/FEniCS/dolfinx / solve

Method solve

python/dolfinx/fem/problems.py:135–175  ·  view source on GitHub ↗

Solve the problem. This method updates the solution function ``u`` stored in the problem instance. Returns: The solution function.

(self)

Source from the content-addressed store, hash-verified

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:

Callers

nothing calls this directly

Calls 10

assemble_matrixFunction · 0.90
superlu_dist_matrixFunction · 0.90
superlu_dist_solverFunction · 0.90
assemble_vectorFunction · 0.90
apply_liftingFunction · 0.90
set_valueMethod · 0.80
scatter_forwardMethod · 0.80
scatter_reverseMethod · 0.45
set_optionMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected