libMesh/libmesh: coverage diff

Base 6ae6ba Head #4515 9b32e2
Total Total +/- New
Rate 65.86% 65.88% +0.02% 100.00%
Hits 79476 79530 +54 68
Misses 41196 41188 -8 0
Filename Stmts Miss Cover
include/solvers/linear_solver.h +3 +3 -8.61%
src/mesh/distributed_mesh.C 0 -2 +0.25%
src/mesh/mesh_triangle_holes.C 0 +1 -0.27%
src/solvers/linear_solver.C 0 -10 +13.16%
src/systems/linear_implicit_system.C +43 0 +4.45%
TOTAL +46 -8 +0.02%
code
coverage unchanged
code
coverage increased
code
coverage decreased
+
line added or modified

include/solvers/linear_solver.h

268  
269  
270  
271 +
272  
273 +
274 +
275  
276  
277  
  /**
   * Set the solver configuration object.
   */
  void set_solver_configuration(SolverConfiguration & solver_configuration)
  {
    this->set_solver_configuration(&solver_configuration);
  }

protected:
  /**

src/mesh/distributed_mesh.C

1546  
1547  
1548  
1549  
1550  
1551  
1552  
1553  
1554  
1555  
1556  
1557  
1558  
1559  
                      sender_could_become_owner)
                    {
                      if (it != repartitioned_node_pids.end() &&
                          pid < it->second)
                        it->second = pid;
                      else
                        repartitioned_node_pids[n] = pid;
                    }
                  else
                    if (it == repartitioned_node_pids.end())
                      repartitioned_node_pids[n] =
                        DofObject::invalid_processor_id;

                  repartitioned_node_sets_to_push[pid].insert(n);

src/mesh/mesh_triangle_holes.C

270  
271  
272  
273  
274  
275  
276  
    {
      ray_target = inside - Point(1);
      intersection_distances =
        this->find_ray_intersections(inside, ray_target);
    }

  // I'd make this an assert, but I'm not 100% confident we can't

src/solvers/linear_solver.C

176  
177  
178  
179 +
180  
181 +
182  
183  
184  
185 +
186  
187 +
188  
189  
190  
}

template <typename T>
SolverConfiguration * LinearSolver<T>::solver_configuration() const
{
  return _solver_configuration;
}

template <typename T>
void LinearSolver<T>::set_solver_configuration(SolverConfiguration * solver_configuration)
{
  _solver_configuration = solver_configuration;
}

template <typename T>
195  
196  
197  
198 +
199  
200  
201  
202  
203 +
204  
205  
206 +
207  
208  
209  
  if (setting.has_value())
    return setting.value();

  if (_solver_configuration)
    if (const auto it = this->_solver_configuration->real_valued_data.find(setting_name);
        it != this->_solver_configuration->real_valued_data.end())
      return double(it->second);

  if (default_value.has_value())
    return default_value.value();

  libmesh_error_msg("Linear solver setting '"
                    << setting_name
                    << "' must be supplied through an input argument, a SolverConfiguration "
                    << "object, or a default value.");
219  
220  
221  
222 +
223  
224  
225  
226  
227 +
228  
229  
230 +
231  
232  
233  
  if (setting.has_value())
    return setting.value();

  if (_solver_configuration)
    if (const auto it = this->_solver_configuration->int_valued_data.find(setting_name);
        it != this->_solver_configuration->int_valued_data.end())
      return it->second;

  if (default_value.has_value())
    return default_value.value();

  libmesh_error_msg("Linear solver setting '"
                    << setting_name
                    << "' must be supplied through an input argument, a SolverConfiguration "
                    << "object, or a default value.");

src/systems/linear_implicit_system.C

46  
47  
48  
49 +
50  
51 +
52 +
53 +
54  
55 +
56 +
57 +
58  
59 +
60 +
61 +
62 +
63 +
64  
65  
66  
class ScopedSolverConfiguration
{
public:
  ScopedSolverConfiguration(LinearSolver<Number> & solver,
                            SolverConfiguration * temporary_configuration)
    : _solver(solver),
      _previous_configuration(solver.solver_configuration()),
      _restore(temporary_configuration != nullptr)
  {
    if (_restore)
      _solver.set_solver_configuration(temporary_configuration);
  }

  ~ScopedSolverConfiguration()
  {
    if (_restore)
      _solver.set_solver_configuration(_previous_configuration);
  }

private:
  LinearSolver<Number> & _solver;
77  
78  
79  
80 +
81 +
82  
83 +
84  
85 +
86 +
87 +
88 +
89 +
90  
91 +
92  
93 +
94 +
95 +
96  
97 +
98  
99 +
100  
101 +
102 +
103  
104 +
105  
106  
107  
class SubsetRestrictionGuard
{
public:
  explicit SubsetRestrictionGuard(LinearSolver<Number> & solver)
    : _solver(solver), _restricted(false)
  {
  }

  ~SubsetRestrictionGuard()
  {
    if (_restricted)
      _solver.restrict_solve_to(nullptr);
  }

  void restrict(const std::vector<unsigned int> * dofs, const SubsetSolveMode subset_solve_mode)
  {
    _restricted = true;
    _solver.restrict_solve_to(dofs, subset_solve_mode);
  }

  void clear()
  {
    if (_restricted)
      {
        _solver.restrict_solve_to(nullptr);
        _restricted = false;
      }
  }

private:
  LinearSolver<Number> & _solver;
195  
196  
197  
198 +
199 +
200  
201 +
202  
203 +
204 +
205  
206  
207  
208  
209 +
210  
211 +
212  
213  
214  
215  
216  
217 +
218  
219 +
220  
221 +
222  
223 +
224  
225  
226  
227 +
228  
229 +
230  
231 +
232  
233 +
234  
235  
236 +
237  
238  
239  
240 +
241  
242 +
243  
244 +
245  
246 +
247  
248  
249 +
250  
251  
252  
253  
254 +
255  
256 +
257  
258 +
259  
260  
261 +
262  
263  
264 +
265  
266  
267  

void LinearImplicitSystem::solve ()
{
  this->solve(LinearImplicitSystemSolveOptions{});
}

void LinearImplicitSystem::solve(const LinearImplicitSystemSolveOptions & options)
{
  LinearSolver<Number> * const solver = options.solver ? options.solver : linear_solver.get();
  libmesh_assert(solver);

#ifndef NDEBUG
#ifdef LIBMESH_HAVE_MPI
  int communicator_comparison;
  libmesh_call_mpi(
      MPI_Comm_compare(solver->comm().get(), this->comm().get(), &communicator_comparison));
  libmesh_assert(communicator_comparison == MPI_IDENT || communicator_comparison == MPI_CONGRUENT);
#else
  libmesh_assert_equal_to(solver->comm().get(), this->comm().get());
#endif
#endif

  const bool assemble = options.assemble_before_solve.value_or(this->assemble_before_solve);

  if (assemble)
    // Assemble the linear system
    this->assemble();

  ScopedSolverConfiguration scoped_configuration(*solver, options.solver_configuration);

  // If the linear solver hasn't been initialized, we do so here.
  if (this->prefix_with_name())
    solver->init(this->prefix().c_str());
  else
    solver->init();

  solver->init_systems(*this);

  SubsetRestrictionGuard subset_guard(*solver);

  if (_subset != nullptr)
    subset_guard.restrict(&_subset->dof_ids(), _subset_solve_mode);

  // Solve the linear system.  Several cases:
  std::pair<unsigned int, Real> rval = std::make_pair(0,0.0);
  SparseMatrix<Number> * const preconditioner = this->request_matrix("Preconditioner");

  if (options.solver_configuration)
    {
      if (_shell_matrix)
        // 1.) Shell matrix with or without user-supplied preconditioner.
        rval = solver->solve(*_shell_matrix, preconditioner, *solution, *rhs);
      else
        // 2.) No shell matrix, with or without user-supplied preconditioner.
        rval = solver->solve(*matrix, preconditioner, *solution, *rhs);
    }
  else
    {
      // Get the user-specified linear solver tolerance and iteration limit.
      const auto [maxits, tol] = this->get_linear_solve_parameters();

      if (_shell_matrix)
        // 1.) Shell matrix with or without user-supplied preconditioner.
        rval = solver->solve(*_shell_matrix, preconditioner, *solution, *rhs, tol, maxits);
      else
        // 2.) No shell matrix, with or without user-supplied preconditioner.
        rval = solver->solve(*matrix, preconditioner, *solution, *rhs, tol, maxits);
    }

  subset_guard.clear();

  // Store the number of linear iterations required to
  // solve and the final residual.