本文整理汇总了C++中Epetra_MultiVector::PutScalar方法的典型用法代码示例。如果您正苦于以下问题:C++ Epetra_MultiVector::PutScalar方法的具体用法?C++ Epetra_MultiVector::PutScalar怎么用?C++ Epetra_MultiVector::PutScalar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Epetra_MultiVector
的用法示例。
在下文中一共展示了Epetra_MultiVector::PutScalar方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: operator
void Iterative_Inverse_Operator::operator () (const Epetra_MultiVector &b, Epetra_MultiVector &x)
{
// Initialize the solution to zero
x.PutScalar( 0.0 );
// Reset the solver, problem, and status test for next solve (HKT)
pProb->setProblem( Teuchos::rcp(&x, false), Teuchos::rcp(&b, false) );
timer.start();
Belos::ReturnType ret = pBelos->solve();
timer.stop();
int pid = pComm->MyPID();
if (pid == 0 && print) {
if (ret == Belos::Converged)
{
std::cout << std::endl << "pid[" << pid << "] Block GMRES converged" << std::endl;
std::cout << "Solution time: " << timer.totalElapsedTime() << std::endl;
}
else
std::cout << std::endl << "pid[" << pid << "] Block GMRES did not converge" << std::endl;
}
}
示例2:
void
Stokhos::EpetraMultiVectorOrthogPoly::
computeStandardDeviation(Epetra_MultiVector& v) const
{
const Teuchos::Array<double>& nrm2 = this->basis_->norm_squared();
v.PutScalar(0.0);
for (int i=1; i<this->size(); i++)
v.Multiply(nrm2[i], *coeff_[i], *coeff_[i], 1.0);
for (int j=0; j<v.NumVectors(); j++)
for (int i=0; i<v.MyLength(); i++)
v[j][i] = std::sqrt(v[j][i]);
}
示例3: ApplyInverse
//=========================================================================
// Returns the result of a Epetra_Operator inverse applied to an Epetra_MultiVector X in Y.
int EpetraExt_PointToBlockDiagPermute::ApplyInverse(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const{
// Stuff borrowed from Epetra_CrsMatrix
int NumVectors = X.NumVectors();
if (NumVectors!=Y.NumVectors()) {
EPETRA_CHK_ERR(-2); // Need same number of vectors in each MV
}
const Epetra_MultiVector *Xp=&X;
Epetra_MultiVector *Yp=&Y;
// Allocate temp workspace if X==Y and there are no imports or exports
Epetra_MultiVector * Xcopy = 0;
if (&X==&Y && Importer_==0 && Exporter_==0) {
Xcopy = new Epetra_MultiVector(X);
Xp=Xcopy;
}
UpdateImportVector(NumVectors); // Make sure Import and Export Vectors are compatible
UpdateExportVector(NumVectors);
// If we have a non-trivial importer, we must import elements that are permuted or are on other processors
if (Importer_){
EPETRA_CHK_ERR(ImportVector_->Import(X, *Importer_, Insert));
Xp=ImportVector_;
}
// If we have a non-trivial exporter, we must export elements that are permuted or belong to other processors
if (Exporter_) {
Yp=ExportVector_;
}
// Do the matvec
BDMat_->ApplyInverse(*Xp,*Yp);
// Export if needed
if (Exporter_) {
Y.PutScalar(0.0); // Make sure target is zero
Y.Export(*ExportVector_, *Exporter_, Add); // Fill Y with Values from export vector
}
// Cleanup
if(Xcopy) {
delete Xcopy;
EPETRA_CHK_ERR(1); // Return positive code to alert the user about needing extra copy of X
return 1;
}
return 0;
}
示例4: Apply
int EpetraSamplingOperator::Apply(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
{
TEUCHOS_ASSERT(map_.PointSameAs(X.Map()) && map_.PointSameAs(Y.Map()));
TEUCHOS_ASSERT(X.NumVectors() == Y.NumVectors());
Y.PutScalar(0.0);
for (int iVec = 0; iVec < X.NumVectors(); ++iVec) {
const ArrayView<const double> sourceVec(X[iVec], X.MyLength());
const ArrayView<double> targetVec(Y[iVec], Y.MyLength());
for (Array<GlobalIndex>::const_iterator it = sampleLIDs_.begin(), it_end = sampleLIDs_.end(); it != it_end; ++it) {
targetVec[*it] = sourceVec[*it];
}
}
return 0;
}
示例5: logic_error
int
AmesosGenOp::Apply (const Epetra_MultiVector& X, Epetra_MultiVector& Y) const
{
if (problem_ == NULL) {
throw std::logic_error ("AmesosGenOp::Apply: problem_ is NULL");
}
if (massMtx_.is_null ()) {
throw std::logic_error ("AmesosGenOp::Apply: massMtx_ is null");
}
if (solver_.is_null ()) {
throw std::logic_error ("AmesosGenOp::Apply: solver_ is null");
}
if (! useTranspose_) {
// Storage for M*X
Epetra_MultiVector MX (X.Map (), X.NumVectors ());
// Apply M*X
massMtx_->Apply (X, MX);
Y.PutScalar (0.0);
// Set the LHS and RHS
problem_->SetRHS (&MX);
problem_->SetLHS (&Y);
// Solve the linear system A*Y = MX
solver_->Solve ();
}
else { // apply the transposed operator
// Storage for A^{-T}*X
Epetra_MultiVector ATX (X.Map (), X.NumVectors ());
Epetra_MultiVector tmpX = const_cast<Epetra_MultiVector&> (X);
// Set the LHS and RHS
problem_->SetRHS (&tmpX);
problem_->SetLHS (&ATX);
// Solve the linear system A^T*Y = X
solver_->Solve ();
// Apply M*ATX
massMtx_->Apply (ATX, Y);
}
return 0; // the method completed correctly
}
示例6:
Teuchos::RCP<Epetra_LinearProblem> build_problem_mm(Teuchos::ParameterList& test_params, Epetra_CrsMatrix* A, Epetra_MultiVector* b)
{
const Epetra_Map& rowmap = A->RowMap();
Epetra_MultiVector* x = new Epetra_MultiVector(rowmap, 1);
if (b == NULL) {
std::cout << "creating b = A*random" << std::endl;
b = new Epetra_MultiVector(rowmap, 1);
x->Random();
A->Apply(*x, *b);
}
x->PutScalar(0);
Teuchos::RCP<Epetra_LinearProblem> problem = Teuchos::rcp(new Epetra_LinearProblem(A,x,b));
return problem;
}
示例7: Apply
int AmesosBucklingOp::Apply(const Epetra_MultiVector& X, Epetra_MultiVector& Y ) const
{
// Storage for A*X
Epetra_MultiVector AX(X.Map(),X.NumVectors());
// Apply A*X
stiffMtx_->Apply(X, AX);
Y.PutScalar(0.0);
// Set the LHS and RHS
problem_->SetRHS(&AX);
problem_->SetLHS(&Y);
// Solve the linear system (A-sigma*M)*Y = AX
solver_->Solve();
return 0;
}
示例8: Xcopy
//==============================================================================
int Ifpack_Polynomial::
ApplyInverse(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const
{
if (!IsComputed())
IFPACK_CHK_ERR(-3);
if (PolyDegree_ == 0)
return 0;
int nVec = X.NumVectors();
if (nVec != Y.NumVectors())
IFPACK_CHK_ERR(-2);
Time_->ResetStartTime();
Epetra_MultiVector Xcopy(X);
if(ZeroStartingSolution_==true) {
Y.PutScalar(0.0);
}
// mfh 20 Mar 2014: IBD never gets used, so I'm commenting out the
// following lines of code in order to forestall build warnings.
// #ifdef HAVE_IFPACK_EPETRAEXT
// EpetraExt_PointToBlockDiagPermute* IBD=0;
// if (UseBlockMode_) IBD=&*InvBlockDiagonal_;
// #endif
Y.Update(-coeff_[1], Xcopy, 1.0);
for (int ii = 2; ii < static_cast<int> (coeff_.size ()); ++ii) {
const Epetra_MultiVector V(Xcopy);
Operator_->Apply(V,Xcopy);
Xcopy.Multiply(1.0, *InvDiagonal_, Xcopy, 0.0);
// Update Y
Y.Update(-coeff_[ii], Xcopy, 1.0);
}
// Flops are updated in each of the following.
++NumApplyInverse_;
ApplyInverseTime_ += Time_->ElapsedTime();
return(0);
}
示例9: switch
//==============================================================================
// Note that Ifpack_PointRelaxation and Jacobi is much faster than
// Ifpack_AdditiveSchwarz<Ifpack_PointRelaxation> (because of the
// way the matrix-vector produce is performed).
//
// Another ML-related observation is that the starting solution (in Y)
// is NOT supposed to be zero. This may slow down the application of just
// one sweep of Jacobi.
//
int Ifpack_PointRelaxation::
ApplyInverse(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const
{
if (!IsComputed())
IFPACK_CHK_ERR(-3);
if (X.NumVectors() != Y.NumVectors())
IFPACK_CHK_ERR(-2);
Time_->ResetStartTime();
// AztecOO gives X and Y pointing to the same memory location,
// need to create an auxiliary vector, Xcopy
Teuchos::RefCountPtr< const Epetra_MultiVector > Xcopy;
if (X.Pointers()[0] == Y.Pointers()[0])
Xcopy = Teuchos::rcp( new Epetra_MultiVector(X) );
else
Xcopy = Teuchos::rcp( &X, false );
if (ZeroStartingSolution_)
Y.PutScalar(0.0);
// Flops are updated in each of the following.
switch (PrecType_) {
case IFPACK_JACOBI:
IFPACK_CHK_ERR(ApplyInverseJacobi(*Xcopy,Y));
break;
case IFPACK_GS:
IFPACK_CHK_ERR(ApplyInverseGS(*Xcopy,Y));
break;
case IFPACK_SGS:
IFPACK_CHK_ERR(ApplyInverseSGS(*Xcopy,Y));
break;
default:
IFPACK_CHK_ERR(-1); // something wrong
}
++NumApplyInverse_;
ApplyInverseTime_ += Time_->ElapsedTime();
return(0);
}
示例10: if
//==============================================================================
int Ifpack_PointRelaxation::
ApplyInverseSGS(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const
{
if (ZeroStartingSolution_)
Y.PutScalar(0.0);
const Epetra_CrsMatrix* CrsMatrix = dynamic_cast<const Epetra_CrsMatrix*>(&*Matrix_);
// try to pick the best option; performances may be improved
// if several sweeps are used.
if (CrsMatrix != 0)
{
if (CrsMatrix->StorageOptimized() && LocalSmoothingIndices_)
return(ApplyInverseSGS_LocalFastCrsMatrix(CrsMatrix, X, Y));
else if (CrsMatrix->StorageOptimized())
return(ApplyInverseSGS_FastCrsMatrix(CrsMatrix, X, Y));
else
return(ApplyInverseSGS_CrsMatrix(CrsMatrix, X, Y));
}
else
return(ApplyInverseSGS_RowMatrix(X, Y));
}
示例11: sg_input
int
Stokhos::ProductEpetraOperator::
Apply(const Epetra_MultiVector& Input, Epetra_MultiVector& Result) const
{
if (useTranspose) {
EpetraExt::BlockMultiVector sg_input(View, *range_base_map, Input);
Epetra_MultiVector tmp(Result.Map(), Result.NumVectors());
Result.PutScalar(0.0);
for (int i=0; i<coeff_.size(); i++) {
coeff_[i]->Apply(*(sg_input.GetBlock(i)), tmp);
Result.Update(1.0, tmp, 1.0);
}
}
else {
EpetraExt::BlockMultiVector sg_result(View, *range_base_map, Result);
for (int i=0; i<coeff_.size(); i++)
coeff_[i]->Apply(Input, *(sg_result.GetBlock(i)));
}
return 0;
}
示例12: Indices
//==============================================================================
int Ifpack_DropFilter::
Multiply(bool TransA, const Epetra_MultiVector& X,
Epetra_MultiVector& Y) const
{
// NOTE: I suppose that the matrix has been localized,
// hence all maps are trivial.
int NumVectors = X.NumVectors();
if (NumVectors != Y.NumVectors())
IFPACK_CHK_ERR(-1);
Y.PutScalar(0.0);
vector<int> Indices(MaxNumEntries_);
vector<double> Values(MaxNumEntries_);
for (int i = 0 ; i < NumRows_ ; ++i) {
int Nnz;
ExtractMyRowCopy(i,MaxNumEntries_,Nnz,
&Values[0], &Indices[0]);
if (!TransA) {
// no transpose first
for (int j = 0 ; j < NumVectors ; ++j) {
for (int k = 0 ; k < Nnz ; ++k) {
Y[j][i] += Values[k] * X[j][Indices[k]];
}
}
}
else {
// transpose here
for (int j = 0 ; j < NumVectors ; ++j) {
for (int k = 0 ; k < Nnz ; ++k) {
Y[j][Indices[k]] += Values[k] * X[j][i];
}
}
}
}
return(0);
}
示例13: SetLHS
//==============================================================================
int Ifpack_Krylov::
ApplyInverse(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const
{
if (!IsComputed())
IFPACK_CHK_ERR(-3);
if (Iterations_ == 0)
return 0;
int nVec = X.NumVectors();
if (nVec != Y.NumVectors())
IFPACK_CHK_ERR(-2);
Time_->ResetStartTime();
// AztecOO gives X and Y pointing to the same memory location,
// need to create an auxiliary vector, Xcopy
Teuchos::RCP<Epetra_MultiVector> Xcopy = Teuchos::rcp( new Epetra_MultiVector(X) );
if(ZeroStartingSolution_==true) {
Y.PutScalar(0.0);
}
#ifdef HAVE_IFPACK_AZTECOO
AztecSolver_ -> SetLHS(&Y);
AztecSolver_ -> SetRHS(&*Xcopy);
AztecSolver_ -> Iterate(Iterations_,Tolerance_);
#else
cout << "You need to configure IFPACK with support for AztecOO" << endl;
cout << "to use this preconditioner. This may require --enable-aztecoo" << endl;
cout << "in your configure script." << endl;
IFPACK_CHK_ERR(-1);
#endif
// Flops are updated in each of the following.
++NumApplyInverse_;
ApplyInverseTime_ += Time_->ElapsedTime();
return(0);
}
示例14: Indices
//==============================================================================
int Ifpack_SparsityFilter::
Multiply(bool TransA, const Epetra_MultiVector& X,
Epetra_MultiVector& Y) const
{
int NumVectors = X.NumVectors();
if (NumVectors != Y.NumVectors())
IFPACK_CHK_ERR(-1);
Y.PutScalar(0.0);
std::vector<int> Indices(MaxNumEntries_);
std::vector<double> Values(MaxNumEntries_);
for (int i = 0 ; i < A_->NumMyRows() ; ++i) {
int Nnz;
ExtractMyRowCopy(i,MaxNumEntries_,Nnz,
&Values[0], &Indices[0]);
if (!TransA) {
// no transpose first
for (int j = 0 ; j < NumVectors ; ++j) {
for (int k = 0 ; k < Nnz ; ++k) {
Y[j][i] += Values[k] * X[j][Indices[k]];
}
}
}
else {
// transpose here
for (int j = 0 ; j < NumVectors ; ++j) {
for (int k = 0 ; k < Nnz ; ++k) {
Y[j][Indices[k]] += Values[k] * X[j][i];
}
}
}
}
return(0);
}
示例15: Multiply
virtual int Multiply(bool TransA, const Epetra_MultiVector& X,
Epetra_MultiVector& Y) const
{
Epetra_MultiVector Xtmp(RowMatrixColMap(), X.NumVectors());
Xtmp.Import(X, *RowMatrixImporter(), Insert);
std::vector<int> Indices(MaxNumEntries());
std::vector<double> Values(MaxNumEntries());
Y.PutScalar(0.0);
for (int i = 0 ; i < NumMyRows() ; ++i)
{
int NumEntries;
// use the inlined function
getrow(i, MaxNumEntries(), NumEntries, &Values[0], &Indices[0]);
for (int j = 0 ; j < NumEntries ; ++j)
for (int k = 0 ; k < Y.NumVectors() ; ++k)
Y[k][i] += Values[j] * Xtmp[k][Indices[j]];
}
return(0);
}