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 );
}
// ***************************************************************************
void CStringMapper::localSerialString(NLMISC::IStream &f, TStringId &id)
{
	std::string	str;
	if(f.isReading())
	{
		f.serial(str);
		id= localMap(str);
	}
	else
	{
		str= localUnmap(id);
		f.serial(str);
	}
}
Exemple #3
0
void EntityServer::startDynamicDomainVerification() {
    qCDebug(entities) << "Starting Dynamic Domain Verification...";

    QString thisDomainID = DependencyManager::get<AddressManager>()->getDomainID().remove(QRegExp("\\{|\\}"));

    EntityTreePointer tree = std::static_pointer_cast<EntityTree>(_tree);
    QHash<QString, EntityItemID> localMap(tree->getEntityCertificateIDMap());

    QHashIterator<QString, EntityItemID> i(localMap);
    qCDebug(entities) << localMap.size() << "entities in _entityCertificateIDMap";
    while (i.hasNext()) {
        i.next();

        EntityItemPointer entity = tree->findEntityByEntityItemID(i.value());

        if (entity) {
            if (!entity->getProperties().verifyStaticCertificateProperties()) {
                qCDebug(entities) << "During Dynamic Domain Verification, a certified entity with ID" << i.value() << "failed"
                    << "static certificate verification.";
                // Delete the entity if it doesn't pass static certificate verification
                tree->deleteEntity(i.value(), true);
            } else {

                QNetworkAccessManager& networkAccessManager = NetworkAccessManager::getInstance();
                QNetworkRequest networkRequest;
                networkRequest.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
                networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
                QUrl requestURL = NetworkingConstants::METAVERSE_SERVER_URL();
                requestURL.setPath("/api/v1/commerce/proof_of_purchase_status/location");
                QJsonObject request;
                request["certificate_id"] = i.key();
                networkRequest.setUrl(requestURL);

                QNetworkReply* networkReply = NULL;
                networkReply = networkAccessManager.put(networkRequest, QJsonDocument(request).toJson());

                connect(networkReply, &QNetworkReply::finished, [=]() {
                    QJsonObject jsonObject = QJsonDocument::fromJson(networkReply->readAll()).object();
                    jsonObject = jsonObject["data"].toObject();

                    if (networkReply->error() == QNetworkReply::NoError) {
                        if (jsonObject["domain_id"].toString() != thisDomainID) {
                            qCDebug(entities) << "Entity's cert's domain ID" << jsonObject["domain_id"].toString()
                                << "doesn't match the current Domain ID" << thisDomainID << "; deleting entity" << i.value();
                            tree->deleteEntity(i.value(), true);
                        } else {
                            qCDebug(entities) << "Entity passed dynamic domain verification:" << i.value();
                        }
                    } else {
                        qCDebug(entities) << "Call to" << networkReply->url() << "failed with error" << networkReply->error() << "; deleting entity" << i.value()
                            << "More info:" << jsonObject;
                        tree->deleteEntity(i.value(), true);
                    }

                    networkReply->deleteLater();
                });
            }
        } else {
            qCWarning(entities) << "During DDV, an entity with ID" << i.value() << "was NOT found in the Entity Tree!";
        }
    }

    int nextInterval = qrand() % ((_MAXIMUM_DYNAMIC_DOMAIN_VERIFICATION_TIMER_MS + 1) - _MINIMUM_DYNAMIC_DOMAIN_VERIFICATION_TIMER_MS) + _MINIMUM_DYNAMIC_DOMAIN_VERIFICATION_TIMER_MS;
    qCDebug(entities) << "Restarting Dynamic Domain Verification timer for" << nextInterval / 1000 << "seconds";
    _dynamicDomainVerificationTimer.start(nextInterval);
}
  void solvetriadmatrixwithtrilinos(int& nnz, int& order, int* row, 
              int* col, double* val, double* rhs, double* solution) {
#else
  void solvetriadmatrixwithtrilinos_(int& nnz, int& order, int* row, 
              int* col, double* val, double* rhs, double* solution) {
#endif

    try{
    
#ifdef _MPI
    Epetra_MpiComm Comm(MPI_COMM_WORLD);
#else
    Epetra_SerialComm Comm;
#endif
    
    int i, j, ierr;
    int MyPID = Comm.MyPID();
    bool verbose = (MyPID == 0);
    Epetra_Map RowMap(order, 0, Comm);
    int NumMyElements = RowMap.NumMyElements();
    int *MyGlobalElements = new int[NumMyElements];
    RowMap.MyGlobalElements(&MyGlobalElements[0]);

#ifdef _MPI
    int nPEs;
    MPI_Comm_size(MPI_COMM_WORLD, &nPEs);
#endif

    int anEst = nnz / order + 1;
    Epetra_CrsMatrix A(Copy, RowMap, anEst);
    
    for (j=0; j<nnz; ++j) {
      if (RowMap.MyGID(row[j]) ) {
	ierr = A.InsertGlobalValues(row[j], 1, &(val[j]), &(col[j]) );
	assert(ierr >= 0);
      }
    }
    
    ierr = A.FillComplete();
    assert(ierr == 0);
    
    //-------------------------------------------------------------------------
    // RN_20091221: Taking care of the rhs
    //-------------------------------------------------------------------------
    Epetra_Vector b(RowMap);

    // Inserting values into the rhs
    double *MyGlobalValues = new double[NumMyElements];
    for (j=0; j<NumMyElements; ++j) {
      MyGlobalValues[j] = rhs[MyGlobalElements[j] ];
    }
    ierr = b.ReplaceGlobalValues(NumMyElements, &MyGlobalValues[0],
				 &MyGlobalElements[0]);

    //-------------------------------------------------------------------------
    // RN_20091221: Taking care of the solution
    //-------------------------------------------------------------------------
    Epetra_Vector x(RowMap);

    Teuchos::ParameterList paramList;

    Teuchos::RCP<Teuchos::ParameterList>
      paramList1 = Teuchos::rcp(&paramList, false);
    Teuchos::updateParametersFromXmlFile("./strat1.xml", paramList1.get() );

    Teuchos::RCP<Teuchos::FancyOStream>
      out = Teuchos::VerboseObjectBase::getDefaultOStream();

    Stratimikos::DefaultLinearSolverBuilder linearSolverBuilder;

    Teuchos::RCP<Epetra_CrsMatrix> epetraOper = Teuchos::rcp(&A, false);
    Teuchos::RCP<Epetra_Vector> epetraRhs = Teuchos::rcp(&b, false);
    Teuchos::RCP<Epetra_Vector> epetraSol = Teuchos::rcp(&x, false);

    Teuchos::RCP<const Thyra::LinearOpBase<double> >
      thyraOper = Thyra::epetraLinearOp(epetraOper);
    Teuchos::RCP<Thyra::VectorBase<double> >
      thyraRhs = Thyra::create_Vector(epetraRhs, thyraOper->range() );
    Teuchos::RCP<Thyra::VectorBase<double> >
      thyraSol = Thyra::create_Vector(epetraSol, thyraOper->domain() );

    linearSolverBuilder.setParameterList(Teuchos::rcp(&paramList, false) );

    Teuchos::RCP<Thyra::LinearOpWithSolveFactoryBase<double> >
      lowsFactory = linearSolverBuilder.createLinearSolveStrategy("");

    lowsFactory->setOStream(out);
    lowsFactory->setVerbLevel(Teuchos::VERB_LOW);

    Teuchos::RCP<Thyra::LinearOpWithSolveBase<double> >
      lows = Thyra::linearOpWithSolve(*lowsFactory, thyraOper);

    Thyra::SolveStatus<double>
      status = Thyra::solve(*lows, Thyra::NOTRANS, *thyraRhs, &*thyraSol);

    thyraSol = Teuchos::null;

    // For debugging =)
    //    cout << "A: " << A << endl;
    //    cout << "b: " << b << endl;
    //    cout << "x: " << x << endl;

    //    Epetra_Vector temp(RowMap);
    //    double residualNorm;
    //    A.Multiply(false, x, temp);
    //    temp.Update(-1, b, 1);
    //    temp.Norm2(&residualNorm);

    Epetra_LocalMap localMap(order, 0, Comm);
    Epetra_Vector xExtra(localMap); // local vector in each processor

    // RN_20091218: Create an import map and then import the data to the
    // local vector.
    Epetra_Import import(localMap, RowMap);

    xExtra.Import(x, import, Add);
    xExtra.ExtractCopy(solution);

    delete[] MyGlobalElements;
    delete[] MyGlobalValues;
    }
  
    catch (std::exception& e) {
      cout << e.what() << endl;
    }
    catch (string& s) {
      cout << s << endl;
    }
    catch (char *s) {
      cout << s << endl;
    }
    catch (...) {
      cout << "Caught unknown exception!" << endl;
    }
  }

} // extern "C"