| 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 pde.hpp |
| 11 |
\brief Implements the local PDE interface for the Poisson-Boltzmann control problem. |
| 12 |
*/ |
| 13 |
|
| 14 |
#ifndef PDE_ALLEN_CAHN_HPP |
| 15 |
#define PDE_ALLEN_CAHN_HPP |
| 16 |
|
| 17 |
#include "../TOOLS/pde.hpp" |
| 18 |
#include "../TOOLS/fe.hpp" |
| 19 |
|
| 20 |
#include "Intrepid_HGRAD_QUAD_C1_FEM.hpp" |
| 21 |
#include "Intrepid_HGRAD_QUAD_C2_FEM.hpp" |
| 22 |
#include "Intrepid_DefaultCubatureFactory.hpp" |
| 23 |
#include "Intrepid_FunctionSpaceTools.hpp" |
| 24 |
#include "Intrepid_CellTools.hpp" |
| 25 |
|
| 26 |
#include "ROL_Ptr.hpp" |
| 27 |
|
| 28 |
template <class Real> |
| 29 |
class PDE_Allen_Cahn : public PDE<Real> { |
| 30 |
private: |
| 31 |
// Finite element basis information |
| 32 |
ROL::Ptr<Intrepid::Basis<Real, Intrepid::FieldContainer<Real>>> basisPtr_; |
| 33 |
std::vector<ROL::Ptr<Intrepid::Basis<Real, Intrepid::FieldContainer<Real>>>> basisPtrs_; |
| 34 |
// Cell cubature information |
| 35 |
ROL::Ptr<Intrepid::Cubature<Real>> cellCub_; |
| 36 |
ROL::Ptr<Intrepid::Cubature<Real>> bdryCub_; |
| 37 |
// Cell node information |
| 38 |
ROL::Ptr<Intrepid::FieldContainer<Real>> volCellNodes_; |
| 39 |
std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>>> bdryCellNodes_; |
| 40 |
std::vector<std::vector<std::vector<int>>> bdryCellLocIds_; |
| 41 |
// Finite element definition |
| 42 |
ROL::Ptr<FE<Real>> fe_vol_; |
| 43 |
std::vector<std::vector<ROL::Ptr<FE<Real>>>> fe_bdry_; |
| 44 |
// Local degrees of freedom on boundary, for each side of the reference cell (first index). |
| 45 |
std::vector<std::vector<int>> fidx_; |
| 46 |
|
| 47 |
Real uScale_, vScale_; |
| 48 |
Real robinCoeff_; |
| 49 |
|
| 50 |
public: |
| 51 |
PDE_Allen_Cahn(Teuchos::ParameterList &parlist) { |
| 52 |
// Finite element fields. |
| 53 |
int basisOrder = parlist.sublist("Problem").get("Order of FE discretization",1); |
| 54 |
if (basisOrder == 1) { |
| 55 |
basisPtr_ = ROL::makePtr<Intrepid::Basis_HGRAD_QUAD_C1_FEM<Real, Intrepid::FieldContainer<Real>>>(); |
| 56 |
} |
| 57 |
else if (basisOrder == 2) { |
| 58 |
basisPtr_ = ROL::makePtr<Intrepid::Basis_HGRAD_QUAD_C2_FEM<Real, Intrepid::FieldContainer<Real>>>(); |
| 59 |
} |
| 60 |
basisPtrs_.clear(); basisPtrs_.push_back(basisPtr_); |
| 61 |
// Quadrature rules. |
| 62 |
shards::CellTopology cellType = basisPtr_->getBaseCellTopology(); // get the cell type from any basis |
| 63 |
Intrepid::DefaultCubatureFactory<Real> cubFactory; // create cubature factory |
| 64 |
int cubDegree = parlist.sublist("PDE Poisson Boltzmann").get("Cubature Degree",2); // set cubature degree, e.g., 2 |
| 65 |
cellCub_ = cubFactory.create(cellType, cubDegree); // create default cubature |
| 66 |
|
| 67 |
int d = cellType.getDimension(); |
| 68 |
shards::CellTopology bdryCellType = cellType.getCellTopologyData(d-1, 0); |
| 69 |
int bdryCubDegree = parlist.sublist("Problem").get("Boundary Cubature Degree",2); // set cubature degree, e.g., 2 |
| 70 |
bdryCub_ = cubFactory.create(bdryCellType, bdryCubDegree); |
| 71 |
|
| 72 |
uScale_ = parlist.sublist("Problem").get("Scale Third Order Term",1.0); |
| 73 |
vScale_ = parlist.sublist("Problem").get("Scale First Order Term",1.0); |
| 74 |
robinCoeff_ = parlist.sublist("Problem").get("Robin Coefficient",1e0); |
| 75 |
} |
| 76 |
|
| 77 |
void residual(ROL::Ptr<Intrepid::FieldContainer<Real>> & res, |
| 78 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 79 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 80 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 81 |
// GET DIMENSIONS |
| 82 |
const int c = fe_vol_->gradN()->dimension(0); |
| 83 |
const int f = fe_vol_->gradN()->dimension(1); |
| 84 |
const int p = fe_vol_->gradN()->dimension(2); |
| 85 |
const int d = fe_vol_->gradN()->dimension(3); |
| 86 |
// INITIALIZE RESIDUAL |
| 87 |
res = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f); |
| 88 |
// STORAGE |
| 89 |
ROL::Ptr<Intrepid::FieldContainer<Real>> valU_eval, gradU_eval, lambda, lambda_gradU_eval, phi_valU_eval; |
| 90 |
valU_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 91 |
gradU_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d); |
| 92 |
lambda = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 93 |
lambda_gradU_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d); |
| 94 |
phi_valU_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 95 |
// COMPUTE PDE COEFFICIENTS |
| 96 |
computeCoefficients(lambda); |
| 97 |
// EVALUATE STATE AT QUADRATURE POINTS |
| 98 |
fe_vol_->evaluateValue(valU_eval, u_coeff); |
| 99 |
fe_vol_->evaluateGradient(gradU_eval, u_coeff); |
| 100 |
// ADD STIFFNESS TERM TO RESIDUAL |
| 101 |
Intrepid::FunctionSpaceTools::tensorMultiplyDataData<Real>(*lambda_gradU_eval, |
| 102 |
*lambda, |
| 103 |
*gradU_eval); |
| 104 |
Intrepid::FunctionSpaceTools::integrate<Real>(*res, |
| 105 |
*lambda_gradU_eval, |
| 106 |
*(fe_vol_->gradNdetJ()), |
| 107 |
Intrepid::COMP_CPP, false); |
| 108 |
// ADD NONLINEAR TERM TO RESIDUAL |
| 109 |
computeNonlinearity(phi_valU_eval, valU_eval,0); |
| 110 |
Intrepid::FunctionSpaceTools::integrate<Real>(*res, |
| 111 |
*phi_valU_eval, |
| 112 |
*(fe_vol_->NdetJ()), |
| 113 |
Intrepid::COMP_CPP, true); |
| 114 |
// APPLY ROBIN CONDITIONS |
| 115 |
std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>>> bdryCellDofValues; |
| 116 |
const int numSideSets = bdryCellLocIds_.size(); |
| 117 |
for (int i = 0; i < numSideSets; ++i) { |
| 118 |
int numLocalSideIds = bdryCellLocIds_[i].size(); |
| 119 |
for (int j = 0; j < numLocalSideIds; ++j) { |
| 120 |
int numCellsSide = bdryCellLocIds_[i][j].size(); |
| 121 |
const int numCubPerSide = bdryCub_->getNumPoints(); |
| 122 |
if (numCellsSide) { |
| 123 |
// Get U and Z coefficients on Robin boundary |
| 124 |
ROL::Ptr<Intrepid::FieldContainer<Real >> u_coeff_bdry, z_coeff_bdry; |
| 125 |
u_coeff_bdry = getBoundaryCoeff(*u_coeff, i, j); |
| 126 |
z_coeff_bdry = getBoundaryCoeff(*z_coeff, i, j); |
| 127 |
// Evaluate U and Z on FE basis |
| 128 |
ROL::Ptr<Intrepid::FieldContainer<Real >> valU_eval_bdry, valZ_eval_bdry; |
| 129 |
valU_eval_bdry = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 130 |
valZ_eval_bdry = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 131 |
fe_bdry_[i][j]->evaluateValue(valU_eval_bdry, u_coeff_bdry); |
| 132 |
fe_bdry_[i][j]->evaluateValue(valZ_eval_bdry, z_coeff_bdry); |
| 133 |
// Compute Robin residual |
| 134 |
Intrepid::FieldContainer<Real> robinRes(numCellsSide, f); |
| 135 |
ROL::Ptr< Intrepid::FieldContainer<Real>> robinVal |
| 136 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 137 |
computeRobin(robinVal,valU_eval_bdry,valZ_eval_bdry,i,j,0); |
| 138 |
Intrepid::FunctionSpaceTools::integrate<Real>(robinRes, |
| 139 |
*robinVal, |
| 140 |
*(fe_bdry_[i][j]->NdetJ()), |
| 141 |
Intrepid::COMP_CPP, false); |
| 142 |
// Add Robin residual to volume residual |
| 143 |
for (int k = 0; k < numCellsSide; ++k) { |
| 144 |
int cidx = bdryCellLocIds_[i][j][k]; |
| 145 |
for (int l = 0; l < f; ++l) { |
| 146 |
(*res)(cidx,l) += robinRes(k,l); |
| 147 |
} |
| 148 |
} |
| 149 |
} |
| 150 |
} |
| 151 |
} |
| 152 |
} |
| 153 |
|
| 154 |
void Jacobian_1(ROL::Ptr<Intrepid::FieldContainer<Real>> & jac, |
| 155 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 156 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 157 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 158 |
// GET DIMENSIONS |
| 159 |
const int c = fe_vol_->gradN()->dimension(0); |
| 160 |
const int f = fe_vol_->gradN()->dimension(1); |
| 161 |
const int p = fe_vol_->gradN()->dimension(2); |
| 162 |
const int d = fe_vol_->gradN()->dimension(3); |
| 163 |
// INITIALIZE JACOBIAN |
| 164 |
jac = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, f); |
| 165 |
// STORAGE |
| 166 |
ROL::Ptr<Intrepid::FieldContainer<Real>> valU_eval, lambda, lambda_gradN_eval, dphi_valU_eval, NdphiU; |
| 167 |
valU_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 168 |
lambda = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 169 |
lambda_gradN_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, p, d); |
| 170 |
dphi_valU_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 171 |
NdphiU = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, p); |
| 172 |
// COMPUTE PDE COEFFICIENTS |
| 173 |
computeCoefficients(lambda); |
| 174 |
// EVALUATE STATE AT QUADRATURE POINTS |
| 175 |
fe_vol_->evaluateValue(valU_eval, u_coeff); |
| 176 |
// ADD STIFFNESS TERM TO JACOBIAN |
| 177 |
Intrepid::FunctionSpaceTools::tensorMultiplyDataField<Real>(*lambda_gradN_eval, |
| 178 |
*lambda, |
| 179 |
*(fe_vol_->gradN())); |
| 180 |
Intrepid::FunctionSpaceTools::integrate<Real>(*jac, |
| 181 |
*lambda_gradN_eval, |
| 182 |
*(fe_vol_->gradNdetJ()), |
| 183 |
Intrepid::COMP_CPP, false); |
| 184 |
// ADD NONLINEAR TERM |
| 185 |
computeNonlinearity(dphi_valU_eval, valU_eval, 1); |
| 186 |
Intrepid::FunctionSpaceTools::scalarMultiplyDataField<Real>(*NdphiU, |
| 187 |
*dphi_valU_eval, |
| 188 |
*(fe_vol_->N())); |
| 189 |
Intrepid::FunctionSpaceTools::integrate<Real>(*jac, |
| 190 |
*NdphiU, |
| 191 |
*(fe_vol_->NdetJ()), |
| 192 |
Intrepid::COMP_CPP, true); |
| 193 |
// APPLY ROBIN CONDITIONS |
| 194 |
const int numSideSets = bdryCellLocIds_.size(); |
| 195 |
for (int i = 0; i < numSideSets; ++i) { |
| 196 |
int numLocalSideIds = bdryCellLocIds_[i].size(); |
| 197 |
for (int j = 0; j < numLocalSideIds; ++j) { |
| 198 |
int numCellsSide = bdryCellLocIds_[i][j].size(); |
| 199 |
const int numCubPerSide = bdryCub_->getNumPoints(); |
| 200 |
if (numCellsSide) { |
| 201 |
// Get U and Z coefficients on Robin boundary |
| 202 |
ROL::Ptr<Intrepid::FieldContainer<Real >> u_coeff_bdry, z_coeff_bdry; |
| 203 |
u_coeff_bdry = getBoundaryCoeff(*u_coeff, i, j); |
| 204 |
z_coeff_bdry = getBoundaryCoeff(*z_coeff, i, j); |
| 205 |
// Evaluate U and Z on FE basis |
| 206 |
ROL::Ptr<Intrepid::FieldContainer<Real >> valU_eval_bdry, valZ_eval_bdry; |
| 207 |
valU_eval_bdry = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 208 |
valZ_eval_bdry = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 209 |
fe_bdry_[i][j]->evaluateValue(valU_eval_bdry, u_coeff_bdry); |
| 210 |
fe_bdry_[i][j]->evaluateValue(valZ_eval_bdry, z_coeff_bdry); |
| 211 |
// Compute Robin residual |
| 212 |
Intrepid::FieldContainer<Real> robinVal_N(numCellsSide, f, numCubPerSide); |
| 213 |
Intrepid::FieldContainer<Real> robinJac(numCellsSide, f, f); |
| 214 |
ROL::Ptr< Intrepid::FieldContainer<Real>> robinVal |
| 215 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 216 |
computeRobin(robinVal,valU_eval_bdry,valZ_eval_bdry,i,j,1,1); |
| 217 |
Intrepid::FunctionSpaceTools::scalarMultiplyDataField<Real>(robinVal_N, |
| 218 |
*robinVal, |
| 219 |
*(fe_bdry_[i][j]->N())); |
| 220 |
Intrepid::FunctionSpaceTools::integrate<Real>(robinJac, |
| 221 |
robinVal_N, |
| 222 |
*(fe_bdry_[i][j]->NdetJ()), |
| 223 |
Intrepid::COMP_CPP, false); |
| 224 |
// Add Robin residual to volume residual |
| 225 |
for (int k = 0; k < numCellsSide; ++k) { |
| 226 |
int cidx = bdryCellLocIds_[i][j][k]; |
| 227 |
for (int l = 0; l < f; ++l) { |
| 228 |
for (int m = 0; m < f; ++m) { |
| 229 |
(*jac)(cidx,l,m) += robinJac(k,l,m); |
| 230 |
} |
| 231 |
} |
| 232 |
} |
| 233 |
} |
| 234 |
} |
| 235 |
} |
| 236 |
} |
| 237 |
|
| 238 |
void Jacobian_2(ROL::Ptr<Intrepid::FieldContainer<Real>> & jac, |
| 239 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 240 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 241 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 242 |
// GET DIMENSIONS |
| 243 |
const int c = fe_vol_->gradN()->dimension(0); |
| 244 |
const int f = fe_vol_->gradN()->dimension(1); |
| 245 |
// INITIALIZE JACOBIAN |
| 246 |
jac = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, f); |
| 247 |
// APPLY ROBIN CONDITIONS |
| 248 |
const int numSideSets = bdryCellLocIds_.size(); |
| 249 |
for (int i = 0; i < numSideSets; ++i) { |
| 250 |
int numLocalSideIds = bdryCellLocIds_[i].size(); |
| 251 |
for (int j = 0; j < numLocalSideIds; ++j) { |
| 252 |
int numCellsSide = bdryCellLocIds_[i][j].size(); |
| 253 |
const int numCubPerSide = bdryCub_->getNumPoints(); |
| 254 |
if (numCellsSide) { |
| 255 |
// Get U and Z coefficients on Robin boundary |
| 256 |
ROL::Ptr<Intrepid::FieldContainer<Real >> u_coeff_bdry, z_coeff_bdry; |
| 257 |
u_coeff_bdry = getBoundaryCoeff(*u_coeff, i, j); |
| 258 |
z_coeff_bdry = getBoundaryCoeff(*z_coeff, i, j); |
| 259 |
// Evaluate U and Z on FE basis |
| 260 |
ROL::Ptr<Intrepid::FieldContainer<Real >> valU_eval_bdry, valZ_eval_bdry; |
| 261 |
valU_eval_bdry = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 262 |
valZ_eval_bdry = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 263 |
fe_bdry_[i][j]->evaluateValue(valU_eval_bdry, u_coeff_bdry); |
| 264 |
fe_bdry_[i][j]->evaluateValue(valZ_eval_bdry, z_coeff_bdry); |
| 265 |
// Compute Robin residual |
| 266 |
Intrepid::FieldContainer<Real> robinVal_N(numCellsSide, f, numCubPerSide); |
| 267 |
Intrepid::FieldContainer<Real> robinJac(numCellsSide, f, f); |
| 268 |
ROL::Ptr< Intrepid::FieldContainer<Real>> robinVal |
| 269 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 270 |
computeRobin(robinVal,valU_eval_bdry,valZ_eval_bdry,i,j,1,2); |
| 271 |
Intrepid::FunctionSpaceTools::scalarMultiplyDataField<Real>(robinVal_N, |
| 272 |
*robinVal, |
| 273 |
*(fe_bdry_[i][j]->N())); |
| 274 |
Intrepid::FunctionSpaceTools::integrate<Real>(robinJac, |
| 275 |
robinVal_N, |
| 276 |
*(fe_bdry_[i][j]->NdetJ()), |
| 277 |
Intrepid::COMP_CPP, false); |
| 278 |
// Add Robin residual to volume residual |
| 279 |
for (int k = 0; k < numCellsSide; ++k) { |
| 280 |
int cidx = bdryCellLocIds_[i][j][k]; |
| 281 |
for (int l = 0; l < f; ++l) { |
| 282 |
for (int m = 0; m < f; ++m) { |
| 283 |
(*jac)(cidx,l,m) += robinJac(k,l,m); |
| 284 |
} |
| 285 |
} |
| 286 |
} |
| 287 |
} |
| 288 |
} |
| 289 |
} |
| 290 |
} |
| 291 |
|
| 292 |
void Hessian_11(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess, |
| 293 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff, |
| 294 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 295 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 296 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 297 |
// GET DIMENSIONS |
| 298 |
const int c = fe_vol_->gradN()->dimension(0); |
| 299 |
const int f = fe_vol_->gradN()->dimension(1); |
| 300 |
const int p = fe_vol_->gradN()->dimension(2); |
| 301 |
// INITIALIZE HESSIAN |
| 302 |
hess = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, f); |
| 303 |
// STORAGE |
| 304 |
ROL::Ptr<Intrepid::FieldContainer<Real>> valU_eval, valL_eval, d2phi_valU_eval, Ld2phiU, NLd2phiU; |
| 305 |
valU_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 306 |
valL_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 307 |
d2phi_valU_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 308 |
Ld2phiU = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 309 |
NLd2phiU = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, p); |
| 310 |
// EVALUATE STATE AT QUADRATURE POINTS |
| 311 |
fe_vol_->evaluateValue(valU_eval, u_coeff); |
| 312 |
fe_vol_->evaluateValue(valL_eval, l_coeff); |
| 313 |
// COMPUTE NONLINEAR TERM |
| 314 |
computeNonlinearity(d2phi_valU_eval, valU_eval, 2); |
| 315 |
Intrepid::FunctionSpaceTools::scalarMultiplyDataData<Real>(*Ld2phiU, |
| 316 |
*d2phi_valU_eval, |
| 317 |
*valL_eval); |
| 318 |
Intrepid::FunctionSpaceTools::scalarMultiplyDataField<Real>(*NLd2phiU, |
| 319 |
*Ld2phiU, |
| 320 |
*(fe_vol_->N())); |
| 321 |
Intrepid::FunctionSpaceTools::integrate<Real>(*hess, |
| 322 |
*NLd2phiU, |
| 323 |
*(fe_vol_->NdetJ()), |
| 324 |
Intrepid::COMP_CPP, false); |
| 325 |
} |
| 326 |
|
| 327 |
void Hessian_12(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess, |
| 328 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff, |
| 329 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 330 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 331 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 332 |
throw Exception::Zero(">>> (PDE_Allen_Cahn:Hessian_12: Hessian is zero."); |
| 333 |
} |
| 334 |
|
| 335 |
void Hessian_21(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess, |
| 336 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff, |
| 337 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 338 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 339 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 340 |
throw Exception::Zero(">>> (PDE_Allen_Cahn:Hessian_21: Hessian is zero."); |
| 341 |
} |
| 342 |
|
| 343 |
void Hessian_22(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess, |
| 344 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff, |
| 345 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 346 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 347 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 348 |
throw Exception::Zero(">>> (PDE_Allen_Cahn:Hessian_22: Hessian is zero."); |
| 349 |
} |
| 350 |
|
| 351 |
void RieszMap_1(ROL::Ptr<Intrepid::FieldContainer<Real>> & riesz) { |
| 352 |
// GET DIMENSIONS |
| 353 |
const int c = fe_vol_->N()->dimension(0); |
| 354 |
const int f = fe_vol_->N()->dimension(1); |
| 355 |
// INITIALIZE RIESZ |
| 356 |
riesz = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, f); |
| 357 |
*riesz = *fe_vol_->stiffMat(); |
| 358 |
Intrepid::RealSpaceTools<Real>::add(*riesz,*(fe_vol_->massMat())); |
| 359 |
} |
| 360 |
|
| 361 |
void RieszMap_2(ROL::Ptr<Intrepid::FieldContainer<Real>> & riesz) { |
| 362 |
// GET DIMENSIONS |
| 363 |
const int c = fe_vol_->N()->dimension(0); |
| 364 |
const int f = fe_vol_->N()->dimension(1); |
| 365 |
// INITIALIZE RIESZ |
| 366 |
riesz = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, f); |
| 367 |
*riesz = *fe_vol_->massMat(); |
| 368 |
} |
| 369 |
|
| 370 |
std::vector<ROL::Ptr<Intrepid::Basis<Real, Intrepid::FieldContainer<Real>>>> getFields() { |
| 371 |
return basisPtrs_; |
| 372 |
} |
| 373 |
|
| 374 |
void setCellNodes(const ROL::Ptr<Intrepid::FieldContainer<Real>> &volCellNodes, |
| 375 |
const std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>>> &bdryCellNodes, |
| 376 |
const std::vector<std::vector<std::vector<int>>> &bdryCellLocIds) { |
| 377 |
volCellNodes_ = volCellNodes; |
| 378 |
bdryCellNodes_ = bdryCellNodes; |
| 379 |
bdryCellLocIds_ = bdryCellLocIds; |
| 380 |
// Finite element definition. |
| 381 |
fe_vol_ = ROL::makePtr<FE<Real>>(volCellNodes_,basisPtr_,cellCub_); |
| 382 |
// Set local boundary DOFs. |
| 383 |
fidx_ = fe_vol_->getBoundaryDofs(); |
| 384 |
// Construct boundary FEs |
| 385 |
const int numSidesets = bdryCellNodes.size(); |
| 386 |
fe_bdry_.resize(numSidesets); |
| 387 |
for(int i = 0; i < numSidesets; ++i) { |
| 388 |
int numLocSides = bdryCellNodes[i].size(); |
| 389 |
fe_bdry_[i].resize(numLocSides); |
| 390 |
for (int j = 0; j < numLocSides; ++j) { |
| 391 |
if (bdryCellNodes_[i][j] != ROL::nullPtr) { |
| 392 |
fe_bdry_[i][j] = ROL::makePtr<FE<Real>>(bdryCellNodes_[i][j],basisPtr_,bdryCub_,j); |
| 393 |
} |
| 394 |
} |
| 395 |
} |
| 396 |
} |
| 397 |
|
| 398 |
const ROL::Ptr<FE<Real>> getFE(void) const { |
| 399 |
return fe_vol_; |
| 400 |
} |
| 401 |
|
| 402 |
const std::vector<std::vector<ROL::Ptr<FE<Real>>>> getBdryFE(void) const { |
| 403 |
return fe_bdry_; |
| 404 |
} |
| 405 |
|
| 406 |
const ROL::Ptr<Intrepid::FieldContainer<Real>> getCellNodes(void) const { |
| 407 |
return volCellNodes_; |
| 408 |
} |
| 409 |
|
| 410 |
const std::vector<std::vector<std::vector<int>>> getBdryCellLocIds(void) const { |
| 411 |
return bdryCellLocIds_; |
| 412 |
} |
| 413 |
|
| 414 |
private: |
| 415 |
|
| 416 |
Real evaluateLambda(const std::vector<Real> &x) const { |
| 417 |
const std::vector<Real> param = PDE<Real>::getParameter(); |
| 418 |
Real val(1); |
| 419 |
if (param.size()) { |
| 420 |
val += param[0]; |
| 421 |
} |
| 422 |
return val; |
| 423 |
} |
| 424 |
|
| 425 |
void computeCoefficients(ROL::Ptr<Intrepid::FieldContainer<Real>> &lambda) const { |
| 426 |
// GET DIMENSIONS |
| 427 |
const int c = fe_vol_->gradN()->dimension(0); |
| 428 |
const int p = fe_vol_->gradN()->dimension(2); |
| 429 |
const int d = fe_vol_->gradN()->dimension(3); |
| 430 |
std::vector<Real> pt(d); |
| 431 |
for (int i = 0; i < c; ++i) { |
| 432 |
for (int j = 0; j < p; ++j) { |
| 433 |
for ( int k = 0; k < d; ++k) { |
| 434 |
pt[k] = (*fe_vol_->cubPts())(i,j,k); |
| 435 |
} |
| 436 |
(*lambda)(i,j) = evaluateLambda(pt); |
| 437 |
} |
| 438 |
} |
| 439 |
} |
| 440 |
|
| 441 |
Real evaluateDelta(const std::vector<Real> &x) const { |
| 442 |
const std::vector<Real> param = PDE<Real>::getParameter(); |
| 443 |
Real val(1); |
| 444 |
if (param.size()) { |
| 445 |
val += param[1]; |
| 446 |
} |
| 447 |
return val; |
| 448 |
} |
| 449 |
|
| 450 |
Real evaluateNonlinearity(const std::vector<Real> &x, const Real u, const int deriv) const { |
| 451 |
Real val(0); |
| 452 |
if (deriv == 0) { |
| 453 |
val = uScale_*std::pow(u,3) - vScale_*u; |
| 454 |
} |
| 455 |
if (deriv == 1) { |
| 456 |
val = uScale_*static_cast<Real>(3)*std::pow(u,2) - vScale_; |
| 457 |
} |
| 458 |
if (deriv == 2) { |
| 459 |
val = uScale_*static_cast<Real>(6)*u; |
| 460 |
} |
| 461 |
return evaluateDelta(x) * val; |
| 462 |
} |
| 463 |
|
| 464 |
void computeNonlinearity(ROL::Ptr<Intrepid::FieldContainer<Real>> &val, |
| 465 |
const ROL::Ptr<Intrepid::FieldContainer<Real>> &u, |
| 466 |
const int deriv = 0) const { |
| 467 |
// GET DIMENSIONS |
| 468 |
const int c = fe_vol_->gradN()->dimension(0); |
| 469 |
const int p = fe_vol_->gradN()->dimension(2); |
| 470 |
const int d = fe_vol_->gradN()->dimension(3); |
| 471 |
std::vector<Real> pt(d); |
| 472 |
for (int i = 0; i < c; ++i) { |
| 473 |
for (int j = 0; j < p; ++j) { |
| 474 |
for ( int k = 0; k < d; ++k) { |
| 475 |
pt[k] = (*fe_vol_->cubPts())(i,j,k); |
| 476 |
} |
| 477 |
(*val)(i,j) = evaluateNonlinearity(pt, (*u)(i,j), deriv); |
| 478 |
} |
| 479 |
} |
| 480 |
} |
| 481 |
|
| 482 |
Real evaluateRobin(const Real u, const Real z, const std::vector<Real> &x, |
| 483 |
const int sideset, const int locSideId, |
| 484 |
const int deriv = 0, const int component = 1) const { |
| 485 |
const std::vector<Real> param = PDE<Real>::getParameter(); |
| 486 |
Real h(robinCoeff_); |
| 487 |
if (param.size()) { |
| 488 |
h += param[2]; |
| 489 |
} |
| 490 |
if ( deriv == 1 ) { |
| 491 |
return (component==1) ? h : -h; |
| 492 |
} |
| 493 |
if ( deriv > 1 ) { |
| 494 |
return static_cast<Real>(0); |
| 495 |
} |
| 496 |
return h * (u - z); |
| 497 |
} |
| 498 |
|
| 499 |
void computeRobin(ROL::Ptr<Intrepid::FieldContainer<Real>> &robin, |
| 500 |
const ROL::Ptr<Intrepid::FieldContainer<Real>> &u, |
| 501 |
const ROL::Ptr<Intrepid::FieldContainer<Real>> &z, |
| 502 |
const int sideset, |
| 503 |
const int locSideId, |
| 504 |
const int deriv = 0, |
| 505 |
const int component = 1) const { |
| 506 |
const int c = u->dimension(0); |
| 507 |
const int p = u->dimension(1); |
| 508 |
const int d = fe_vol_->gradN()->dimension(3); |
| 509 |
std::vector<Real> pt(d); |
| 510 |
for (int i = 0; i < c; ++i) { |
| 511 |
for (int j = 0; j < p; ++j) { |
| 512 |
for (int k = 0; k < d; ++k) { |
| 513 |
pt[k] = (*fe_bdry_[sideset][locSideId]->cubPts())(i,j,k); |
| 514 |
} |
| 515 |
(*robin)(i,j) = evaluateRobin((*u)(i,j),(*z)(i,j),pt,sideset,locSideId,deriv,component); |
| 516 |
} |
| 517 |
} |
| 518 |
} |
| 519 |
|
| 520 |
ROL::Ptr<Intrepid::FieldContainer<Real>> getBoundaryCoeff( |
| 521 |
const Intrepid::FieldContainer<Real> & cell_coeff, |
| 522 |
int sideSet, int cell) const { |
| 523 |
std::vector<int> bdryCellLocId = bdryCellLocIds_[sideSet][cell]; |
| 524 |
const int numCellsSide = bdryCellLocId.size(); |
| 525 |
const int f = basisPtr_->getCardinality(); |
| 526 |
|
| 527 |
ROL::Ptr<Intrepid::FieldContainer<Real >> bdry_coeff = |
| 528 |
ROL::makePtr<Intrepid::FieldContainer<Real >>(numCellsSide, f); |
| 529 |
for (int i = 0; i < numCellsSide; ++i) { |
| 530 |
for (int j = 0; j < f; ++j) { |
| 531 |
(*bdry_coeff)(i, j) = cell_coeff(bdryCellLocId[i], j); |
| 532 |
} |
| 533 |
} |
| 534 |
return bdry_coeff; |
| 535 |
} |
| 536 |
|
| 537 |
}; // PDE_Allen_Cahn |
| 538 |
|
| 539 |
#endif |