// ============================================================================= Epetra_NumPyMultiVector::Epetra_NumPyMultiVector(PyObject * pyObject): Epetra_MultiVector(View, getMap(pyObject), getArray(pyObject), getVectorSize(pyObject), getNumVectors(pyObject)) { // Store the pointer to the Epetra_Map map = tmp_map; tmp_map = NULL; // Store the pointer to the PyArrayObject array = tmp_array; tmp_array = NULL; }
// ============================================================================= Epetra_NumPyMultiVector::Epetra_NumPyMultiVector(const Epetra_BlockMap & blockMap, PyObject * pyObject): Epetra_MultiVector(View, blockMap, getArray(blockMap,pyObject), blockMap.NumMyPoints(), getNumVectors(blockMap,pyObject)) { // Store the array pointer array = tmp_array; tmp_array = NULL; // Copy the Epetra_BlockMap map = new Epetra_BlockMap(blockMap); }
//! Set multi-vector values to random numbers. XPetra implementation virtual void Xpetra_randomize() { typedef Teuchos::ScalarTraits<Scalar> SCT; const size_t numVectors = getNumVectors(); for (size_t i = 0; i < numVectors; i++) { Teuchos::ArrayRCP< Scalar > datai = getDataNonConst(i); const size_t myLength = getLocalLength(); for(size_t j=0; j<myLength; j++) { datai[j] = SCT::random(); } } }
int PViewDataList::getNumElements(int step, int ent) { return getNumScalars() + getNumVectors() + getNumTensors(); }
virtual void evalModelImpl( const Thyra::ModelEvaluatorBase::InArgs<double> &in_args, const Thyra::ModelEvaluatorBase::OutArgs<double> &out_args ) const { const auto & x_in = in_args.get_x(); #ifndef NDEBUG TEUCHOS_ASSERT(!x_in.is_null()); #endif // create corresponding tpetra vector auto x_in_tpetra = Thyra::TpetraOperatorVectorExtraction<double,int,int>::getConstTpetraVector( x_in ); // compute F const auto & f_out = out_args.get_f(); if (!f_out.is_null()) { // Dissect in_args.get_p(0) into parameter sublists. const auto & p_in = in_args.get_p(0); #ifndef NDEBUG TEUCHOS_ASSERT(!p_in.is_null()); // Make sure the parameters aren't NaNs. for (int k = 0; k < p_in->space()->dim(); k++) { TEUCHOS_ASSERT(!std::isnan(Thyra::get_ele(*p_in, k))); } #endif // Fill the parameters into a std::map. const auto param_names = this->get_p_names(0); const double alph = Thyra::get_ele(*p_in, 0); auto f_out_tpetra = Thyra::TpetraOperatorVectorExtraction<double,int,int>::getTpetraVector( f_out ); const auto x_data = x_in_tpetra->getData(); auto f_data = f_out_tpetra->getDataNonConst(); for (size_t i = 0; i < f_data.size(); i++) { f_data[i] = x_data[i] * x_data[i] - alph; } } // Compute df/dp. const auto & derivMv = out_args.get_DfDp(0).getDerivativeMultiVector(); const auto & dfdp_out = derivMv.getMultiVector(); if (!dfdp_out.is_null()) { auto dfdp_out_tpetra = Thyra::TpetraOperatorVectorExtraction<double,int,int>::getTpetraMultiVector( dfdp_out ); TEUCHOS_ASSERT_EQUALITY(dfdp_out_tpetra->getNumVectors(), 1); auto out = dfdp_out_tpetra->getVectorNonConst(0); auto out_data = out->getDataNonConst(); for (size_t k = 0; k < out_data.size(); k++) { out_data[k] = -1.0; } } // Fill Jacobian. const auto & W_out = out_args.get_W_op(); if(!W_out.is_null()) { auto W_outT = Thyra::TpetraOperatorVectorExtraction<double,int,int>::getTpetraOperator( W_out ); const auto & jac = Teuchos::rcp_dynamic_cast<jac_sqrt_alpha>(W_outT, true); jac->set_x0(*x_in_tpetra); } return; }
virtual void evalModelImpl( const Thyra::ModelEvaluatorBase::InArgs<double> &in_args, const Thyra::ModelEvaluatorBase::OutArgs<double> &out_args ) const { const double alpha = in_args.get_alpha(); double beta = in_args.get_beta(); // From packages/piro/test/MockModelEval_A.cpp if (alpha == 0.0 && beta == 0.0) { // beta = 1.0; } #ifndef NDEBUG TEUCHOS_ASSERT_EQUALITY(alpha, 0.0); TEUCHOS_ASSERT_EQUALITY(beta, 1.0); #endif const auto & x_in = in_args.get_x(); #ifndef NDEBUG TEUCHOS_ASSERT(!x_in.is_null()); #endif // create corresponding tpetra vector auto x_in_tpetra = Thyra::TpetraOperatorVectorExtraction<double,int,int>::getConstTpetraVector( x_in ); // Dissect in_args.get_p(0) into parameter sublists. const auto & p_in = in_args.get_p(0); #ifndef NDEBUG TEUCHOS_ASSERT(!p_in.is_null()); #endif #ifndef NDEBUG // Make sure the parameters aren't NaNs. for (int k = 0; k < p_in->space()->dim(); k++) { TEUCHOS_ASSERT(!std::isnan(Thyra::get_ele(*p_in, k))); } #endif // Fill the parameters into a std::map. const auto param_names = this->get_p_names(0); std::map<std::string, double> params; for (int k = 0; k < p_in->space()->dim(); k++) { params[(*param_names)[k]] = Thyra::get_ele(*p_in, k); } // compute F const auto & f_out = out_args.get_f(); if (!f_out.is_null()) { auto f_out_tpetra = Thyra::TpetraOperatorVectorExtraction<double,int,int>::getTpetraVector( f_out ); this->f_->set_parameters(params, {}); this->f_->apply( *x_in_tpetra, *f_out_tpetra ); } // Compute df/dp. const auto & derivMv = out_args.get_DfDp(0).getDerivativeMultiVector(); const auto & dfdp_out = derivMv.getMultiVector(); if (!dfdp_out.is_null()) { auto dfdp_out_tpetra = Thyra::TpetraOperatorVectorExtraction<double,int,int>::getTpetraMultiVector( dfdp_out ); const int numAllParams = this->get_p_space(0)->dim(); TEUCHOS_ASSERT_EQUALITY( numAllParams, dfdp_out_tpetra->getNumVectors() ); // Compute all derivatives. this->dfdp_->set_parameters(params, {}); for (int k = 0; k < numAllParams; k++) { this->dfdp_->apply( *x_in_tpetra, *dfdp_out_tpetra->getVectorNonConst(k) ); } } // Fill Jacobian. const auto & W_out = out_args.get_W_op(); if(!W_out.is_null()) { auto W_outT = Thyra::TpetraOperatorVectorExtraction<double,int,int>::getTpetraOperator( W_out ); const auto & jac = Teuchos::rcp_dynamic_cast<nosh::fvm_operator>(W_outT, true); std::shared_ptr<const Tpetra::Vector<double,int,int>> x_std = Teuchos::get_shared_ptr(x_in_tpetra); jac->set_parameters(params, {{"u0", x_std}}); } // // Fill preconditioner. // const auto & WPrec_out = out_args.get_W_prec(); // if(!WPrec_out.is_null()) { // auto WPrec_outT = // Thyra::TpetraOperatorVectorExtraction<double,int,int>::getTpetraOperator( // WPrec_out->getNonconstUnspecifiedPrecOp() // ); // const auto & keoPrec = // Teuchos::rcp_dynamic_cast<nosh::keo_regularized>(WPrec_outT, true); // keoPrec->rebuild( // params, // *x_in_tpetra // ); // } return; }