| 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 PDEOPT_DYNAMIC_NAVIERSTOKES_HPP |
| 15 |
#define PDEOPT_DYNAMIC_NAVIERSTOKES_HPP |
| 16 |
|
| 17 |
#include "../../TOOLS/dynpde.hpp" |
| 18 |
#include "../../TOOLS/fe.hpp" |
| 19 |
#include "pde_navier-stokes.hpp" |
| 20 |
|
| 21 |
template <class Real> |
| 22 |
class DynamicPDE_NavierStokes : public DynamicPDE<Real> { |
| 23 |
private: |
| 24 |
// Finite element basis information |
| 25 |
std::vector<ROL::Ptr<Intrepid::Basis<Real, Intrepid::FieldContainer<Real>>>> basisPtrs_; |
| 26 |
// Cell node information |
| 27 |
ROL::Ptr<Intrepid::FieldContainer<Real> > volCellNodes_; |
| 28 |
std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > > bdryCellNodes_; |
| 29 |
std::vector<std::vector<std::vector<int> > > bdryCellLocIds_; |
| 30 |
// Finite element definition |
| 31 |
ROL::Ptr<FE<Real>> feVel_; |
| 32 |
ROL::Ptr<FE<Real>> fePrs_; |
| 33 |
// Local degrees of freedom on boundary, for each side of the reference cell (first index). |
| 34 |
std::vector<std::vector<int>> fvidx_; |
| 35 |
std::vector<std::vector<int>> fpidx_; |
| 36 |
// Coordinates of degrees freedom on boundary cells. |
| 37 |
// Indexing: [sideset number][local side id](cell number, value at dof) |
| 38 |
std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > > bdryCellDofValues_; |
| 39 |
// Steady PDE without Dirichlet BC |
| 40 |
ROL::Ptr<PDE_NavierStokes<Real>> pde_; |
| 41 |
Real theta_; // Time integration factor |
| 42 |
Real cx_, cy_; // Cylinder center |
| 43 |
Real r_; // Cylinder radius |
| 44 |
bool useParametricControl_; |
| 45 |
bool useParabolicInflow_; |
| 46 |
bool useNonPenetratingWalls_; |
| 47 |
|
| 48 |
ROL::Ptr<FieldHelper<Real> > fieldHelper_; |
| 49 |
|
| 50 |
public: |
| 51 |
DynamicPDE_NavierStokes(Teuchos::ParameterList &parlist) { |
| 52 |
pde_ = ROL::makePtr<PDE_NavierStokes<Real>>(parlist); |
| 53 |
// Problem data |
| 54 |
theta_ = parlist.sublist("Time Discretization").get("Theta", 1.0); |
| 55 |
useParametricControl_ = parlist.sublist("Problem").get("Use Parametric Control", false); |
| 56 |
useParabolicInflow_ = parlist.sublist("Problem").get("Use Parabolic Inflow", true); |
| 57 |
useNonPenetratingWalls_ = parlist.sublist("Problem").get("Use Non-Penetrating Walls", false); |
| 58 |
cx_ = parlist.sublist("Problem").get("Cylinder Center X", 0.0); |
| 59 |
cy_ = parlist.sublist("Problem").get("Cylinder Center Y", 0.0); |
| 60 |
r_ = parlist.sublist("Problem").get("Cylinder Radius", 0.5); |
| 61 |
} |
| 62 |
|
| 63 |
void residual(ROL::Ptr<Intrepid::FieldContainer<Real>> & res, |
| 64 |
const ROL::TimeStamp<Real> & ts, |
| 65 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & uo_coeff, |
| 66 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & un_coeff, |
| 67 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 68 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 69 |
const Real one(1); |
| 70 |
// GET DIMENSIONS |
| 71 |
int c = feVel_->gradN()->dimension(0); |
| 72 |
int fv = feVel_->gradN()->dimension(1); |
| 73 |
int p = feVel_->gradN()->dimension(2); |
| 74 |
int d = feVel_->gradN()->dimension(3); |
| 75 |
// GET TIME STEP INFORMATION |
| 76 |
Real told = ts.t[0], tnew = ts.t[1], dt = tnew-told; |
| 77 |
// INITIALIZE STORAGE |
| 78 |
ROL::Ptr<Intrepid::FieldContainer<Real>> r1, r2; |
| 79 |
Intrepid::FieldContainer<Real> velX_res(c, fv), velY_res(c, fv); |
| 80 |
ROL::Ptr<Intrepid::FieldContainer<Real>> valVelX_eval, valVelY_eval; |
| 81 |
std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> U, Z, R; |
| 82 |
// COMPUTE STEADY RESIDUAL |
| 83 |
pde_->setTime(told); |
| 84 |
pde_->residual(r1,uo_coeff,z_coeff,z_param); |
| 85 |
Intrepid::RealSpaceTools<Real>::scale(*r1, (one-theta_)*dt); |
| 86 |
pde_->setTime(tnew); |
| 87 |
pde_->residual(r2,un_coeff,z_coeff,z_param); |
| 88 |
Intrepid::RealSpaceTools<Real>::scale(*r2, theta_*dt); |
| 89 |
Intrepid::RealSpaceTools<Real>::add(*r1, *r2); |
| 90 |
fieldHelper_->splitFieldCoeff(R, r1); |
| 91 |
// Integrate Uold * N |
| 92 |
valVelX_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 93 |
valVelY_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 94 |
fieldHelper_->splitFieldCoeff(U, uo_coeff); |
| 95 |
feVel_->evaluateValue(valVelX_eval, U[0]); |
| 96 |
feVel_->evaluateValue(valVelY_eval, U[1]); |
| 97 |
Intrepid::FunctionSpaceTools::integrate<Real>(velX_res, |
| 98 |
*valVelX_eval, // UX |
| 99 |
*(feVel_->NdetJ()), // Phi |
| 100 |
Intrepid::COMP_CPP, |
| 101 |
false); |
| 102 |
Intrepid::FunctionSpaceTools::integrate<Real>(velY_res, |
| 103 |
*valVelY_eval, // UY |
| 104 |
*(feVel_->NdetJ()), // Phi |
| 105 |
Intrepid::COMP_CPP, |
| 106 |
false); |
| 107 |
Intrepid::RealSpaceTools<Real>::subtract(*R[0], velX_res); |
| 108 |
Intrepid::RealSpaceTools<Real>::subtract(*R[1], velY_res); |
| 109 |
// Integrate Uold * N |
| 110 |
valVelX_eval->initialize(); |
| 111 |
valVelY_eval->initialize(); |
| 112 |
fieldHelper_->splitFieldCoeff(U, un_coeff); |
| 113 |
feVel_->evaluateValue(valVelX_eval, U[0]); |
| 114 |
feVel_->evaluateValue(valVelY_eval, U[1]); |
| 115 |
Intrepid::FunctionSpaceTools::integrate<Real>(velX_res, |
| 116 |
*valVelX_eval, // UX |
| 117 |
*(feVel_->NdetJ()), // Phi |
| 118 |
Intrepid::COMP_CPP, |
| 119 |
false); |
| 120 |
Intrepid::FunctionSpaceTools::integrate<Real>(velY_res, |
| 121 |
*valVelY_eval, // UY |
| 122 |
*(feVel_->NdetJ()), // Phi |
| 123 |
Intrepid::COMP_CPP, |
| 124 |
false); |
| 125 |
Intrepid::RealSpaceTools<Real>::add(*R[0], velX_res); |
| 126 |
Intrepid::RealSpaceTools<Real>::add(*R[1], velY_res); |
| 127 |
// Apply boundary conditions |
| 128 |
int numSideSets = bdryCellLocIds_.size(); |
| 129 |
Real bv(0); |
| 130 |
if (numSideSets > 0) { |
| 131 |
// APPLY DIRICHLET CONDITIONS |
| 132 |
for (int i = 0; i < numSideSets; ++i) { |
| 133 |
// Apply dirichlet conditions on inflow, top and bottom wall |
| 134 |
if (i==0 || i==2) { |
| 135 |
int numLocalSideIds = bdryCellLocIds_[i].size(); |
| 136 |
for (int j = 0; j < numLocalSideIds; ++j) { |
| 137 |
int numCellsSide = bdryCellLocIds_[i][j].size(); |
| 138 |
int numBdryDofs = fvidx_[j].size(); |
| 139 |
for (int k = 0; k < numCellsSide; ++k) { |
| 140 |
int cidx = bdryCellLocIds_[i][j][k]; |
| 141 |
for (int l = 0; l < numBdryDofs; ++l) { |
| 142 |
if (useNonPenetratingWalls_) { |
| 143 |
(*R[1])(cidx,fvidx_[j][l]) = (*U[1])(cidx,fvidx_[j][l]); |
| 144 |
} |
| 145 |
else { |
| 146 |
for (int m=0; m < d; ++m) { |
| 147 |
bv = (*bdryCellDofValues_[i][j])(k,fvidx_[j][l],m); |
| 148 |
(*R[m])(cidx,fvidx_[j][l]) = (*U[m])(cidx,fvidx_[j][l]) - bv; |
| 149 |
} |
| 150 |
} |
| 151 |
} |
| 152 |
} |
| 153 |
} |
| 154 |
} |
| 155 |
// Apply dirichlet conditions on inflow, top and bottom wall |
| 156 |
if (i==3) { |
| 157 |
int numLocalSideIds = bdryCellLocIds_[i].size(); |
| 158 |
for (int j = 0; j < numLocalSideIds; ++j) { |
| 159 |
int numCellsSide = bdryCellLocIds_[i][j].size(); |
| 160 |
int numBdryDofs = fvidx_[j].size(); |
| 161 |
for (int k = 0; k < numCellsSide; ++k) { |
| 162 |
int cidx = bdryCellLocIds_[i][j][k]; |
| 163 |
for (int l = 0; l < numBdryDofs; ++l) { |
| 164 |
for (int m=0; m < d; ++m) { |
| 165 |
bv = (*bdryCellDofValues_[i][j])(k,fvidx_[j][l],m); |
| 166 |
(*R[m])(cidx,fvidx_[j][l]) = (*U[m])(cidx,fvidx_[j][l]) - bv; |
| 167 |
} |
| 168 |
} |
| 169 |
} |
| 170 |
} |
| 171 |
} |
| 172 |
// Apply Dirichlet control on cylinder |
| 173 |
if (i==4) { |
| 174 |
if (!useParametricControl_) { |
| 175 |
fieldHelper_->splitFieldCoeff(Z, z_coeff); |
| 176 |
} |
| 177 |
int numLocalSideIds = bdryCellLocIds_[i].size(); |
| 178 |
for (int j = 0; j < numLocalSideIds; ++j) { |
| 179 |
int numCellsSide = bdryCellLocIds_[i][j].size(); |
| 180 |
int numBdryDofs = fvidx_[j].size(); |
| 181 |
for (int k = 0; k < numCellsSide; ++k) { |
| 182 |
int cidx = bdryCellLocIds_[i][j][k]; |
| 183 |
for (int l = 0; l < numBdryDofs; ++l) { |
| 184 |
for (int m=0; m < d; ++m) { |
| 185 |
if (!useParametricControl_) { |
| 186 |
(*R[m])(cidx,fvidx_[j][l]) = (*U[m])(cidx,fvidx_[j][l]) - (*Z[m])(cidx,fvidx_[j][l]); |
| 187 |
} |
| 188 |
else { |
| 189 |
bv = (*bdryCellDofValues_[i][j])(k,fvidx_[j][l],m); |
| 190 |
(*R[m])(cidx,fvidx_[j][l]) = (*U[m])(cidx,fvidx_[j][l]) - (*z_param)[0] * bv; |
| 191 |
} |
| 192 |
} |
| 193 |
} |
| 194 |
} |
| 195 |
} |
| 196 |
} |
| 197 |
} |
| 198 |
} |
| 199 |
// Combine the residuals. |
| 200 |
fieldHelper_->combineFieldCoeff(res, R); |
| 201 |
} |
| 202 |
|
| 203 |
void Jacobian_uo(ROL::Ptr<Intrepid::FieldContainer<Real>> & jac, |
| 204 |
const ROL::TimeStamp<Real> & ts, |
| 205 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & uo_coeff, |
| 206 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & un_coeff, |
| 207 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 208 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 209 |
const Real zero(0), one(1); |
| 210 |
// GET DIMENSIONS |
| 211 |
int c = feVel_->gradN()->dimension(0); |
| 212 |
int fv = feVel_->gradN()->dimension(1); |
| 213 |
int fp = fePrs_->gradN()->dimension(1); |
| 214 |
int d = feVel_->gradN()->dimension(3); |
| 215 |
// GET TIME STEP INFORMATION |
| 216 |
Real told = ts.t[0], tnew = ts.t[1], dt = tnew-told; |
| 217 |
// INITIALIZE STORAGE |
| 218 |
ROL::Ptr<Intrepid::FieldContainer<Real>> j; |
| 219 |
Intrepid::FieldContainer<Real> velX_jac(c, fv, fv), velY_jac(c, fv, fv); |
| 220 |
std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>>> J; |
| 221 |
// COMPUTE STEADY RESIDUAL |
| 222 |
pde_->setTime(told); |
| 223 |
pde_->Jacobian_1(j,uo_coeff,z_coeff,z_param); |
| 224 |
Intrepid::RealSpaceTools<Real>::scale(*j, (one-theta_)*dt); |
| 225 |
fieldHelper_->splitFieldCoeff(J, j); |
| 226 |
// Integrate Uold * N |
| 227 |
Intrepid::FunctionSpaceTools::integrate<Real>(velX_jac, |
| 228 |
*(feVel_->N()), // Phi |
| 229 |
*(feVel_->NdetJ()), // Phi |
| 230 |
Intrepid::COMP_CPP, |
| 231 |
false); |
| 232 |
Intrepid::FunctionSpaceTools::integrate<Real>(velY_jac, |
| 233 |
*(feVel_->N()), // Phi |
| 234 |
*(feVel_->NdetJ()), // Phi |
| 235 |
Intrepid::COMP_CPP, |
| 236 |
false); |
| 237 |
Intrepid::RealSpaceTools<Real>::subtract(*J[0][0], velX_jac); |
| 238 |
Intrepid::RealSpaceTools<Real>::subtract(*J[1][1], velY_jac); |
| 239 |
// APPLY BOUNDARY CONDITIONS |
| 240 |
int numSideSets = bdryCellLocIds_.size(); |
| 241 |
if (numSideSets > 0) { |
| 242 |
for (int i = 0; i < numSideSets; ++i) { |
| 243 |
if (i==0 || i==2) { |
| 244 |
int numLocalSideIds = bdryCellLocIds_[i].size(); |
| 245 |
for (int j = 0; j < numLocalSideIds; ++j) { |
| 246 |
int numCellsSide = bdryCellLocIds_[i][j].size(); |
| 247 |
int numBdryDofs = fvidx_[j].size(); |
| 248 |
for (int k = 0; k < numCellsSide; ++k) { |
| 249 |
int cidx = bdryCellLocIds_[i][j][k]; |
| 250 |
for (int l = 0; l < numBdryDofs; ++l) { |
| 251 |
for (int m=0; m < fv; ++m) { |
| 252 |
if (useNonPenetratingWalls_) { |
| 253 |
for (int p=0; p < d; ++p) { |
| 254 |
(*J[1][p])(cidx,fvidx_[j][l],m) = zero; |
| 255 |
} |
| 256 |
} |
| 257 |
else { |
| 258 |
for (int n=0; n < d; ++n) { |
| 259 |
for (int p=0; p < d; ++p) { |
| 260 |
(*J[n][p])(cidx,fvidx_[j][l],m) = zero; |
| 261 |
} |
| 262 |
} |
| 263 |
} |
| 264 |
} |
| 265 |
for (int m=0; m < fp; ++m) { |
| 266 |
if (useNonPenetratingWalls_) { |
| 267 |
(*J[1][2])(cidx,fvidx_[j][l],m) = zero; |
| 268 |
} |
| 269 |
else { |
| 270 |
for (int n=0; n < d; ++n) { |
| 271 |
(*J[n][2])(cidx,fvidx_[j][l],m) = zero; |
| 272 |
} |
| 273 |
} |
| 274 |
} |
| 275 |
} |
| 276 |
} |
| 277 |
} |
| 278 |
} |
| 279 |
if (i==3 || i==4) { |
| 280 |
int numLocalSideIds = bdryCellLocIds_[i].size(); |
| 281 |
for (int j = 0; j < numLocalSideIds; ++j) { |
| 282 |
int numCellsSide = bdryCellLocIds_[i][j].size(); |
| 283 |
int numBdryDofs = fvidx_[j].size(); |
| 284 |
for (int k = 0; k < numCellsSide; ++k) { |
| 285 |
int cidx = bdryCellLocIds_[i][j][k]; |
| 286 |
for (int l = 0; l < numBdryDofs; ++l) { |
| 287 |
for (int m=0; m < fv; ++m) { |
| 288 |
for (int n=0; n < d; ++n) { |
| 289 |
for (int p=0; p < d; ++p) { |
| 290 |
(*J[n][p])(cidx,fvidx_[j][l],m) = zero; |
| 291 |
} |
| 292 |
} |
| 293 |
} |
| 294 |
for (int m=0; m < fp; ++m) { |
| 295 |
for (int n=0; n < d; ++n) { |
| 296 |
(*J[n][2])(cidx,fvidx_[j][l],m) = zero; |
| 297 |
} |
| 298 |
} |
| 299 |
} |
| 300 |
} |
| 301 |
} |
| 302 |
} |
| 303 |
} |
| 304 |
} |
| 305 |
// Combine the Jacobians. |
| 306 |
fieldHelper_->combineFieldCoeff(jac, J); |
| 307 |
} |
| 308 |
|
| 309 |
void Jacobian_un(ROL::Ptr<Intrepid::FieldContainer<Real>> & jac, |
| 310 |
const ROL::TimeStamp<Real> & ts, |
| 311 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & uo_coeff, |
| 312 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & un_coeff, |
| 313 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 314 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 315 |
const Real zero(0), one(1); |
| 316 |
// GET DIMENSIONS |
| 317 |
int c = feVel_->gradN()->dimension(0); |
| 318 |
int fv = feVel_->gradN()->dimension(1); |
| 319 |
int fp = fePrs_->gradN()->dimension(1); |
| 320 |
int d = feVel_->gradN()->dimension(3); |
| 321 |
// GET TIME STEP INFORMATION |
| 322 |
Real told = ts.t[0], tnew = ts.t[1], dt = tnew-told; |
| 323 |
// INITIALIZE STORAGE |
| 324 |
ROL::Ptr<Intrepid::FieldContainer<Real>> j; |
| 325 |
Intrepid::FieldContainer<Real> velX_jac(c, fv, fv), velY_jac(c, fv, fv); |
| 326 |
std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>>> J; |
| 327 |
// COMPUTE STEADY RESIDUAL |
| 328 |
pde_->setTime(tnew); |
| 329 |
pde_->Jacobian_1(j,un_coeff,z_coeff,z_param); |
| 330 |
Intrepid::RealSpaceTools<Real>::scale(*j, theta_*dt); |
| 331 |
fieldHelper_->splitFieldCoeff(J, j); |
| 332 |
// Integrate Uold * N |
| 333 |
Intrepid::FunctionSpaceTools::integrate<Real>(velX_jac, |
| 334 |
*(feVel_->N()), // Phi |
| 335 |
*(feVel_->NdetJ()), // Phi |
| 336 |
Intrepid::COMP_CPP, |
| 337 |
false); |
| 338 |
Intrepid::FunctionSpaceTools::integrate<Real>(velY_jac, |
| 339 |
*(feVel_->N()), // Phi |
| 340 |
*(feVel_->NdetJ()), // Phi |
| 341 |
Intrepid::COMP_CPP, |
| 342 |
false); |
| 343 |
Intrepid::RealSpaceTools<Real>::add(*J[0][0], velX_jac); |
| 344 |
Intrepid::RealSpaceTools<Real>::add(*J[1][1], velY_jac); |
| 345 |
// APPLY BOUNDARY CONDITIONS |
| 346 |
int numSideSets = bdryCellLocIds_.size(); |
| 347 |
if (numSideSets > 0) { |
| 348 |
for (int i = 0; i < numSideSets; ++i) { |
| 349 |
if (i==0 || i==2) { |
| 350 |
int numLocalSideIds = bdryCellLocIds_[i].size(); |
| 351 |
for (int j = 0; j < numLocalSideIds; ++j) { |
| 352 |
int numCellsSide = bdryCellLocIds_[i][j].size(); |
| 353 |
int numBdryDofs = fvidx_[j].size(); |
| 354 |
for (int k = 0; k < numCellsSide; ++k) { |
| 355 |
int cidx = bdryCellLocIds_[i][j][k]; |
| 356 |
for (int l = 0; l < numBdryDofs; ++l) { |
| 357 |
for (int m=0; m < fv; ++m) { |
| 358 |
if (useNonPenetratingWalls_) { |
| 359 |
for (int p=0; p < d; ++p) { |
| 360 |
(*J[1][p])(cidx,fvidx_[j][l],m) = zero; |
| 361 |
} |
| 362 |
(*J[1][1])(cidx,fvidx_[j][l],fvidx_[j][l]) = one; |
| 363 |
} |
| 364 |
else { |
| 365 |
for (int n=0; n < d; ++n) { |
| 366 |
for (int p=0; p < d; ++p) { |
| 367 |
(*J[n][p])(cidx,fvidx_[j][l],m) = zero; |
| 368 |
} |
| 369 |
(*J[n][n])(cidx,fvidx_[j][l],fvidx_[j][l]) = one; |
| 370 |
} |
| 371 |
} |
| 372 |
} |
| 373 |
for (int m=0; m < fp; ++m) { |
| 374 |
if (useNonPenetratingWalls_) { |
| 375 |
(*J[1][2])(cidx,fvidx_[j][l],m) = zero; |
| 376 |
} |
| 377 |
else { |
| 378 |
for (int n=0; n < d; ++n) { |
| 379 |
(*J[n][2])(cidx,fvidx_[j][l],m) = zero; |
| 380 |
} |
| 381 |
} |
| 382 |
} |
| 383 |
} |
| 384 |
} |
| 385 |
} |
| 386 |
} |
| 387 |
if (i==3 || i==4) { |
| 388 |
int numLocalSideIds = bdryCellLocIds_[i].size(); |
| 389 |
for (int j = 0; j < numLocalSideIds; ++j) { |
| 390 |
int numCellsSide = bdryCellLocIds_[i][j].size(); |
| 391 |
int numBdryDofs = fvidx_[j].size(); |
| 392 |
for (int k = 0; k < numCellsSide; ++k) { |
| 393 |
int cidx = bdryCellLocIds_[i][j][k]; |
| 394 |
for (int l = 0; l < numBdryDofs; ++l) { |
| 395 |
for (int m=0; m < fv; ++m) { |
| 396 |
for (int n=0; n < d; ++n) { |
| 397 |
for (int p=0; p < d; ++p) { |
| 398 |
(*J[n][p])(cidx,fvidx_[j][l],m) = zero; |
| 399 |
} |
| 400 |
(*J[n][n])(cidx,fvidx_[j][l],fvidx_[j][l]) = one; |
| 401 |
} |
| 402 |
} |
| 403 |
for (int m=0; m < fp; ++m) { |
| 404 |
for (int n=0; n < d; ++n) { |
| 405 |
(*J[n][2])(cidx,fvidx_[j][l],m) = zero; |
| 406 |
} |
| 407 |
} |
| 408 |
} |
| 409 |
} |
| 410 |
} |
| 411 |
} |
| 412 |
} |
| 413 |
} |
| 414 |
// Combine the Jacobians. |
| 415 |
fieldHelper_->combineFieldCoeff(jac, J); |
| 416 |
} |
| 417 |
|
| 418 |
void Jacobian_zf(ROL::Ptr<Intrepid::FieldContainer<Real>> & jac, |
| 419 |
const ROL::TimeStamp<Real> & ts, |
| 420 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & uo_coeff, |
| 421 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & un_coeff, |
| 422 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 423 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 424 |
if (!useParametricControl_) { |
| 425 |
const Real one(1); |
| 426 |
// GET DIMENSIONS |
| 427 |
int d = feVel_->gradN()->dimension(3); |
| 428 |
// INITILAIZE JACOBIAN |
| 429 |
pde_->Jacobian_2(jac,uo_coeff,z_coeff,z_param); // Resizes and zeros jac |
| 430 |
std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>>> J; |
| 431 |
fieldHelper_->splitFieldCoeff(J, jac); |
| 432 |
// APPLY DIRICHLET CONDITIONS |
| 433 |
int numSideSets = bdryCellLocIds_.size(); |
| 434 |
if (numSideSets > 0) { |
| 435 |
for (int i = 0; i < numSideSets; ++i) { |
| 436 |
if (i==4) { |
| 437 |
int numLocalSideIds = bdryCellLocIds_[i].size(); |
| 438 |
for (int j = 0; j < numLocalSideIds; ++j) { |
| 439 |
int numCellsSide = bdryCellLocIds_[i][j].size(); |
| 440 |
int numBdryDofs = fvidx_[j].size(); |
| 441 |
for (int k = 0; k < numCellsSide; ++k) { |
| 442 |
int cidx = bdryCellLocIds_[i][j][k]; |
| 443 |
for (int l = 0; l < numBdryDofs; ++l) { |
| 444 |
for (int m=0; m < d; ++m) { |
| 445 |
(*J[m][m])(cidx,fvidx_[j][l],fvidx_[j][l]) = -one; |
| 446 |
} |
| 447 |
} |
| 448 |
} |
| 449 |
} |
| 450 |
} |
| 451 |
} |
| 452 |
} |
| 453 |
// Combine the jacobians. |
| 454 |
fieldHelper_->combineFieldCoeff(jac, J); |
| 455 |
} |
| 456 |
else { |
| 457 |
throw Exception::Zero(">>> (PDE_NavierStokes::Jacobian_zf): Jacobian is zero."); |
| 458 |
} |
| 459 |
} |
| 460 |
|
| 461 |
void Jacobian_zp(std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> & jac, |
| 462 |
const ROL::TimeStamp<Real> & ts, |
| 463 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & uo_coeff, |
| 464 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & un_coeff, |
| 465 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 466 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 467 |
if (useParametricControl_) { |
| 468 |
// GET DIMENSIONS |
| 469 |
int d = feVel_->gradN()->dimension(3); |
| 470 |
// INITILAIZE JACOBIAN |
| 471 |
pde_->Jacobian_3(jac,uo_coeff,z_coeff,z_param); // Resizes and zeros jac |
| 472 |
std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> J; |
| 473 |
fieldHelper_->splitFieldCoeff(J, jac[0]); |
| 474 |
// APPLY DIRICHLET CONDITIONS |
| 475 |
int numSideSets = bdryCellLocIds_.size(); |
| 476 |
if (numSideSets > 0) { |
| 477 |
for (int i = 0; i < numSideSets; ++i) { |
| 478 |
// Apply Dirichlet controls |
| 479 |
if (i==4) { |
| 480 |
Real bv(0); |
| 481 |
int numLocalSideIds = bdryCellLocIds_[i].size(); |
| 482 |
for (int j = 0; j < numLocalSideIds; ++j) { |
| 483 |
int numCellsSide = bdryCellLocIds_[i][j].size(); |
| 484 |
int numBdryDofs = fvidx_[j].size(); |
| 485 |
for (int k = 0; k < numCellsSide; ++k) { |
| 486 |
int cidx = bdryCellLocIds_[i][j][k]; |
| 487 |
for (int l = 0; l < numBdryDofs; ++l) { |
| 488 |
for (int m=0; m < d; ++m) { |
| 489 |
bv = (*bdryCellDofValues_[i][j])(k,fvidx_[j][l],m); |
| 490 |
(*J[m])(cidx,fvidx_[j][l]) = -bv; |
| 491 |
} |
| 492 |
} |
| 493 |
} |
| 494 |
} |
| 495 |
} |
| 496 |
} |
| 497 |
} |
| 498 |
// Combine the jacobians. |
| 499 |
fieldHelper_->combineFieldCoeff(jac[0], J); |
| 500 |
} |
| 501 |
else { |
| 502 |
throw Exception::Zero(">>> (PDE_NavierStokes::Jacobian_zp): Jacobian is zero."); |
| 503 |
} |
| 504 |
} |
| 505 |
|
| 506 |
void Hessian_uo_uo(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess, |
| 507 |
const ROL::TimeStamp<Real> & ts, |
| 508 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff, |
| 509 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & uo_coeff, |
| 510 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & un_coeff, |
| 511 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 512 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 513 |
const Real zero(0), one(1); |
| 514 |
// GET DIMENSIONS |
| 515 |
int d = feVel_->gradN()->dimension(3); |
| 516 |
// GET TIME STEP INFORMATION |
| 517 |
Real told = ts.t[0], tnew = ts.t[1], dt = tnew-told; |
| 518 |
// Split u_coeff into components. |
| 519 |
std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> L; |
| 520 |
ROL::Ptr<Intrepid::FieldContainer<Real>> l0_coeff; |
| 521 |
fieldHelper_->splitFieldCoeff(L, l_coeff); |
| 522 |
// Apply Dirichlet conditions |
| 523 |
int numSideSets = bdryCellLocIds_.size(); |
| 524 |
if (numSideSets > 0) { |
| 525 |
for (int i = 0; i < numSideSets; ++i) { |
| 526 |
if (i==0 || i==2) { |
| 527 |
int numLocalSideIds = bdryCellLocIds_[i].size(); |
| 528 |
for (int j = 0; j < numLocalSideIds; ++j) { |
| 529 |
int numCellsSide = bdryCellLocIds_[i][j].size(); |
| 530 |
int numBdryDofs = fvidx_[j].size(); |
| 531 |
for (int k = 0; k < numCellsSide; ++k) { |
| 532 |
int cidx = bdryCellLocIds_[i][j][k]; |
| 533 |
for (int l = 0; l < numBdryDofs; ++l) { |
| 534 |
if (useNonPenetratingWalls_) { |
| 535 |
(*L[1])(cidx,fvidx_[j][l]) = zero; |
| 536 |
} |
| 537 |
else { |
| 538 |
for (int m=0; m < d; ++m) { |
| 539 |
(*L[m])(cidx,fvidx_[j][l]) = zero; |
| 540 |
} |
| 541 |
} |
| 542 |
} |
| 543 |
} |
| 544 |
} |
| 545 |
} |
| 546 |
if (i==3 || i==4) { |
| 547 |
int numLocalSideIds = bdryCellLocIds_[i].size(); |
| 548 |
for (int j = 0; j < numLocalSideIds; ++j) { |
| 549 |
int numCellsSide = bdryCellLocIds_[i][j].size(); |
| 550 |
int numBdryDofs = fvidx_[j].size(); |
| 551 |
for (int k = 0; k < numCellsSide; ++k) { |
| 552 |
int cidx = bdryCellLocIds_[i][j][k]; |
| 553 |
for (int l = 0; l < numBdryDofs; ++l) { |
| 554 |
for (int m=0; m < d; ++m) { |
| 555 |
(*L[m])(cidx,fvidx_[j][l]) = zero; |
| 556 |
} |
| 557 |
} |
| 558 |
} |
| 559 |
} |
| 560 |
} |
| 561 |
} |
| 562 |
} |
| 563 |
fieldHelper_->combineFieldCoeff(l0_coeff, L); |
| 564 |
// COMPUTE STEADY RESIDUAL |
| 565 |
pde_->setTime(told); |
| 566 |
pde_->Hessian_11(hess,l0_coeff,uo_coeff,z_coeff,z_param); |
| 567 |
Intrepid::RealSpaceTools<Real>::scale(*hess, (one-theta_)*dt); |
| 568 |
} |
| 569 |
|
| 570 |
void Hessian_uo_un(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess, |
| 571 |
const ROL::TimeStamp<Real> & ts, |
| 572 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff, |
| 573 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & uo_coeff, |
| 574 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & un_coeff, |
| 575 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 576 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 577 |
throw Exception::Zero(">>> (PDE_NavierStokes::Hessian_uo_un): Hessian is zero."); |
| 578 |
} |
| 579 |
|
| 580 |
void Hessian_uo_zf(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess, |
| 581 |
const ROL::TimeStamp<Real> & ts, |
| 582 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff, |
| 583 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & uo_coeff, |
| 584 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & un_coeff, |
| 585 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 586 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 587 |
throw Exception::Zero(">>> (PDE_NavierStokes::Hessian_uo_zf): Hessian is zero."); |
| 588 |
} |
| 589 |
|
| 590 |
void Hessian_uo_zp(std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> & hess, |
| 591 |
const ROL::TimeStamp<Real> & ts, |
| 592 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff, |
| 593 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & uo_coeff, |
| 594 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & un_coeff, |
| 595 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 596 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 597 |
throw Exception::Zero(">>> (PDE_NavierStokes::Hessian_uo_zp): Hessian is zero."); |
| 598 |
} |
| 599 |
|
| 600 |
void Hessian_un_uo(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess, |
| 601 |
const ROL::TimeStamp<Real> & ts, |
| 602 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff, |
| 603 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & uo_coeff, |
| 604 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & un_coeff, |
| 605 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 606 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 607 |
throw Exception::Zero(">>> (PDE_NavierStokes::Hessian_un_uo): Hessian is zero."); |
| 608 |
} |
| 609 |
|
| 610 |
void Hessian_un_un(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess, |
| 611 |
const ROL::TimeStamp<Real> & ts, |
| 612 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff, |
| 613 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & uo_coeff, |
| 614 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & un_coeff, |
| 615 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 616 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 617 |
const Real zero(0); |
| 618 |
// GET DIMENSIONS |
| 619 |
int d = feVel_->gradN()->dimension(3); |
| 620 |
// GET TIME STEP INFORMATION |
| 621 |
Real told = ts.t[0], tnew = ts.t[1], dt = tnew-told; |
| 622 |
// Split u_coeff into components. |
| 623 |
std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> L; |
| 624 |
ROL::Ptr<Intrepid::FieldContainer<Real>> l0_coeff; |
| 625 |
fieldHelper_->splitFieldCoeff(L, l_coeff); |
| 626 |
// Apply Dirichlet conditions |
| 627 |
int numSideSets = bdryCellLocIds_.size(); |
| 628 |
if (numSideSets > 0) { |
| 629 |
for (int i = 0; i < numSideSets; ++i) { |
| 630 |
if (i==0 || i==2) { |
| 631 |
int numLocalSideIds = bdryCellLocIds_[i].size(); |
| 632 |
for (int j = 0; j < numLocalSideIds; ++j) { |
| 633 |
int numCellsSide = bdryCellLocIds_[i][j].size(); |
| 634 |
int numBdryDofs = fvidx_[j].size(); |
| 635 |
for (int k = 0; k < numCellsSide; ++k) { |
| 636 |
int cidx = bdryCellLocIds_[i][j][k]; |
| 637 |
for (int l = 0; l < numBdryDofs; ++l) { |
| 638 |
if (useNonPenetratingWalls_) { |
| 639 |
(*L[1])(cidx,fvidx_[j][l]) = zero; |
| 640 |
} |
| 641 |
else { |
| 642 |
for (int m=0; m < d; ++m) { |
| 643 |
(*L[m])(cidx,fvidx_[j][l]) = zero; |
| 644 |
} |
| 645 |
} |
| 646 |
} |
| 647 |
} |
| 648 |
} |
| 649 |
} |
| 650 |
if (i==3 || i==4) { |
| 651 |
int numLocalSideIds = bdryCellLocIds_[i].size(); |
| 652 |
for (int j = 0; j < numLocalSideIds; ++j) { |
| 653 |
int numCellsSide = bdryCellLocIds_[i][j].size(); |
| 654 |
int numBdryDofs = fvidx_[j].size(); |
| 655 |
for (int k = 0; k < numCellsSide; ++k) { |
| 656 |
int cidx = bdryCellLocIds_[i][j][k]; |
| 657 |
for (int l = 0; l < numBdryDofs; ++l) { |
| 658 |
for (int m=0; m < d; ++m) { |
| 659 |
(*L[m])(cidx,fvidx_[j][l]) = zero; |
| 660 |
} |
| 661 |
} |
| 662 |
} |
| 663 |
} |
| 664 |
} |
| 665 |
} |
| 666 |
} |
| 667 |
fieldHelper_->combineFieldCoeff(l0_coeff, L); |
| 668 |
// COMPUTE STEADY RESIDUAL |
| 669 |
pde_->setTime(told); |
| 670 |
pde_->Hessian_11(hess,l0_coeff,un_coeff,z_coeff,z_param); |
| 671 |
Intrepid::RealSpaceTools<Real>::scale(*hess, theta_*dt); |
| 672 |
} |
| 673 |
|
| 674 |
void Hessian_un_zf(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess, |
| 675 |
const ROL::TimeStamp<Real> & ts, |
| 676 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff, |
| 677 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & uo_coeff, |
| 678 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & un_coeff, |
| 679 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 680 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 681 |
throw Exception::Zero(">>> (PDE_NavierStokes::Hessian_un_zf): Hessian is zero."); |
| 682 |
} |
| 683 |
|
| 684 |
void Hessian_un_zp(std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> & hess, |
| 685 |
const ROL::TimeStamp<Real> & ts, |
| 686 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff, |
| 687 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & uo_coeff, |
| 688 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & un_coeff, |
| 689 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 690 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 691 |
throw Exception::Zero(">>> (PDE_NavierStokes::Hessian_un_zp): Hessian is zero."); |
| 692 |
} |
| 693 |
|
| 694 |
void Hessian_zf_uo(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess, |
| 695 |
const ROL::TimeStamp<Real> & ts, |
| 696 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff, |
| 697 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & uo_coeff, |
| 698 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & un_coeff, |
| 699 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 700 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 701 |
throw Exception::Zero(">>> (PDE_NavierStokes::Hessian_zf_uo): Hessian is zero."); |
| 702 |
} |
| 703 |
|
| 704 |
void Hessian_zf_un(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess, |
| 705 |
const ROL::TimeStamp<Real> & ts, |
| 706 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff, |
| 707 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & uo_coeff, |
| 708 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & un_coeff, |
| 709 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 710 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 711 |
throw Exception::Zero(">>> (PDE_NavierStokes::Hessian_zf_un): Hessian is zero."); |
| 712 |
} |
| 713 |
|
| 714 |
void Hessian_zf_zf(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess, |
| 715 |
const ROL::TimeStamp<Real> & ts, |
| 716 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff, |
| 717 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & uo_coeff, |
| 718 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & un_coeff, |
| 719 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 720 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 721 |
throw Exception::Zero(">>> (PDE_NavierStokes::Hessian_zf_zf): Hessian is zero."); |
| 722 |
} |
| 723 |
|
| 724 |
void Hessian_zf_zp(std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> & hess, |
| 725 |
const ROL::TimeStamp<Real> & ts, |
| 726 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff, |
| 727 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & uo_coeff, |
| 728 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & un_coeff, |
| 729 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 730 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 731 |
throw Exception::Zero(">>> (PDE_NavierStokes::Hessian_zf_zp): Hessian is zero."); |
| 732 |
} |
| 733 |
|
| 734 |
void Hessian_zp_uo(std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> & hess, |
| 735 |
const ROL::TimeStamp<Real> & ts, |
| 736 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff, |
| 737 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & uo_coeff, |
| 738 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & un_coeff, |
| 739 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 740 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 741 |
throw Exception::Zero(">>> (PDE_NavierStokes::Hessian_zp_uo): Hessian is zero."); |
| 742 |
} |
| 743 |
|
| 744 |
void Hessian_zp_un(std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> & hess, |
| 745 |
const ROL::TimeStamp<Real> & ts, |
| 746 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff, |
| 747 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & uo_coeff, |
| 748 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & un_coeff, |
| 749 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 750 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 751 |
throw Exception::Zero(">>> (PDE_NavierStokes::Hessian_zp_un): Hessian is zero."); |
| 752 |
} |
| 753 |
|
| 754 |
void Hessian_zp_zf(std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> & hess, |
| 755 |
const ROL::TimeStamp<Real> & ts, |
| 756 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff, |
| 757 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & uo_coeff, |
| 758 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & un_coeff, |
| 759 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 760 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 761 |
throw Exception::Zero(">>> (PDE_NavierStokes::Hessian_zp_zf): Hessian is zero."); |
| 762 |
} |
| 763 |
|
| 764 |
void Hessian_zp_zp(std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>>> & hess, |
| 765 |
const ROL::TimeStamp<Real> & ts, |
| 766 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff, |
| 767 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & uo_coeff, |
| 768 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & un_coeff, |
| 769 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 770 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 771 |
throw Exception::Zero(">>> (PDE_NavierStokes::Hessian_zp_zp): Hessian is zero."); |
| 772 |
} |
| 773 |
|
| 774 |
void RieszMap_1(ROL::Ptr<Intrepid::FieldContainer<Real>> & riesz) { |
| 775 |
pde_->RieszMap_1(riesz); |
| 776 |
} |
| 777 |
|
| 778 |
void RieszMap_2(ROL::Ptr<Intrepid::FieldContainer<Real>> & riesz) { |
| 779 |
pde_->RieszMap_2(riesz); |
| 780 |
} |
| 781 |
|
| 782 |
std::vector<ROL::Ptr<Intrepid::Basis<Real, Intrepid::FieldContainer<Real>>>> getFields() { |
| 783 |
return pde_->getFields(); |
| 784 |
} |
| 785 |
|
| 786 |
void setCellNodes(const ROL::Ptr<Intrepid::FieldContainer<Real>> &volCellNodes, |
| 787 |
const std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>>> &bdryCellNodes, |
| 788 |
const std::vector<std::vector<std::vector<int>>> &bdryCellLocIds) { |
| 789 |
pde_->setCellNodes(volCellNodes,bdryCellNodes,bdryCellLocIds); |
| 790 |
volCellNodes_ = volCellNodes; |
| 791 |
bdryCellNodes_ = bdryCellNodes; |
| 792 |
bdryCellLocIds_ = bdryCellLocIds; |
| 793 |
basisPtrs_ = pde_->getFields(); |
| 794 |
feVel_ = pde_->getVelocityFE(); |
| 795 |
fePrs_ = pde_->getPressureFE(); |
| 796 |
fvidx_ = feVel_->getBoundaryDofs(); |
| 797 |
fpidx_ = fePrs_->getBoundaryDofs(); |
| 798 |
computeDirichlet(); |
| 799 |
} |
| 800 |
|
| 801 |
void setFieldPattern(const std::vector<std::vector<int>> &fieldPattern) { |
| 802 |
pde_->setFieldPattern(fieldPattern); |
| 803 |
fieldHelper_ = pde_->getFieldHelper(); |
| 804 |
} |
| 805 |
|
| 806 |
const ROL::Ptr<FE<Real>> getVelocityFE(void) const { |
| 807 |
return feVel_; |
| 808 |
} |
| 809 |
|
| 810 |
const ROL::Ptr<FE<Real>> getPressureFE(void) const { |
| 811 |
return fePrs_; |
| 812 |
} |
| 813 |
|
| 814 |
const ROL::Ptr<Intrepid::FieldContainer<Real> > getCellNodes(void) const { |
| 815 |
return pde_->getCellNodes(); |
| 816 |
} |
| 817 |
|
| 818 |
const std::vector<ROL::Ptr<FE<Real>>> getVelocityBdryFE(const int sideset = -1) const { |
| 819 |
return pde_->getVelocityBdryFE(sideset); |
| 820 |
} |
| 821 |
|
| 822 |
const std::vector<std::vector<int>> getBdryCellLocIds(const int sideset = -1) const { |
| 823 |
int side = (sideset < 0 ? 4 : sideset); |
| 824 |
return bdryCellLocIds_[side]; |
| 825 |
} |
| 826 |
|
| 827 |
const ROL::Ptr<FieldHelper<Real>> getFieldHelper(void) const { |
| 828 |
return fieldHelper_; |
| 829 |
} |
| 830 |
|
| 831 |
private: |
| 832 |
Real DirichletFunc(const std::vector<Real> & coords, int sideset, int locSideId, int dir) const { |
| 833 |
const Real one(1), two(2); |
| 834 |
const Real x = coords[0], y = coords[1]; |
| 835 |
Real val(0); |
| 836 |
if ((sideset!=4) && (dir==0)) { |
| 837 |
val = (useParabolicInflow_ ? (two + y) * (two - y) : one); |
| 838 |
} |
| 839 |
if (sideset==4) { |
| 840 |
Real tx = y-cy_, ty = cx_-x; |
| 841 |
val = (dir==0 ? tx : ty)/r_; |
| 842 |
} |
| 843 |
return val; |
| 844 |
} |
| 845 |
|
| 846 |
void computeDirichlet(void) { |
| 847 |
// Compute Dirichlet values at DOFs. |
| 848 |
int d = basisPtrs_[0]->getBaseCellTopology().getDimension(); |
| 849 |
int numSidesets = bdryCellLocIds_.size(); |
| 850 |
bdryCellDofValues_.resize(numSidesets); |
| 851 |
for (int i=0; i<numSidesets; ++i) { |
| 852 |
int numLocSides = bdryCellLocIds_[i].size(); |
| 853 |
bdryCellDofValues_[i].resize(numLocSides); |
| 854 |
for (int j=0; j<numLocSides; ++j) { |
| 855 |
int c = bdryCellLocIds_[i][j].size(); |
| 856 |
int f = basisPtrs_[0]->getCardinality(); |
| 857 |
bdryCellDofValues_[i][j] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, d); |
| 858 |
ROL::Ptr<Intrepid::FieldContainer<Real> > coords = |
| 859 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, d); |
| 860 |
if (c > 0) { |
| 861 |
feVel_->computeDofCoords(coords, bdryCellNodes_[i][j]); |
| 862 |
} |
| 863 |
for (int k=0; k<c; ++k) { |
| 864 |
for (int l=0; l<f; ++l) { |
| 865 |
std::vector<Real> dofpoint(d); |
| 866 |
for (int m=0; m<d; ++m) { |
| 867 |
dofpoint[m] = (*coords)(k, l, m); |
| 868 |
} |
| 869 |
for (int m=0; m<d; ++m) { |
| 870 |
(*bdryCellDofValues_[i][j])(k, l, m) = DirichletFunc(dofpoint, i, j, m); |
| 871 |
} |
| 872 |
} |
| 873 |
} |
| 874 |
} |
| 875 |
} |
| 876 |
} |
| 877 |
}; // DynamicPDE_NavierStokes |
| 878 |
|
| 879 |
#endif |