Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP Polymorphic sparse scheme to solve following use case (#46) #47

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tkloczko
Copy link

@tkloczko tkloczko commented Aug 10, 2020

Let us consider a Finite-Element or Finite-Volume code for which we have to solve a linear system using different libraries (Hypre, Petsc, Trilinos, Mumps, PastiX, ...). We would like to avoid conversions between different formats of sparse matrix. As the linear solver drives the choice of the sparse matrix format, we would like that the matrix the FE code has to fill has directly the format the linear solver requires. The choice of the solver is done at runtime, so it means that the underlying sparse scheme of the matrix should be instanciated at runtime. It implies that the sparse array or sparse tensor is a wrapper around a polymorphic sparse scheme. This latter is a bridge over an abstract scheme that uses type erasure to handle the different format implementations.

The following piece of code tries to illustrate which problem we try to solve. Let us say that we have wrapped several linear solvers into a minimal common API, namely MyLinearSolver. According to the choice of the linear solver, we want the Finite Volume solver to fill the sparse matrix A in the format that the linear solver requires. This choice is done after, for instance reading options in a file. It is thus at runtime that everything should work.

namespace xt {
template <T>
using polymorphic_sparse_array = xsparse_array<T, xsparse_polymorphic_scheme<T>>;
}

MyFVSolver fv_solver;
MyLinearSolver lin_solver;

// Init options and policy
fv_solver.init(options);
lin_solver.init(options);

// Init sparse matrix using the linear solver choice
xt::scheme_policy.setPolicy(lin_solver.format());
xt::polymorphic_sparse_array<double> A; 
// A uses now the scheme defined by the policy but the type remains the same
// enabling to use this unique type as argument for both MyFVSolver and MyLinearSolver API.

//  In the time loop

fv_solver.supplySparseMatrix(A); // No template except the value type of the matrix.
fv_solver.computeConvectiveTerm(); // fill the sparse matrix

lin_solver.setSparseMatrix(A); // No template except the value type of the matrix.
lin_solver.solve();

/// ...

* Let us consider a Finite-Element or Finite-Volume code for which we
  have to solve a linear system using different libraries (Hypre, Petsc,
  Trilinos, Mumps, PastiX, ...). We would like to avoid conversions
  between different formats of sparse matrix. As the linear solver
  drives the choice of the sparse matrix format, we would like that the
  matrix the FE code has to fill has directly the format the linear
  solver requires. The choice of the solver is done at runtime, so it
  means that the underlying sparse scheme of the matrix should be
  instanciated at runtime. It implies that the sparse array or sparse
  tensor is a wrapper around a polymorphic sparse scheme. This latter is
  a bridge over an abstract scheme that uses type erasure to handle the
  different format implementation.
@tkloczko tkloczko changed the title Polymorphic sparse scheme to solve following use case (#46) WIP Polymorphic sparse scheme to solve following use case (#46) Aug 10, 2020
@tkloczko
Copy link
Author

In a recent past, we encountered the same difficulties, naming dealing with runtime options and template collections, using CGAL. A similar solution was found to address them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant