Currently, in the C++ interface to XBraid, when the user writes their subclass of BraidApp (in braid.hpp), they are given the unhelpful incomplete type braid_Vector, which they have to cast every time to a pointer of their own BraidVector type. For example, in examples/ex-01-pp.cpp:
int MyBraidApp::Sum(double alpha,
braid_Vector x_,
double beta,
braid_Vector y_)
{
BraidVector *x = (BraidVector*) x_;
BraidVector *y = (BraidVector*) y_;
(y->value) = alpha*(x->value) + beta*(y->value);
return 0;
}
This could be fixed by adding a template type to the BraidApp super class. For example, in the generic_cpp branch where I've made the change the declaration of MyBraidApp changes only slightly:
class MyBraidApp : public BraidApp<MyBraidVector>
{
...
Then all the methods can be written much nicer using the BraidVector type (which is typedef'd in this example to MyBraidVector *):
int MyBraidApp::Sum(double alpha,
BraidVector x,
double beta,
BraidVector y)
{
(y->value) = alpha*(x->value) + beta*(y->value);
return 0;
}
The pointer casting then takes place in the _BraidAppX functions automatically. I think this is pretty obviously nicer for the user, since there's never really a situation where they want to use braid_Vector in C++, and the pointer casts are probably free.
The only other small change this creates though is either:
BraidCore must have a template type as well:
...
// Initialize Braid Core Object and set some solver options
BraidCore<MyBraidVector> core(MPI_COMM_WORLD, &app);
core.SetPrintLevel(2);
...
or
2. BraidCore's SetSpacialCoarsenAndRefine, SetSync and SetResidual methods (which take no arguments) can be changed to boolean optional arguments to the BraidCore constructor, so unless you use those methods, no change is needed to your code. This option is rendered in my generic_cpp_2 branch.
I don't know how flexible the API for the C++ interface is, but I hope this change can be considered
Currently, in the C++ interface to XBraid, when the user writes their subclass of
BraidApp(in braid.hpp), they are given the unhelpful incomplete typebraid_Vector, which they have to cast every time to a pointer of their ownBraidVectortype. For example, in examples/ex-01-pp.cpp:This could be fixed by adding a template type to the
BraidAppsuper class. For example, in thegeneric_cppbranch where I've made the change the declaration ofMyBraidAppchanges only slightly:Then all the methods can be written much nicer using the
BraidVectortype (which is typedef'd in this example toMyBraidVector *):The pointer casting then takes place in the
_BraidAppXfunctions automatically. I think this is pretty obviously nicer for the user, since there's never really a situation where they want to usebraid_Vectorin C++, and the pointer casts are probably free.The only other small change this creates though is either:
BraidCoremust have a template type as well:or
2.
BraidCore'sSetSpacialCoarsenAndRefine,SetSyncandSetResidualmethods (which take no arguments) can be changed to boolean optional arguments to theBraidCoreconstructor, so unless you use those methods, no change is needed to your code. This option is rendered in mygeneric_cpp_2branch.I don't know how flexible the API for the C++ interface is, but I hope this change can be considered