本文整理汇总了C++中Epetra_MultiVector::Map方法的典型用法代码示例。如果您正苦于以下问题:C++ Epetra_MultiVector::Map方法的具体用法?C++ Epetra_MultiVector::Map怎么用?C++ Epetra_MultiVector::Map使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Epetra_MultiVector
的用法示例。
在下文中一共展示了Epetra_MultiVector::Map方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
void PeridigmNS::State::copyLocallyOwnedMultiVectorData(Epetra_MultiVector& source, Epetra_MultiVector& target)
{
TEUCHOS_TEST_FOR_EXCEPTION(source.NumVectors() != target.NumVectors(), std::runtime_error,
"PeridigmNS::State::copyLocallyOwnedMultiVectorData() called with incompatible MultiVectors.\n");
int numVectors = target.NumVectors();
const Epetra_BlockMap& sourceMap = source.Map();
const Epetra_BlockMap& targetMap = target.Map();
for(int iVec=0 ; iVec<numVectors ; ++iVec){
Epetra_Vector& sourceVector = *source(iVec);
Epetra_Vector& targetVector = *target(iVec);
for(int targetLID=0 ; targetLID<targetMap.NumMyElements() ; ++targetLID){
int GID = targetMap.GID(targetLID);
int sourceLID = sourceMap.LID(GID);
TEUCHOS_TEST_FOR_EXCEPTION(sourceLID == -1, std::range_error,
"PeridigmNS::State::copyLocallyOwnedMultiVectorData() called with incompatible MultiVectors.\n");
TEUCHOS_TEST_FOR_EXCEPTION(sourceMap.ElementSize(sourceLID) != targetMap.ElementSize(targetLID), std::range_error,
"PeridigmNS::State::copyLocallyOwnedMultiVectorData() called with incompatible MultiVectors.\n");
int elementSize = targetMap.ElementSize(targetLID);
int sourceFirstPointInElement = sourceMap.FirstPointInElement(sourceLID);
int targetFirstPointInElement = targetMap.FirstPointInElement(targetLID);
for(int i=0 ; i<elementSize ; ++i){
targetVector[targetFirstPointInElement+i] = sourceVector[sourceFirstPointInElement+i];
}
}
}
}
示例2: show_matrix
void show_matrix(const char *txt, const Epetra_LinearProblem &problem, const Epetra_Comm &comm)
{
int me = comm.MyPID();
if (comm.NumProc() > 10){
if (me == 0){
std::cout << txt << std::endl;
std::cout << "Printed matrix format only works for 10 or fewer processes" << std::endl;
}
return;
}
Epetra_RowMatrix *matrix = problem.GetMatrix();
Epetra_MultiVector *lhs = problem.GetLHS();
Epetra_MultiVector *rhs = problem.GetRHS();
int numRows = matrix->NumGlobalRows();
int numCols = matrix->NumGlobalCols();
if ((numRows > 200) || (numCols > 500)){
if (me == 0){
std::cerr << txt << std::endl;
std::cerr << "show_matrix: problem is too large to display" << std::endl;
}
return;
}
int *myA = new int [numRows * numCols];
make_my_A(*matrix, myA, comm);
int *myX = new int [numCols];
int *myB = new int [numRows];
memset(myX, 0, sizeof(int) * numCols);
memset(myB, 0, sizeof(int) * numRows);
const Epetra_BlockMap &lhsMap = lhs->Map();
const Epetra_BlockMap &rhsMap = rhs->Map();
int base = lhsMap.IndexBase();
for (int j=0; j < lhsMap.NumMyElements(); j++){
int colGID = lhsMap.GID(j);
myX[colGID - base] = me + 1;
}
for (int i=0; i < rhsMap.NumMyElements(); i++){
int rowGID = rhsMap.GID(i);
myB[rowGID - base] = me + 1;
}
printMatrix(txt, myA, myX, myB, numRows, numCols, comm);
delete [] myA;
delete [] myX;
delete [] myB;
}
示例3: MultiVectorToMatlabFile
int MultiVectorToMatlabFile( const char *filename, const Epetra_MultiVector & A) {
std::FILE * handle = 0;
if (A.Map().Comm().MyPID()==0) { // Only PE 0 does this section
handle = fopen(filename,"w");
if (!handle) return(-1);
}
if (MultiVectorToMatlabHandle(handle, A)) return(-1); // Everybody calls this routine
if (A.Map().Comm().MyPID()==0) // Only PE 0 opened a file
if (fclose(handle)) return(-1);
return(0);
}
示例4: copyThyraIntoEpetra
void EpetraOperatorWrapper::copyThyraIntoEpetra(
const VectorBase<double>& thyraVec, Epetra_MultiVector& x) const
{
using Teuchos::rcpFromRef;
using Teuchos::rcp_dynamic_cast;
const int numVecs = x.NumVectors();
TEUCHOS_TEST_FOR_EXCEPTION(numVecs != 1, std::runtime_error,
"epetraToThyra does not work with MV dimension != 1");
const RCP<const ProductVectorBase<double> > prodThyraVec =
castOrCreateProductVectorBase(rcpFromRef(thyraVec));
const ArrayView<double> epetraData(x[0], x.Map().NumMyElements());
// NOTE: See above!
int offset = 0;
const int numBlocks = prodThyraVec->productSpace()->numBlocks();
for (int b = 0; b < numBlocks; ++b) {
const RCP<const VectorBase<double> > vec_b = prodThyraVec->getVectorBlock(b);
const RCP<const SpmdVectorSpaceBase<double> > spmd_vs_b =
rcp_dynamic_cast<const SpmdVectorSpaceBase<double> >(vec_b->space(), true);
ConstDetachedSpmdVectorView<double> view(vec_b);
const ArrayRCP<const double> thyraData = view.sv().values();
const int localNumElems = spmd_vs_b->localSubDim();
for (int i=0; i < localNumElems; ++i) {
epetraData[i+offset] = thyraData[i];
}
offset += localNumElems;
}
}
示例5: writeMultiVector
int writeMultiVector(FILE * handle, const Epetra_MultiVector & A, bool mmFormat) {
int ierr = 0;
int length = A.GlobalLength();
int numVectors = A.NumVectors();
const Epetra_Comm & comm = A.Map().Comm();
if (comm.MyPID()!=0) {
if (A.MyLength()!=0) ierr = -1;
}
else {
if (length!=A.MyLength()) ierr = -1;
for (int j=0; j<numVectors; j++) {
for (int i=0; i<length; i++) {
double val = A[j][i];
if (mmFormat)
fprintf(handle, "%22.16e\n", val);
else
fprintf(handle, "%22.16e ", val);
}
if (!mmFormat) fprintf(handle, "%s", "\n");
}
}
int ierrGlobal;
comm.MinAll(&ierr, &ierrGlobal, 1); // If any processor has -1, all return -1
return(ierrGlobal);
}
示例6:
EpetraOpMultiVec::EpetraOpMultiVec(const Teuchos::RCP<Epetra_Operator> &Op,
Epetra_DataAccess CV, const Epetra_MultiVector& P_vec, const std::vector<int>& index)
: Epetra_OP( Op )
{
Epetra_MV = Teuchos::rcp( new Epetra_MultiVector(CV, P_vec, &(const_cast<std::vector<int> &>(index))[0], index.size()) );
Epetra_MV_Temp = Teuchos::rcp( new Epetra_MultiVector( P_vec.Map(), index.size()) );
}
示例7: GetBoundaryBulkResiduals
void PhcGeoMGPrec::GetBoundaryBulkResiduals (const Epetra_CrsMatrix & op,
const Epetra_MultiVector & x,
const Epetra_MultiVector & b,
double & bndryRes,
double & bulkRes,
double & totalRes,
int level) const {
Epetra_MultiVector work(x);
op.Apply(x, work);
work.Update(-1., b, 1.);
bndryRes=0.; bulkRes=0.; totalRes=0.;
int numInds = x.Map().getNodeNumElements();
double * vals = work[0];
for (int i=0; i<numInds; i++) {
double val = vals[i];
double afrac = (*dmAreas_[level])[i];
if ((afrac==0.) || (afrac==1.))
bulkRes += val*val;
else {
//std::cout << "afrac: " << afrac << std::endl;
bndryRes += val*val;
}
totalRes += val*val;
}
bulkRes = sqrt(bulkRes);
bndryRes = sqrt(bndryRes);
totalRes = sqrt(totalRes);
}
示例8: BasisAngle
double BasisAngle( const Epetra_MultiVector& S, const Epetra_MultiVector& T )
{
//
// Computes the largest acute angle between the two orthogonal basis
//
if (S.NumVectors() != T.NumVectors()) {
return acos( 0.0 );
} else {
int lwork, info = 0;
int m = S.NumVectors(), n = T.NumVectors();
int num_vecs = ( m < n ? m : n );
double U[ 1 ], Vt[ 1 ];
lwork = 3*m*n;
std::vector<double> work( lwork );
std::vector<double> theta( num_vecs );
Epetra_LAPACK lapack;
Epetra_LocalMap localMap( S.NumVectors(), 0, S.Map().Comm() );
Epetra_MultiVector Pvec( localMap, T.NumVectors() );
info = Pvec.Multiply( 'T', 'N', 1.0, S, T, 0.0 );
//
// Perform SVD on S^T*T
//
lapack.GESVD( 'N', 'N', num_vecs, num_vecs, Pvec.Values(), Pvec.Stride(),
&theta[0], U, 1, Vt, 1, &work[0], &lwork, &info );
assert( info == 0 );
return (acos( theta[num_vecs-1] ) );
}
//
// Default return statement, should never be executed.
//
return acos( 0.0 );
}
示例9: A_times_LHS
//==============================================================================
// This preconditioner can be much slower than AztecOO and ML versions
// if the matrix-vector product requires all ExtractMyRowCopy()
// (as done through Ifpack_AdditiveSchwarz).
int Ifpack_PointRelaxation::
ApplyInverseJacobi(const Epetra_MultiVector& RHS, Epetra_MultiVector& LHS) const
{
int NumVectors = LHS.NumVectors();
Epetra_MultiVector A_times_LHS( LHS.Map(),NumVectors );
for (int j = 0; j < NumSweeps_ ; j++) {
IFPACK_CHK_ERR(Apply(LHS,A_times_LHS));
IFPACK_CHK_ERR(A_times_LHS.Update(1.0,RHS,-1.0));
for (int v = 0 ; v < NumVectors ; ++v)
IFPACK_CHK_ERR(LHS(v)->Multiply(DampingFactor_, *(A_times_LHS(v)),
*Diagonal_, 1.0));
}
// Flops:
// - matrix vector (2 * NumGlobalNonzeros_)
// - update (2 * NumGlobalRows_)
// - Multiply:
// - DampingFactor (NumGlobalRows_)
// - Diagonal (NumGlobalRows_)
// - A + B (NumGlobalRows_)
// - 1.0 (NumGlobalRows_)
ApplyInverseFlops_ += NumVectors * (6 * NumGlobalRows_ + 2 * NumGlobalNonzeros_);
return(0);
}
示例10: Resid
// ================================================ ====== ==== ==== == =
//! Implicitly applies in the inverse in an 1-2-1 format
int ML_Epetra::RefMaxwellPreconditioner::ApplyInverse_Implicit_121(const Epetra_MultiVector& B, Epetra_MultiVector& X) const
{
#ifdef ML_TIMING
double t_time,t_diff;
StartTimer(&t_time);
#endif
int NumVectors=B.NumVectors();
Epetra_MultiVector TempE1(X.Map(),NumVectors,false);
Epetra_MultiVector TempE2(X.Map(),NumVectors,true);
Epetra_MultiVector TempN1(*NodeMap_,NumVectors,false);
Epetra_MultiVector TempN2(*NodeMap_,NumVectors,true);
Epetra_MultiVector Resid(B);
/* Pre-Smoothing */
ML_CHK_ERR(PreEdgeSmoother->ApplyInverse(B,X));
/* Precondition (1,1) Block */
ML_CHK_ERR(EdgePC->ApplyInverse(Resid,TempE2));
ML_CHK_ERR(X.Update(1.0,TempE2,1.0));;
/* Build Residual */
ML_CHK_ERR(SM_Matrix_->Multiply(false,X,TempE1));
ML_CHK_ERR(Resid.Update(-1.0,TempE1,1.0,B,0.0));
if(!HasOnlyDirichletNodes){
ML_CHK_ERR(D0_Matrix_->Multiply(true,Resid,TempN1));
}
/* Precondition (2,2) Block */
if(!HasOnlyDirichletNodes){
ML_CHK_ERR(NodePC->ApplyInverse(TempN1,TempN2));
D0_Matrix_->Multiply(false,TempN2,TempE1);
}/*end if*/
if(!HasOnlyDirichletNodes) X.Update(1.0,TempE1,1.0);
/* Build Residual */
ML_CHK_ERR(SM_Matrix_->Multiply(false,X,TempE1));
ML_CHK_ERR(Resid.Update(-1.0,TempE1,1.0,B,0.0));
/* Precondition (1,1) Block */
TempE2.PutScalar(0.0);
ML_CHK_ERR(EdgePC->ApplyInverse(Resid,TempE2));
ML_CHK_ERR(X.Update(1.0,TempE2,1.0));;
/* Post-Smoothing */
ML_CHK_ERR(PostEdgeSmoother->ApplyInverse(B,X));
#ifdef ML_TIMING
StopTimer(&t_time,&t_diff);
/* Output */
ML_Comm *comm_;
ML_Comm_Create(&comm_);
this->ApplicationTime_+= t_diff;
ML_Comm_Destroy(&comm_);
#endif
return 0;
}
示例11: 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;
}
示例12: 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
}
示例13: Xtilde
//==============================================================================
int Ifpack_ReorderFilter::
Multiply(bool TransA, const Epetra_MultiVector& X,
Epetra_MultiVector& Y) const
{
// need two additional vectors
Epetra_MultiVector Xtilde(X.Map(),X.NumVectors());
Epetra_MultiVector Ytilde(Y.Map(),Y.NumVectors());
// bring X back to original ordering
Reordering_->Pinv(X,Xtilde);
// apply original matrix
IFPACK_CHK_ERR(Matrix()->Multiply(TransA,Xtilde,Ytilde));
// now reorder result
Reordering_->P(Ytilde,Y);
return(0);
}
示例14: head
void
Albany::STKDiscretization::getSolutionFieldHistory(Epetra_MultiVector &result) const
{
TEUCHOS_TEST_FOR_EXCEPT(!this->map->SameAs(result.Map()));
const int stepCount = std::min(this->getSolutionFieldHistoryDepth(), result.NumVectors());
Epetra_MultiVector head(View, result, 0, stepCount);
this->getSolutionFieldHistoryImpl(head);
}
示例15: X
// ================================================ ====== ==== ==== == =
// Apply the preconditioner to an Epetra_MultiVector X, puts the result in Y
int ML_Epetra::RefMaxwellPreconditioner::ApplyInverse(const Epetra_MultiVector& B, Epetra_MultiVector& X_) const
{
int rv;
/* Sanity Checks */
if (!B.Map().SameAs(*DomainMap_)) ML_CHK_ERR(-1);
if (B.NumVectors() != X_.NumVectors()) ML_CHK_ERR(-1);
/* Check for zero RHS */
bool norm0=true;
double *norm=new double[B.NumVectors()];
B.Norm2(norm);
for(int i=0;norm0==true && i<B.NumVectors();i++) norm0=norm0 && (norm[i]==0);
delete [] norm;
if(norm0) return 0;
/* Build new work vector X */
Epetra_MultiVector X(X_.Map(),X_.NumVectors());
X.PutScalar(0);
/* What mode to run in? */
if(mode=="212") rv=ApplyInverse_Implicit_212(B,X);
else if(mode=="additive") rv=ApplyInverse_Implicit_Additive(B,X);
else if(mode=="121") rv=ApplyInverse_Implicit_121(B,X);
else {fprintf(stderr,"%s","RefMaxwellPreconditioner ERROR: Invalid ApplyInverse mode set in Teuchos list");ML_CHK_ERR(-2);}
ML_CHK_ERR(rv);
/* Copy work vector to output */
X_=X;
/* Timer Stuff */
#ifdef ML_TIMING
ML_Epetra::RefMaxwellPreconditioner* This = const_cast<ML_Epetra::RefMaxwellPreconditioner *>(this);
if(FirstApplication_){
This->FirstApplication_=false;
This->FirstApplicationTime_=ApplicationTime_;
}/*end if*/
This->NumApplications_++;
#endif
return 0;
}/*end ApplyInverse*/