| 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 |
/*! \file obj.hpp |
| 11 |
\brief Provides the interface for local (cell-based) objective function computations. |
| 12 |
*/ |
| 13 |
|
| 14 |
#ifndef PDEOPT_QOI_VOLUME_HPP |
| 15 |
#define PDEOPT_QOI_VOLUME_HPP |
| 16 |
|
| 17 |
#include "../../TOOLS/qoi.hpp" |
| 18 |
#include "../../TOOLS/fe.hpp" |
| 19 |
|
| 20 |
template <class Real> |
| 21 |
class QoI_Volume_TopoOpt : public QoI<Real> { |
| 22 |
private: |
| 23 |
const ROL::Ptr<FE<Real>> fe_; |
| 24 |
ROL::Ptr<Intrepid::FieldContainer<Real>> ones_; |
| 25 |
ROL::Ptr<Intrepid::FieldContainer<Real>> volFrac_; |
| 26 |
|
| 27 |
public: |
| 28 |
QoI_Volume_TopoOpt(const ROL::Ptr<FE<Real>> &fe, |
| 29 |
const Real v0 = Real(0)) |
| 30 |
: fe_(fe) { |
| 31 |
// Get relevant dimensions |
| 32 |
int c = fe_->cubPts()->dimension(0); |
| 33 |
int p = fe_->cubPts()->dimension(1); |
| 34 |
ones_ = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p); |
| 35 |
volFrac_ = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p); |
| 36 |
ones_->initialize(static_cast<Real>(1)); |
| 37 |
volFrac_->initialize(v0); |
| 38 |
} |
| 39 |
|
| 40 |
Real value(ROL::Ptr<Intrepid::FieldContainer<Real>> & val, |
| 41 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 42 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 43 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 44 |
// Get relevant dimensions |
| 45 |
int c = fe_->gradN()->dimension(0); |
| 46 |
int p = fe_->gradN()->dimension(2); |
| 47 |
|
| 48 |
// Initialize output val |
| 49 |
val = ROL::makePtr<Intrepid::FieldContainer<Real>>(c); |
| 50 |
// Evaluate on FE basis |
| 51 |
ROL::Ptr<Intrepid::FieldContainer<Real>> valZ_eval |
| 52 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 53 |
fe_->evaluateValue(valZ_eval, z_coeff); |
| 54 |
Intrepid::RealSpaceTools<Real>::subtract(*valZ_eval,*volFrac_); |
| 55 |
|
| 56 |
// Compute energy |
| 57 |
fe_->computeIntegral(val,valZ_eval,ones_); |
| 58 |
return static_cast<Real>(0); |
| 59 |
} |
| 60 |
|
| 61 |
void gradient_1(ROL::Ptr<Intrepid::FieldContainer<Real>> & grad, |
| 62 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 63 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 64 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 65 |
throw Exception::Zero(">>> QoI_Volume_TopoOpt::gradient_1 is zero."); |
| 66 |
} |
| 67 |
|
| 68 |
void gradient_2(ROL::Ptr<Intrepid::FieldContainer<Real>> & grad, |
| 69 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 70 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 71 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 72 |
// Get relevant dimensions |
| 73 |
int c = fe_->gradN()->dimension(0); |
| 74 |
int f = fe_->gradN()->dimension(1); |
| 75 |
|
| 76 |
// Initialize output grad |
| 77 |
grad = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f); |
| 78 |
|
| 79 |
// Compute gradient of energy |
| 80 |
Intrepid::FunctionSpaceTools::integrate<Real>(*grad, |
| 81 |
*ones_, |
| 82 |
*fe_->NdetJ(), |
| 83 |
Intrepid::COMP_CPP, false); |
| 84 |
|
| 85 |
} |
| 86 |
|
| 87 |
void HessVec_11(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess, |
| 88 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & v_coeff, |
| 89 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 90 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 91 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 92 |
throw Exception::Zero(">>> QoI_Volume_TopoOpt::HessVec_11 is zero."); |
| 93 |
} |
| 94 |
|
| 95 |
void HessVec_12(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess, |
| 96 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & v_coeff, |
| 97 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 98 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 99 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 100 |
throw Exception::Zero(">>> QoI_Volume_TopoOpt::HessVec_12 is zero."); |
| 101 |
} |
| 102 |
|
| 103 |
void HessVec_21(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess, |
| 104 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & v_coeff, |
| 105 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 106 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 107 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 108 |
throw Exception::Zero(">>> QoI_Volume_TopoOpt::HessVec_21 is zero."); |
| 109 |
} |
| 110 |
|
| 111 |
void HessVec_22(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess, |
| 112 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & v_coeff, |
| 113 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 114 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 115 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 116 |
throw Exception::Zero(">>> QoI_Volume_TopoOpt::HessVec_22 is zero."); |
| 117 |
} |
| 118 |
|
| 119 |
}; // QoI_VolumeObj |
| 120 |
|
| 121 |
#endif |