| 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_navier-stokes.hpp |
| 11 |
\brief Implements the local PDE interface for the Navier-Stokes control problem. |
| 12 |
*/ |
| 13 |
|
| 14 |
#ifndef STEADYPDE_DYNAMIC_NAVIERSTOKES_HPP |
| 15 |
#define STEADYPDE_DYNAMIC_NAVIERSTOKES_HPP |
| 16 |
|
| 17 |
#include "pde_navier-stokes.hpp" |
| 18 |
|
| 19 |
template <class Real> |
| 20 |
class SteadyPDE_NavierStokes : public PDE<Real> { |
| 21 |
private: |
| 22 |
// Cell node information |
| 23 |
std::vector<std::vector<std::vector<int>>> bdryCellLocIds_; |
| 24 |
std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>>> bdryCellNodes_; |
| 25 |
// Coordinates of degrees freedom on boundary cells. |
| 26 |
// Indexing: [sideset number][local side id](cell number, value at dof) |
| 27 |
std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>>> bdryCellDofValues_; |
| 28 |
// Finite element definition |
| 29 |
ROL::Ptr<FE<Real>> feVel_; |
| 30 |
ROL::Ptr<FE<Real>> fePrs_; |
| 31 |
// Local degrees of freedom on boundary, for each side of the reference cell (first index). |
| 32 |
std::vector<std::vector<int>> fvidx_; |
| 33 |
std::vector<std::vector<int>> fpidx_; |
| 34 |
// Field pattern, offsets, etc. |
| 35 |
ROL::Ptr<FieldHelper<Real>> fieldHelper_; |
| 36 |
|
| 37 |
ROL::Ptr<PDE_NavierStokes<Real>> pde_; |
| 38 |
|
| 39 |
Real cx_, cy_; // Cylinder center |
| 40 |
bool useParabolicInflow_; |
| 41 |
bool useNonPenetratingWalls_; |
| 42 |
|
| 43 |
public: |
| 44 |
SteadyPDE_NavierStokes(Teuchos::ParameterList &parlist) { |
| 45 |
pde_ = ROL::makePtr<PDE_NavierStokes<Real>>(parlist); |
| 46 |
useParabolicInflow_ = parlist.sublist("Problem").get("Use Parabolic Inflow", true); |
| 47 |
useNonPenetratingWalls_ = parlist.sublist("Problem").get("Use Non-Penetrating Walls", false); |
| 48 |
cx_ = static_cast<Real>(-3); |
| 49 |
cy_ = static_cast<Real>(0); |
| 50 |
} |
| 51 |
|
| 52 |
void residual(ROL::Ptr<Intrepid::FieldContainer<Real>> & res, |
| 53 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 54 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 55 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 56 |
int d = feVel_->gradN()->dimension(3); |
| 57 |
pde_->residual(res, u_coeff, z_coeff, z_param); |
| 58 |
std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> U, R; |
| 59 |
fieldHelper_->splitFieldCoeff(U, u_coeff); |
| 60 |
fieldHelper_->splitFieldCoeff(R, res); |
| 61 |
// Apply boundary conditions |
| 62 |
int numSideSets = bdryCellLocIds_.size(); |
| 63 |
Real bv(0); |
| 64 |
if (numSideSets > 0) { |
| 65 |
// APPLY DIRICHLET CONDITIONS |
| 66 |
for (int i = 0; i < numSideSets; ++i) { |
| 67 |
// Apply dirichlet conditions on inflow, top and bottom wall |
| 68 |
if (i==0 || i==2) { |
| 69 |
int numLocalSideIds = bdryCellLocIds_[i].size(); |
| 70 |
for (int j = 0; j < numLocalSideIds; ++j) { |
| 71 |
int numCellsSide = bdryCellLocIds_[i][j].size(); |
| 72 |
int numBdryDofs = fvidx_[j].size(); |
| 73 |
for (int k = 0; k < numCellsSide; ++k) { |
| 74 |
int cidx = bdryCellLocIds_[i][j][k]; |
| 75 |
for (int l = 0; l < numBdryDofs; ++l) { |
| 76 |
if (useNonPenetratingWalls_) { |
| 77 |
(*R[1])(cidx,fvidx_[j][l]) = (*U[1])(cidx,fvidx_[j][l]); |
| 78 |
} |
| 79 |
else { |
| 80 |
for (int m=0; m < d; ++m) { |
| 81 |
bv = (*bdryCellDofValues_[i][j])(k,fvidx_[j][l],m); |
| 82 |
(*R[m])(cidx,fvidx_[j][l]) = (*U[m])(cidx,fvidx_[j][l]) - bv; |
| 83 |
} |
| 84 |
} |
| 85 |
} |
| 86 |
} |
| 87 |
} |
| 88 |
} |
| 89 |
// Apply dirichlet conditions on inflow, top and bottom wall |
| 90 |
if (i==3) { |
| 91 |
int numLocalSideIds = bdryCellLocIds_[i].size(); |
| 92 |
for (int j = 0; j < numLocalSideIds; ++j) { |
| 93 |
int numCellsSide = bdryCellLocIds_[i][j].size(); |
| 94 |
int numBdryDofs = fvidx_[j].size(); |
| 95 |
for (int k = 0; k < numCellsSide; ++k) { |
| 96 |
int cidx = bdryCellLocIds_[i][j][k]; |
| 97 |
for (int l = 0; l < numBdryDofs; ++l) { |
| 98 |
for (int m=0; m < d; ++m) { |
| 99 |
bv = (*bdryCellDofValues_[i][j])(k,fvidx_[j][l],m); |
| 100 |
(*R[m])(cidx,fvidx_[j][l]) = (*U[m])(cidx,fvidx_[j][l]) - bv; |
| 101 |
} |
| 102 |
} |
| 103 |
} |
| 104 |
} |
| 105 |
} |
| 106 |
// Apply Dirichlet control on cylinder |
| 107 |
if (i==4) { |
| 108 |
Real omega(0); |
| 109 |
int numLocalSideIds = bdryCellLocIds_[i].size(); |
| 110 |
for (int j = 0; j < numLocalSideIds; ++j) { |
| 111 |
int numCellsSide = bdryCellLocIds_[i][j].size(); |
| 112 |
int numBdryDofs = fvidx_[j].size(); |
| 113 |
for (int k = 0; k < numCellsSide; ++k) { |
| 114 |
int cidx = bdryCellLocIds_[i][j][k]; |
| 115 |
for (int l = 0; l < numBdryDofs; ++l) { |
| 116 |
for (int m=0; m < d; ++m) { |
| 117 |
(*R[m])(cidx,fvidx_[j][l]) = (*U[m])(cidx,fvidx_[j][l]); |
| 118 |
} |
| 119 |
} |
| 120 |
} |
| 121 |
} |
| 122 |
} |
| 123 |
} |
| 124 |
} |
| 125 |
// Combine the residuals. |
| 126 |
fieldHelper_->combineFieldCoeff(res, R); |
| 127 |
} |
| 128 |
|
| 129 |
void Jacobian_1(ROL::Ptr<Intrepid::FieldContainer<Real>> & jac, |
| 130 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 131 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 132 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 133 |
const Real zero(0), one(1); |
| 134 |
int fv = feVel_->gradN()->dimension(1); |
| 135 |
int fp = fePrs_->gradN()->dimension(1); |
| 136 |
int d = feVel_->gradN()->dimension(3); |
| 137 |
pde_->Jacobian_1(jac, u_coeff, z_coeff, z_param); |
| 138 |
std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>>> J; |
| 139 |
fieldHelper_->splitFieldCoeff(J, jac); |
| 140 |
// APPLY BOUNDARY CONDITIONS |
| 141 |
int numSideSets = bdryCellLocIds_.size(); |
| 142 |
if (numSideSets > 0) { |
| 143 |
for (int i = 0; i < numSideSets; ++i) { |
| 144 |
if (i==0 || i==2) { |
| 145 |
int numLocalSideIds = bdryCellLocIds_[i].size(); |
| 146 |
for (int j = 0; j < numLocalSideIds; ++j) { |
| 147 |
int numCellsSide = bdryCellLocIds_[i][j].size(); |
| 148 |
int numBdryDofs = fvidx_[j].size(); |
| 149 |
for (int k = 0; k < numCellsSide; ++k) { |
| 150 |
int cidx = bdryCellLocIds_[i][j][k]; |
| 151 |
for (int l = 0; l < numBdryDofs; ++l) { |
| 152 |
for (int m=0; m < fv; ++m) { |
| 153 |
if (useNonPenetratingWalls_) { |
| 154 |
for (int p=0; p < d; ++p) { |
| 155 |
(*J[1][p])(cidx,fvidx_[j][l],m) = zero; |
| 156 |
} |
| 157 |
(*J[1][1])(cidx,fvidx_[j][l],fvidx_[j][l]) = one; |
| 158 |
} |
| 159 |
else { |
| 160 |
for (int n=0; n < d; ++n) { |
| 161 |
for (int p=0; p < d; ++p) { |
| 162 |
(*J[n][p])(cidx,fvidx_[j][l],m) = zero; |
| 163 |
} |
| 164 |
(*J[n][n])(cidx,fvidx_[j][l],fvidx_[j][l]) = one; |
| 165 |
} |
| 166 |
} |
| 167 |
} |
| 168 |
for (int m=0; m < fp; ++m) { |
| 169 |
if (useNonPenetratingWalls_) { |
| 170 |
(*J[1][2])(cidx,fvidx_[j][l],m) = zero; |
| 171 |
} |
| 172 |
else { |
| 173 |
for (int n=0; n < d; ++n) { |
| 174 |
(*J[n][2])(cidx,fvidx_[j][l],m) = zero; |
| 175 |
} |
| 176 |
} |
| 177 |
} |
| 178 |
} |
| 179 |
} |
| 180 |
} |
| 181 |
} |
| 182 |
if (i==3 || i==4) { |
| 183 |
int numLocalSideIds = bdryCellLocIds_[i].size(); |
| 184 |
for (int j = 0; j < numLocalSideIds; ++j) { |
| 185 |
int numCellsSide = bdryCellLocIds_[i][j].size(); |
| 186 |
int numBdryDofs = fvidx_[j].size(); |
| 187 |
for (int k = 0; k < numCellsSide; ++k) { |
| 188 |
int cidx = bdryCellLocIds_[i][j][k]; |
| 189 |
for (int l = 0; l < numBdryDofs; ++l) { |
| 190 |
for (int m=0; m < fv; ++m) { |
| 191 |
for (int n=0; n < d; ++n) { |
| 192 |
for (int p=0; p < d; ++p) { |
| 193 |
(*J[n][p])(cidx,fvidx_[j][l],m) = zero; |
| 194 |
} |
| 195 |
(*J[n][n])(cidx,fvidx_[j][l],fvidx_[j][l]) = one; |
| 196 |
} |
| 197 |
} |
| 198 |
for (int m=0; m < fp; ++m) { |
| 199 |
for (int n=0; n < d; ++n) { |
| 200 |
(*J[n][2])(cidx,fvidx_[j][l],m) = zero; |
| 201 |
} |
| 202 |
} |
| 203 |
} |
| 204 |
} |
| 205 |
} |
| 206 |
} |
| 207 |
} |
| 208 |
} |
| 209 |
// Combine the Jacobians. |
| 210 |
fieldHelper_->combineFieldCoeff(jac, J); |
| 211 |
} |
| 212 |
|
| 213 |
|
| 214 |
void Jacobian_2(ROL::Ptr<Intrepid::FieldContainer<Real>> & jac, |
| 215 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 216 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 217 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 218 |
throw Exception::Zero(">>> (SteadyPDE_NavierStokes::Jacobian_2): Jacobian is zero."); |
| 219 |
} |
| 220 |
|
| 221 |
void Jacobian_3(std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> & jac, |
| 222 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 223 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 224 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 225 |
throw Exception::Zero(">>> (SteadyPDE_NavierStokes::Jacobian_3): Jacobian is zero."); |
| 226 |
} |
| 227 |
|
| 228 |
void Hessian_11(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess, |
| 229 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff, |
| 230 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 231 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 232 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 233 |
const Real zero(0); |
| 234 |
int d = feVel_->gradN()->dimension(3); |
| 235 |
std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> L; |
| 236 |
ROL::Ptr<Intrepid::FieldContainer<Real>> l0_coeff; |
| 237 |
fieldHelper_->splitFieldCoeff(L, l_coeff); |
| 238 |
// Apply Dirichlet conditions |
| 239 |
int numSideSets = bdryCellLocIds_.size(); |
| 240 |
if (numSideSets > 0) { |
| 241 |
for (int i = 0; i < numSideSets; ++i) { |
| 242 |
if (i==0 || i==2) { |
| 243 |
int numLocalSideIds = bdryCellLocIds_[i].size(); |
| 244 |
for (int j = 0; j < numLocalSideIds; ++j) { |
| 245 |
int numCellsSide = bdryCellLocIds_[i][j].size(); |
| 246 |
int numBdryDofs = fvidx_[j].size(); |
| 247 |
for (int k = 0; k < numCellsSide; ++k) { |
| 248 |
int cidx = bdryCellLocIds_[i][j][k]; |
| 249 |
for (int l = 0; l < numBdryDofs; ++l) { |
| 250 |
if (useNonPenetratingWalls_) { |
| 251 |
(*L[1])(cidx,fvidx_[j][l]) = zero; |
| 252 |
} |
| 253 |
else { |
| 254 |
for (int m=0; m < d; ++m) { |
| 255 |
(*L[m])(cidx,fvidx_[j][l]) = zero; |
| 256 |
} |
| 257 |
} |
| 258 |
} |
| 259 |
} |
| 260 |
} |
| 261 |
} |
| 262 |
if (i==3 || i==4) { |
| 263 |
int numLocalSideIds = bdryCellLocIds_[i].size(); |
| 264 |
for (int j = 0; j < numLocalSideIds; ++j) { |
| 265 |
int numCellsSide = bdryCellLocIds_[i][j].size(); |
| 266 |
int numBdryDofs = fvidx_[j].size(); |
| 267 |
for (int k = 0; k < numCellsSide; ++k) { |
| 268 |
int cidx = bdryCellLocIds_[i][j][k]; |
| 269 |
for (int l = 0; l < numBdryDofs; ++l) { |
| 270 |
for (int m=0; m < d; ++m) { |
| 271 |
(*L[m])(cidx,fvidx_[j][l]) = zero; |
| 272 |
} |
| 273 |
} |
| 274 |
} |
| 275 |
} |
| 276 |
} |
| 277 |
} |
| 278 |
} |
| 279 |
fieldHelper_->combineFieldCoeff(l0_coeff, L); |
| 280 |
pde_->Hessian_11(hess, l0_coeff, u_coeff, z_coeff, z_param); |
| 281 |
} |
| 282 |
|
| 283 |
void Hessian_12(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess, |
| 284 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff, |
| 285 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 286 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 287 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 288 |
throw Exception::Zero(">>> (SteadyPDE_NavierStokes::Hessian_12): Hessian is zero."); |
| 289 |
} |
| 290 |
|
| 291 |
void Hessian_13(std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> & hess, |
| 292 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff, |
| 293 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 294 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 295 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 296 |
throw Exception::Zero(">>> (SteadyPDE_NavierStokes::Hessian_13): Hessian is zero."); |
| 297 |
} |
| 298 |
|
| 299 |
void Hessian_21(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess, |
| 300 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff, |
| 301 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 302 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 303 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 304 |
throw Exception::Zero(">>> (SteadyPDE_NavierStokes::Hessian_21): Hessian is zero."); |
| 305 |
} |
| 306 |
|
| 307 |
void Hessian_22(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess, |
| 308 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff, |
| 309 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 310 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 311 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 312 |
throw Exception::Zero(">>> (SteadyPDE_NavierStokes::Hessian_22): Hessian is zero."); |
| 313 |
} |
| 314 |
|
| 315 |
void Hessian_23(std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> & hess, |
| 316 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff, |
| 317 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 318 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 319 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 320 |
throw Exception::Zero(">>> (SteadyPDE_NavierStokes::Hessian_23): Hessian is zero."); |
| 321 |
} |
| 322 |
|
| 323 |
void Hessian_31(std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> & hess, |
| 324 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff, |
| 325 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 326 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 327 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 328 |
throw Exception::Zero(">>> (SteadyPDE_NavierStokes::Hessian_31): Hessian is zero."); |
| 329 |
} |
| 330 |
|
| 331 |
void Hessian_32(std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> & hess, |
| 332 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff, |
| 333 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 334 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 335 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 336 |
throw Exception::Zero(">>> (SteadyPDE_NavierStokes::Hessian_32): Hessian is zero."); |
| 337 |
} |
| 338 |
|
| 339 |
void Hessian_33(std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>>> & hess, |
| 340 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff, |
| 341 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 342 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 343 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 344 |
throw Exception::Zero(">>> (SteadyPDE_NavierStokes::Hessian_33): Hessian is zero."); |
| 345 |
} |
| 346 |
|
| 347 |
void RieszMap_1(ROL::Ptr<Intrepid::FieldContainer<Real>> & riesz) { |
| 348 |
pde_->RieszMap_1(riesz); |
| 349 |
} |
| 350 |
|
| 351 |
void RieszMap_2(ROL::Ptr<Intrepid::FieldContainer<Real>> & riesz) { |
| 352 |
pde_->RieszMap_2(riesz); |
| 353 |
} |
| 354 |
|
| 355 |
std::vector<ROL::Ptr<Intrepid::Basis<Real, Intrepid::FieldContainer<Real>>>> getFields() { |
| 356 |
return pde_->getFields(); |
| 357 |
} |
| 358 |
|
| 359 |
void setCellNodes(const ROL::Ptr<Intrepid::FieldContainer<Real>> &volCellNodes, |
| 360 |
const std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>>> &bdryCellNodes, |
| 361 |
const std::vector<std::vector<std::vector<int>>> &bdryCellLocIds) { |
| 362 |
pde_->setCellNodes(volCellNodes,bdryCellNodes,bdryCellLocIds); |
| 363 |
bdryCellLocIds_ = bdryCellLocIds; |
| 364 |
bdryCellNodes_ = bdryCellNodes; |
| 365 |
feVel_ = pde_->getVelocityFE(); |
| 366 |
fePrs_ = pde_->getPressureFE(); |
| 367 |
fvidx_ = feVel_->getBoundaryDofs(); |
| 368 |
fpidx_ = fePrs_->getBoundaryDofs(); |
| 369 |
computeDirichlet(); |
| 370 |
} |
| 371 |
|
| 372 |
void setFieldPattern(const std::vector<std::vector<int>> & fieldPattern) { |
| 373 |
pde_->setFieldPattern(fieldPattern); |
| 374 |
fieldHelper_ = pde_->getFieldHelper(); |
| 375 |
} |
| 376 |
|
| 377 |
const ROL::Ptr<FE<Real>> getVelocityFE(void) const { |
| 378 |
return feVel_; |
| 379 |
} |
| 380 |
|
| 381 |
const ROL::Ptr<FE<Real>> getPressureFE(void) const { |
| 382 |
return fePrs_; |
| 383 |
} |
| 384 |
|
| 385 |
const std::vector<ROL::Ptr<FE<Real>>> getVelocityBdryFE(void) const { |
| 386 |
return pde_->getVelocityBdryFE(); |
| 387 |
} |
| 388 |
|
| 389 |
const std::vector<std::vector<int>> getBdryCellLocIds(const int sideset = -1) const { |
| 390 |
return pde_->getBdryCellLocIds(sideset); |
| 391 |
} |
| 392 |
|
| 393 |
const ROL::Ptr<FieldHelper<Real>> getFieldHelper(void) const { |
| 394 |
return fieldHelper_; |
| 395 |
} |
| 396 |
|
| 397 |
private: |
| 398 |
Real DirichletFunc(const std::vector<Real> & coords, int sideset, int locSideId, int dir) const { |
| 399 |
const Real one(1); |
| 400 |
const Real x = coords[0], y = coords[1]; |
| 401 |
Real val(0); |
| 402 |
if ((sideset!=4) && (dir==0)) { |
| 403 |
val = (useParabolicInflow_ ? (one + y) * (one - y) : one); |
| 404 |
} |
| 405 |
if (sideset==4) { |
| 406 |
Real tx = y-cy_, ty = cx_-x; |
| 407 |
val = (dir==0 ? tx : ty); |
| 408 |
} |
| 409 |
return val; |
| 410 |
} |
| 411 |
|
| 412 |
void computeDirichlet(void) { |
| 413 |
// Compute Dirichlet values at DOFs. |
| 414 |
int d = feVel_->gradN()->dimension(3); |
| 415 |
int numSidesets = bdryCellLocIds_.size(); |
| 416 |
bdryCellDofValues_.resize(numSidesets); |
| 417 |
for (int i=0; i<numSidesets; ++i) { |
| 418 |
int numLocSides = bdryCellLocIds_[i].size(); |
| 419 |
bdryCellDofValues_[i].resize(numLocSides); |
| 420 |
for (int j=0; j<numLocSides; ++j) { |
| 421 |
int c = bdryCellLocIds_[i][j].size(); |
| 422 |
int f = (pde_->getFields())[0]->getCardinality(); |
| 423 |
bdryCellDofValues_[i][j] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, d); |
| 424 |
ROL::Ptr<Intrepid::FieldContainer<Real> > coords = |
| 425 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, d); |
| 426 |
if (c > 0) { |
| 427 |
feVel_->computeDofCoords(coords, bdryCellNodes_[i][j]); |
| 428 |
} |
| 429 |
for (int k=0; k<c; ++k) { |
| 430 |
for (int l=0; l<f; ++l) { |
| 431 |
std::vector<Real> dofpoint(d); |
| 432 |
for (int m=0; m<d; ++m) { |
| 433 |
dofpoint[m] = (*coords)(k, l, m); |
| 434 |
} |
| 435 |
for (int m=0; m<d; ++m) { |
| 436 |
(*bdryCellDofValues_[i][j])(k, l, m) = DirichletFunc(dofpoint, i, j, m); |
| 437 |
} |
| 438 |
} |
| 439 |
} |
| 440 |
} |
| 441 |
} |
| 442 |
} |
| 443 |
}; // PDE_NavierStokes |
| 444 |
|
| 445 |
#endif |