本文整理汇总了C++中Epetra_Vector::Scale方法的典型用法代码示例。如果您正苦于以下问题:C++ Epetra_Vector::Scale方法的具体用法?C++ Epetra_Vector::Scale怎么用?C++ Epetra_Vector::Scale使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Epetra_Vector
的用法示例。
在下文中一共展示了Epetra_Vector::Scale方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: power_method
int power_method(bool TransA, Epetra_RowMatrix& A, Epetra_Vector& q, Epetra_Vector& z0,
Epetra_Vector& resid, double* lambda, int niters, double tolerance, bool verbose)
{
// Fill z with random Numbers
Epetra_Vector z(z0);
// variable needed for iteration
double normz, residual;
int ierr = 1;
for(int iter = 0; iter < niters; iter++) {
z.Norm2(&normz); // Compute 2-norm of z
q.Scale(1.0/normz, z);
A.Multiply(TransA, q, z); // Compute z = A*q // SEGFAULT HAPPENS HERE
q.Dot(z, lambda); // Approximate maximum eigenvaluE
if(iter%100==0 || iter+1==niters) {
resid.Update(1.0, z, -(*lambda), q, 0.0); // Compute A*q - lambda*q
resid.Norm2(&residual);
if(verbose) cout << "Iter = " << iter << " Lambda = " << *lambda
<< " Residual of A*q - lambda*q = " << residual << endl;
}
if(residual < tolerance) {
ierr = 0;
break;
}
}
return(ierr);
}
示例2: function
/*----------------------------------------------------------------------*
| evaluate nonlinear function (public, derived) m.gee 3/06|
*----------------------------------------------------------------------*/
bool NLNML::NLNML_CoarseLevelNoxInterface::computeF(
const Epetra_Vector& x, Epetra_Vector& F,
const FillType fillFlag)
{
bool err;
if (!Level())
{
err = fineinterface_->computeF(x,F,fillFlag);
if (err==false)
{
cout << "**ERR**: NLNML::NLNML_CoarseLevelNoxInterface::computeF:\n"
<< "**ERR**: call to fine-userinterface returned false on level " << level_ << "\n"
<< "**ERR**: file/line: " << __FILE__ << "/" << __LINE__ << "\n"; throw -1;
}
}
else
{
RefCountPtr<Epetra_Vector> Ffine = rcp(new Epetra_Vector(fineinterface_->getGraph()->RowMap(),false));
RefCountPtr<Epetra_Vector> xfine = rcp(prolong_this_to_fine(x));
err = fineinterface_->computeF(*xfine,*Ffine,fillFlag);
if (err==false)
{
cout << "**ERR**: NLNML::NLNML_CoarseLevelNoxInterface::computeF:\n"
<< "**ERR**: call to fine-userinterface returned false on level " << level_ << "\n"
<< "**ERR**: file/line: " << __FILE__ << "/" << __LINE__ << "\n"; throw -1;
}
RefCountPtr<Epetra_Vector> Fcoarse = rcp(restrict_fine_to_this(*Ffine));
F.Scale(1.0,*Fcoarse);
}
if (isFAS())
F.Update(-1.0,*fxbar_,1.0,*fbar_,1.0);
return err;
}
示例3: q
int
powerMethod (double & lambda,
Epetra_CrsMatrix& A,
const int niters,
const double tolerance,
const bool verbose)
{
// In the power iteration, z = A*q. Thus, q must be in the domain
// of A, and z must be in the range of A. The residual vector is of
// course in the range of A.
Epetra_Vector q (A.OperatorDomainMap ());
Epetra_Vector z (A.OperatorRangeMap ());
Epetra_Vector resid (A.OperatorRangeMap ());
Epetra_Flops* counter = A.GetFlopCounter();
if (counter != 0) {
q.SetFlopCounter(A);
z.SetFlopCounter(A);
resid.SetFlopCounter(A);
}
// Initialize the starting vector z with random data.
z.Random();
double normz, residual;
int ierr = 1;
for (int iter = 0; iter < niters; ++iter)
{
z.Norm2 (&normz); // normz := ||z||_2
q.Scale (1.0/normz, z); // q := z / normz
A.Multiply(false, q, z); // z := A * q
q.Dot(z, &lambda); // lambda := dot (q, z)
// Compute the residual vector and display status output every
// 100 iterations, or if we have reached the maximum number of
// iterations.
if (iter % 100 == 0 || iter + 1 == niters)
{
resid.Update (1.0, z, -lambda, q, 0.0); // resid := A*q - lambda*q
resid.Norm2 (&residual); // residual := ||resid||_2
if (verbose)
cout << "Iter = " << iter << " Lambda = " << lambda
<< " Residual of A*q - lambda*q = " << residual << endl;
}
if (residual < tolerance) { // We've converged!
ierr = 0;
break;
}
}
return ierr;
}
示例4: constraints
/*----------------------------------------------------------------------*
| make application apply all constraints (public) m.gee 3/06|
*----------------------------------------------------------------------*/
void NLNML::NLNML_CoarseLevelNoxInterface::ApplyAllConstraints(
Epetra_Vector& gradient)
{
if (!Level())
fineinterface_->ApplyAllConstraints(gradient,0);
else
{
RefCountPtr<Epetra_Vector> gradientfine = rcp(prolong_this_to_fine(gradient));
fineinterface_->ApplyAllConstraints(*gradientfine,Level());
RefCountPtr<Epetra_Vector> gradientcoarse = rcp(restrict_fine_to_this(*gradientfine));
gradient.Scale(1.0,*gradientcoarse);
}
return;
}
示例5: DestroyPreconditioner
//.........这里部分代码省略.........
if (verbose_) {
std::cout << PrintMsg_ << "\tAdaptation step " << istep << std::endl;
std::cout << PrintMsg_ << "\t---------------" << std::endl;
}
// ==================== //
// look for "bad" modes //
// ==================== //
// note: should an error occur, ML_CHK_ERR will return,
// and LHS and RHS will *not* be delete'd (--> memory leak).
// Anyway, this means that something wrong happened in the code
// and should be fixed by the user.
LHS->Random();
double Norm2;
for (int i = 0 ; i < MaxSweeps ; ++i) {
// RHS = (I - ML^{-1} A) LHS
ML_CHK_ERR(RowMatrix_->Multiply(false,*LHS,*RHS));
// FIXME: can do something slightly better here
ML_CHK_ERR(ApplyInverse(*RHS,*RHS));
ML_CHK_ERR(LHS->Update(-1.0,*RHS,1.0));
LHS->Norm2(&Norm2);
if (verbose_) {
std::cout << PrintMsg_ << "\titer " << i << ", ||x||_2 = ";
std::cout << Norm2 << std::endl;
}
}
// scaling vectors
double NormInf;
LHS->NormInf(&NormInf);
LHS->Scale(1.0 / NormInf);
// ========================================================= //
// copy tentative and computed null space into NewNullSpace, //
// which now becomes the standard null space //
// ========================================================= //
int NewNullSpaceSize = OldNullSpaceSize + 1;
NewNullSpace = new double[NumMyRows() * NewNullSpaceSize];
assert (NewNullSpace != 0);
int itmp = OldNullSpaceSize * NumMyRows();
for (int i = 0 ; i < itmp ; ++i) {
NewNullSpace[i] = OldNullSpace[i];
}
for (int j = 0 ; j < NumMyRows() ; ++j) {
NewNullSpace[itmp + j] = (*LHS)[j];
}
// =============== //
// visualize modes //
// =============== //
if (List_.get("adaptive: visualize", false)) {
double* x_coord = List_.get("viz: x-coordinates", (double*)0);
double* y_coord = List_.get("viz: y-coordinates", (double*)0);
double* z_coord = List_.get("viz: z-coordinates", (double*)0);
assert (x_coord != 0);
std::vector<double> plot_me(NumMyRows()/NumPDEEqns_);
ML_Aggregate_Viz_Stats info;
info.Amatrix = &(ml_->Amat[LevelID_[0]]);
示例6: normalize
void normalize(Epetra_Vector &v)
{
double norm2[1];
v.Norm2(&norm2[0]);
v.Scale(1.0 / norm2[0]);
}