[Trilinos-Users] [EXTERNAL] How to create a new operator from Belos:Operator

Wu, Hui wu40 at llnl.gov
Thu Mar 29 13:20:10 EDT 2018


Hi Heidi,


Thank you for the prompt help. Yes I am using Epetra_MultiVector as MV and the created operator (which is a subclass of Belos::Operator) as OP. The following is the Apply function:


void Apply(const Belos::MultiVec<ScalarType>& X, Belos::MultiVec<ScalarType>& Y, Belos::ETrans trans = Belos::NOTRANS) const

{

    const Epetra_Vector* myX;
    Epetra_Vector* myY;

    myX = dynamic_cast<const Epetra_Vector*>(&X);
    myY = dynamic_cast<Epetra_Vector*>(&Y);
    ......

    ......

    (*myY)[i] = temp1; //temp1 is calculated

}


The reason that I use Epetra_MultiVector is that I need to access the element in rhs vector (to assign value) and solution vector (to perform Ax), but it seems that the Belos::MultiVec do not provide the access to its element (I can only use the operatorTraits to perform some actions on Belos::MultiVec but that's not what I need. Maybe I missed something.).  I am trying to use Belos::EpetraMultiVec now and hope that will work.


Thank you very much.


Hui

________________________________
From: Thornquist, Heidi K <hkthorn at sandia.gov>
Sent: Thursday, March 29, 2018 9:53:18 AM
To: Wu, Hui; trilinos-users at trilinos.org
Subject: Re: [EXTERNAL] [Trilinos-Users] How to create a new operator from Belos:Operator


Hi Hui,



It looks like there is an issue with how the templates are being instantiated in the code that creates the Belos solver.  An example of how you can interact with the Belos CG solvers, given a specialized operator, is in:



Trilinos/packages/belos/test/BlockCG/test_bl_cg_complex_hb.cpp



>From the error, I see that the instantiation of the linear problem object is being done with a mixed template, where the multi-vector is an Epetra_MultiVector and the operator is a Belos::Operator<double>.

The multi-vector and operator template need to be compatible, so either they are both Epetra objects or they are both Belos::MultiVec<double>/Belos::Operator<double> objects.



Is your specialized operator written to apply to Epetra_MultiVector objects?  If so, then the Belos::EpetraMultiVec class is written to inherit from both the Epetra_MultiVector and the Belos::MultiVec<double> classes.

That would be your best path forward.



Let me know if you have any other questions.



Thanks,

Heidi



--



Heidi K. Thornquist

Electrical Models & Simulation

Sandia National Laboratories









From: Trilinos-Users <trilinos-users-bounces at trilinos.org> on behalf of "Wu, Hui" <wu40 at llnl.gov>
Date: Thursday, March 29, 2018 at 10:39 AM
To: "trilinos-users at trilinos.org" <trilinos-users at trilinos.org>
Subject: [EXTERNAL] [Trilinos-Users] How to create a new operator from Belos:Operator



I am trying to solve a problem Ax = b using Belos::BlockCGSolMgr where A is a dense matrix and I don't want to calculate and store A. Therefore I cannot use Epetra_Operator as OP in Belos::LinearProblem<ScalarType, MV, OP>. I need to create a new operator to do Ax. I considered the example mentioned here: https://github.com/trilinos/Trilinos/blob/master/packages/belos/test/MVOPTester/MyBetterOperator.hpp



In the new operator, I write a function Apply to do Ax.



However, the following compiling error shows up:



BelosOperatorTraits.hpp(71): error: class "Belos::Operator<double>" has no member "this_type_is_missing_a_specialization"

        OP::this_type_is_missing_a_specialization();

            ^

          detected during:

            instantiation of "void Belos::UndefinedOperatorTraits<ScalarType, MV, OP>::notDefined() [with ScalarType=double, MV=Epetra_MultiVector, OP=Belos::Operator<double>]" at line 131

            instantiation of "void Belos::OperatorTraits<ScalarType, MV, OP>::Apply(const OP &, const MV &, MV &, Belos::ETrans) [with ScalarType=double, MV=Epetra_MultiVector, OP=Belos::Operator<double>]" at line 1130 of "BelosLinearProblem.hpp"

            instantiation of "void Belos::LinearProblem<ScalarType, MV, OP>::computeCurrResVec(MV *, const MV *, const MV *) const [with ScalarType=double, MV=Epetra_MultiVector, OP=Belos::Operator<double>]" at line 867 of "BelosLinearProblem.hpp"

            instantiation of "bool Belos::LinearProblem<ScalarType, MV, OP>::setProblem(const Teuchos::RCP<MV> &, const Teuchos::RCP<const MV> &) [with ScalarType=double, MV=Epetra_MultiVector, OP=Belos::Operator<double>]"




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://trilinos.org/pipermail/trilinos-users/attachments/20180329/16780abf/attachment.html>


More information about the Trilinos-Users mailing list