Thyra Tpetra Adapters: TpetraVectorSpace to override smallVecSpcFcty()
Created by: bartgol
@trilinos/thyra
Expectations
The method smallVecSpcFcty()
should return a factory that creates a vector space of TpetraVectorSpace type.
Current Behavior
The class TpetraVectorSpace
does not override this method, relying on the implementation of the mother class SpmdVectorSpaceDefaultBase
.
Motivation and Context
The current implementation is ok as long as one only works at the level of Thyra interfaces. The implementation in SpmdVectorSpaceDefaultBase
returns a default factory which creates a default locally replicated vector space, which is fine at the thyra level. However, things get tricky when diving in the adapters world, inside an external application. Most likely, deep down the stack, the customer application casts most of the thyra objects to a concrete implementation. In case of Tpetra adapters, the app will cast, say, a Thyra::VectorBase
to a Thyra::TpetraVector
, then extract the Tpetra vector and do stuff with it. This would be a problem in case the vector was generated by the vector space generated by Thyra::TpetraVectorSpace::smallVecSpcFcty()
, which is not a Thyra::TpetraVectorSpace
.
Possible Solution
This is what I would do:
- create a
TpetraVectorSpaceFactory
which creates a locally replicatedTpetra::Map
, which then wraps in aTpetraVectorSpace
. - in
TpetraVectorSpace
, override thesmallVecSpcFcty()
method, to return aTpetraVectorSpaceFactory
.
Additional Information
Note: this could (in principle) break existing code, since the TpetraVectorSpaceFactory
would create a TpetraVectorSpace
, which would then create objects of type TpetraVector
, which inherit from SpmdVectorDefaultBase
. The current smallVecSpcFcty()
in TpetraVectorSpace
(which is implemented in SpmdVectorDefaultBase
) creates spaces of DefaultSpmdVectorSpace
type, which then create DefaultSpmdVector
, which is a sibling (but not parent) to TpetraVector
(as they both inherit from DefaultSpmdVector
).
This code break would not be related to the proposed modification, per se. It is a consequence of a (imho) current design problem: SpmdVectorSpaceDefaultBase
creates a DefaultSpmdVectorSpaceFactory
which then creates vector spaces that are not of type SpmdVectorSpaceDefaultBase
, but are instead of derived type DefaultSpmdVectorSpace
. In my opinion, it would be more correct if the vector space factory returned by SpmdVectorSpaceDefaultBase
was of type, say, SpmdVectorSpaceDefaultBaseFactory
(this doesn't exist, I'm making the name up), which would create vector spaces of the abstract type SpmdVectorSpaceDefaultBase
, rather than of the derived type DefaultSpmdVectorSpace
. The latter, by the way, is more than welcome to override this.
In short: I think a vector space of type X should create a vs factory that creates vector spaces of type X. This ensures that the small spaces created by the factory created by vs X are fully compatible with the domain spaces of multivectors created by vs X.
Sorry for the super long issue. Thanks for enduring the long read!