| 1 |
// @HEADER |
| 2 |
// ***************************************************************************** |
| 3 |
// Rapid Optimization Library (ROL) Package |
| 4 |
// |
| 5 |
// Copyright 2014 NTESS and the ROL contributors. |
| 6 |
// SPDX-License-Identifier: BSD-3-Clause |
| 7 |
// ***************************************************************************** |
| 8 |
// @HEADER |
| 9 |
|
| 10 |
#ifndef ROL_FRACTIONALVECTOR_H |
| 11 |
#define ROL_FRACTIONALVECTOR_H |
| 12 |
|
| 13 |
#include "ROL_TpetraMultiVector.hpp" |
| 14 |
#include "../../TOOLS/assembler.hpp" |
| 15 |
#include <math.h> |
| 16 |
|
| 17 |
// Do not instantiate the template in this translation unit. |
| 18 |
extern template class Assembler<double>; |
| 19 |
|
| 20 |
template <class Real> |
| 21 |
class FractionalVector { |
| 22 |
private: |
| 23 |
const ROL::Ptr<PDE<Real> > pde_local_; |
| 24 |
const ROL::Ptr<PDE<Real> > pde_cylinder_; |
| 25 |
ROL::Ptr<Assembler<Real> > assembler_local_; |
| 26 |
ROL::Ptr<Assembler<Real> > assembler_cylinder_; |
| 27 |
|
| 28 |
ROL::Ptr<Tpetra::MultiVector<> > Flocal_; |
| 29 |
ROL::Ptr<Tpetra::CrsMatrix<> > Klocal_; |
| 30 |
ROL::Ptr<Tpetra::CrsMatrix<> > Mcylinder_; |
| 31 |
|
| 32 |
ROL::Ptr<Tpetra::MultiVector<> > Fptr_; |
| 33 |
ROL::Ptr<ROL::Vector<Real> > F_; |
| 34 |
|
| 35 |
public: |
| 36 |
FractionalVector(const ROL::Ptr<PDE<Real> > &pde_local, |
| 37 |
const ROL::Ptr<MeshManager<Real> > &mesh_local, |
| 38 |
const ROL::Ptr<PDE<Real> > &pde_cylinder, |
| 39 |
const ROL::Ptr<MeshManager<Real> > &mesh_cylinder, |
| 40 |
const ROL::Ptr<const Teuchos::Comm<int> > &comm, |
| 41 |
Teuchos::ParameterList &parlist, |
| 42 |
std::ostream &outStream = std::cout) |
| 43 |
: pde_local_(pde_local), pde_cylinder_(pde_cylinder) { |
| 44 |
ROL::Ptr<Tpetra::MultiVector<> > uvec; |
| 45 |
ROL::Ptr<Tpetra::MultiVector<> > zvec; |
| 46 |
// Assemble local components |
| 47 |
assembler_local_ = ROL::makePtr<Assembler<Real>>(pde_local_->getFields(),mesh_local,comm,parlist,outStream); |
| 48 |
assembler_local_->setCellNodes(*pde_local_); |
| 49 |
uvec = assembler_local_->createStateVector(); uvec->putScalar(static_cast<Real>(0)); |
| 50 |
zvec = assembler_local_->createControlVector(); zvec->putScalar(static_cast<Real>(0)); |
| 51 |
assembler_local_->assemblePDEJacobian1(Klocal_,pde_local_,uvec,zvec); |
| 52 |
assembler_local_->assemblePDEResidual(Flocal_,pde_local_,uvec,zvec); |
| 53 |
// Assemble cylinder components |
| 54 |
assembler_cylinder_ = ROL::makePtr<Assembler<Real>>(pde_cylinder_->getFields(),mesh_cylinder,comm,parlist,outStream); |
| 55 |
assembler_cylinder_->setCellNodes(*pde_cylinder_); |
| 56 |
assembler_cylinder_->assemblePDERieszMap1(Mcylinder_,pde_cylinder_); |
| 57 |
// Build fractional vector |
| 58 |
Real s = parlist.sublist("Problem").get("Fractional Power",0.5); |
| 59 |
Real alpha = static_cast<Real>(1) - static_cast<Real>(2)*s; |
| 60 |
Real ds = std::pow(static_cast<Real>(2), alpha) * tgamma(static_cast<Real>(1)-s)/tgamma(s); |
| 61 |
Fptr_ = ROL::makePtr<Tpetra::MultiVector<>>(Klocal_->getRowMap(),Mcylinder_->getGlobalNumCols()); |
| 62 |
Fptr_->getVectorNonConst(0)->scale(-ds,*Flocal_); |
| 63 |
F_ = ROL::makePtr<ROL::TpetraMultiVector<Real>>(Fptr_); |
| 64 |
} |
| 65 |
|
| 66 |
FractionalVector(const ROL::Ptr<const Tpetra::MultiVector<> > &F, |
| 67 |
const ROL::Ptr<const Tpetra::Map<> > &map, |
| 68 |
const int numCylinder, |
| 69 |
const Real s) { |
| 70 |
// Build fractional vector |
| 71 |
Real alpha = static_cast<Real>(1) - static_cast<Real>(2)*s; |
| 72 |
Real ds = std::pow(static_cast<Real>(2), alpha) * tgamma(static_cast<Real>(1)-s)/tgamma(s); |
| 73 |
Fptr_ = ROL::makePtr<Tpetra::MultiVector<>>(map,numCylinder); |
| 74 |
Fptr_->getVectorNonConst(0)->scale(-ds,*F); |
| 75 |
F_ = ROL::makePtr<ROL::TpetraMultiVector<Real>>(Fptr_); |
| 76 |
} |
| 77 |
|
| 78 |
const ROL::Ptr<const ROL::Vector<Real> > get(void) const { |
| 79 |
return F_; |
| 80 |
} |
| 81 |
}; |
| 82 |
|
| 83 |
#endif |