User-friendly API, use AbstractSolver as Adapter
In order to make the code more easy to use, we could reestablish the MySolver_Variables data access classes.
We could implement the user hooks that take a raw pointer in the AbstractSolver, and would then call the user solver's implementation which takes the data access object as argument.
Example:
void MyAbstractSolver::adjustPointSolution(double* const Q,...) {
Variables vars(Q);
static_cast<MyUserSolver*>(this)->adjustPointSolution(vars,...);
}
We could then have additional data access classes for the full solution array, e.g. Solution
and ReadOnlySolution
.
Potentially, we could then introduce dimension-aware iterators with appropriate typecast to
a Variables
or ReadOnlyVariables
object.
This would allow writing code like the following.
Example:
void MyAbstractSolver::refinementCriterion(ReadOnlySolution solution,...) {
double rhoMax = 0;
for ( ReadOnlyVariables& Q : solution ) {
rhoMax = std::max( Q.rho(), rhoMax );
}
}
Remarks
(ReadOnly)Variables
and Variables
must be split or declared in such a way that
it is clear that there is not necessarily a contiguous array storing
and variables and parameters. We should get rid of the index operator and
have separate functions double
parameter(int i), double& variable(int i)
instead.