| 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 PDE_DYNAMIC_NAVIERSTOKES_HPP |
| 15 |
#define PDE_DYNAMIC_NAVIERSTOKES_HPP |
| 16 |
|
| 17 |
#include "../../TOOLS/pde.hpp" |
| 18 |
#include "../../TOOLS/fe.hpp" |
| 19 |
#include "../../TOOLS/fieldhelper.hpp" |
| 20 |
|
| 21 |
#include "Intrepid_HGRAD_QUAD_C1_FEM.hpp" |
| 22 |
#include "Intrepid_HGRAD_QUAD_C2_FEM.hpp" |
| 23 |
#include "Intrepid_DefaultCubatureFactory.hpp" |
| 24 |
#include "Intrepid_FunctionSpaceTools.hpp" |
| 25 |
#include "Intrepid_CellTools.hpp" |
| 26 |
|
| 27 |
#include "ROL_Ptr.hpp" |
| 28 |
|
| 29 |
template <class Real> |
| 30 |
class PDE_NavierStokes : public PDE<Real> { |
| 31 |
private: |
| 32 |
// Finite element basis information |
| 33 |
ROL::Ptr<Intrepid::Basis<Real, Intrepid::FieldContainer<Real>>> basisPtrVel_; |
| 34 |
ROL::Ptr<Intrepid::Basis<Real, Intrepid::FieldContainer<Real>>> basisPtrPrs_; |
| 35 |
std::vector<ROL::Ptr<Intrepid::Basis<Real, Intrepid::FieldContainer<Real>>>> basisPtrs_; |
| 36 |
// Cell cubature information |
| 37 |
ROL::Ptr<Intrepid::Cubature<Real>> cellCub_; |
| 38 |
ROL::Ptr<Intrepid::Cubature<Real>> bdryCub_; |
| 39 |
// Cell node information |
| 40 |
ROL::Ptr<Intrepid::FieldContainer<Real>> volCellNodes_; |
| 41 |
std::vector<std::vector<std::vector<int>>> bdryCellLocIds_; |
| 42 |
// Finite element definition |
| 43 |
ROL::Ptr<FE<Real>> feVel_; |
| 44 |
ROL::Ptr<FE<Real>> fePrs_; |
| 45 |
std::vector<std::vector<ROL::Ptr<FE<Real>>>> feVelBdry_; |
| 46 |
// Local degrees of freedom on boundary, for each side of the reference cell (first index). |
| 47 |
std::vector<std::vector<int>> fvidx_; |
| 48 |
std::vector<std::vector<int>> fpidx_; |
| 49 |
// Field pattern, offsets, etc. |
| 50 |
std::vector<std::vector<int>> fieldPattern_; // local Field/DOF pattern; set from DOF manager |
| 51 |
int numFields_; // number of fields (equations in the PDE) |
| 52 |
int numDofs_; // total number of degrees of freedom for all (local) fields |
| 53 |
std::vector<int> offset_; // for each field, a counting offset |
| 54 |
std::vector<int> numFieldDofs_; // for each field, number of degrees of freedom |
| 55 |
|
| 56 |
// Reynolds number. |
| 57 |
Real Re_; |
| 58 |
|
| 59 |
ROL::Ptr<FieldHelper<Real>> fieldHelper_; |
| 60 |
|
| 61 |
Real viscosityFunc(const std::vector<Real> & coords) const { |
| 62 |
return static_cast<Real>(1)/Re_; |
| 63 |
} |
| 64 |
|
| 65 |
void computeViscosity(ROL::Ptr<Intrepid::FieldContainer<Real>> &nu) const { |
| 66 |
int c = feVel_->gradN()->dimension(0); |
| 67 |
int p = feVel_->gradN()->dimension(2); |
| 68 |
int d = feVel_->gradN()->dimension(3); |
| 69 |
std::vector<Real> pt(d); |
| 70 |
for (int i = 0; i < c; ++i) { |
| 71 |
for (int j = 0; j < p; ++j) { |
| 72 |
for ( int k = 0; k < d; ++k) { |
| 73 |
pt[k] = (*feVel_->cubPts())(i,j,k); |
| 74 |
} |
| 75 |
// Compute spatially dependent viscosity |
| 76 |
(*nu)(i,j) = viscosityFunc(pt); |
| 77 |
} |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
public: |
| 82 |
PDE_NavierStokes(Teuchos::ParameterList &parlist) { |
| 83 |
// Finite element fields. |
| 84 |
basisPtrVel_ = ROL::makePtr<Intrepid::Basis_HGRAD_QUAD_C2_FEM<Real, Intrepid::FieldContainer<Real>>>(); |
| 85 |
basisPtrPrs_ = ROL::makePtr<Intrepid::Basis_HGRAD_QUAD_C1_FEM<Real, Intrepid::FieldContainer<Real>>>(); |
| 86 |
basisPtrs_.clear(); |
| 87 |
basisPtrs_.push_back(basisPtrVel_); // Velocity X |
| 88 |
basisPtrs_.push_back(basisPtrVel_); // Velocity Y |
| 89 |
basisPtrs_.push_back(basisPtrPrs_); // Pressure |
| 90 |
// Quadrature rules. |
| 91 |
shards::CellTopology cellType = basisPtrs_[0]->getBaseCellTopology(); // get the cell type from any basis |
| 92 |
Intrepid::DefaultCubatureFactory<Real> cubFactory; // create cubature factory |
| 93 |
int cubDegree = parlist.sublist("Problem").get("Cubature Degree", 4); // set cubature degree, e.g., 4 |
| 94 |
cellCub_ = cubFactory.create(cellType, cubDegree); // create default cubature |
| 95 |
|
| 96 |
int d = cellType.getDimension(); |
| 97 |
shards::CellTopology bdryCellType = cellType.getCellTopologyData(d-1, 0); |
| 98 |
int bdryCubDegree = parlist.sublist("Problem").get("Boundary Cubature Degree",4); // set cubature degree, e.g., 4 |
| 99 |
bdryCub_ = cubFactory.create(bdryCellType, bdryCubDegree); |
| 100 |
|
| 101 |
// Other problem parameters. |
| 102 |
Re_ = parlist.sublist("Problem").get("Reynolds Number", 40.0); |
| 103 |
|
| 104 |
numDofs_ = 0; |
| 105 |
numFields_ = basisPtrs_.size(); |
| 106 |
offset_.resize(numFields_); |
| 107 |
numFieldDofs_.resize(numFields_); |
| 108 |
for (int i=0; i<numFields_; ++i) { |
| 109 |
if (i==0) { |
| 110 |
offset_[i] = 0; |
| 111 |
} |
| 112 |
else { |
| 113 |
offset_[i] = offset_[i-1] + basisPtrs_[i-1]->getCardinality(); |
| 114 |
} |
| 115 |
numFieldDofs_[i] = basisPtrs_[i]->getCardinality(); |
| 116 |
numDofs_ += numFieldDofs_[i]; |
| 117 |
} |
| 118 |
} |
| 119 |
|
| 120 |
void residual(ROL::Ptr<Intrepid::FieldContainer<Real>> & res, |
| 121 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 122 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 123 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 124 |
// Retrieve dimensions. |
| 125 |
int c = u_coeff->dimension(0); |
| 126 |
int p = cellCub_->getNumPoints(); |
| 127 |
int fv = basisPtrVel_->getCardinality(); |
| 128 |
int fp = basisPtrPrs_->getCardinality(); |
| 129 |
int d = cellCub_->getDimension(); |
| 130 |
|
| 131 |
// Initialize residuals. |
| 132 |
Intrepid::FieldContainer<Real> velX_res(c, fv); |
| 133 |
Intrepid::FieldContainer<Real> velY_res(c, fv); |
| 134 |
Intrepid::FieldContainer<Real> pres_res(c, fp); |
| 135 |
std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> R; |
| 136 |
R.resize(numFields_); |
| 137 |
R[0] = ROL::makePtrFromRef(velX_res); |
| 138 |
R[1] = ROL::makePtrFromRef(velY_res); |
| 139 |
R[2] = ROL::makePtrFromRef(pres_res); |
| 140 |
|
| 141 |
// Split u_coeff into components. |
| 142 |
std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> U; |
| 143 |
fieldHelper_->splitFieldCoeff(U, u_coeff); |
| 144 |
|
| 145 |
// Evaluate/interpolate finite element fields on cells. |
| 146 |
ROL::Ptr<Intrepid::FieldContainer<Real>> nu = |
| 147 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 148 |
ROL::Ptr<Intrepid::FieldContainer<Real>> nuGradVelX_eval = |
| 149 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d); |
| 150 |
ROL::Ptr<Intrepid::FieldContainer<Real>> nuGradVelY_eval = |
| 151 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d); |
| 152 |
ROL::Ptr<Intrepid::FieldContainer<Real>> valVel_eval = |
| 153 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d); |
| 154 |
ROL::Ptr<Intrepid::FieldContainer<Real>> valVelX_eval = |
| 155 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 156 |
ROL::Ptr<Intrepid::FieldContainer<Real>> valVelY_eval = |
| 157 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 158 |
ROL::Ptr<Intrepid::FieldContainer<Real>> valPres_eval = |
| 159 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 160 |
ROL::Ptr<Intrepid::FieldContainer<Real>> gradVelX_eval = |
| 161 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d); |
| 162 |
ROL::Ptr<Intrepid::FieldContainer<Real>> gradVelY_eval = |
| 163 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d); |
| 164 |
ROL::Ptr<Intrepid::FieldContainer<Real>> divVel_eval = |
| 165 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 166 |
ROL::Ptr<Intrepid::FieldContainer<Real>> valVelDotgradVelX_eval = |
| 167 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 168 |
ROL::Ptr<Intrepid::FieldContainer<Real>> valVelDotgradVelY_eval = |
| 169 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 170 |
feVel_->evaluateValue(valVelX_eval, U[0]); |
| 171 |
feVel_->evaluateValue(valVelY_eval, U[1]); |
| 172 |
fePrs_->evaluateValue(valPres_eval, U[2]); |
| 173 |
feVel_->evaluateGradient(gradVelX_eval, U[0]); |
| 174 |
feVel_->evaluateGradient(gradVelY_eval, U[1]); |
| 175 |
computeViscosity(nu); |
| 176 |
|
| 177 |
// Assemble the velocity vector and its divergence. |
| 178 |
for (int i = 0; i < c; ++i) { |
| 179 |
for (int j = 0; j < p; ++j) { |
| 180 |
(*valVel_eval)(i,j,0) = (*valVelX_eval)(i,j); |
| 181 |
(*valVel_eval)(i,j,1) = (*valVelY_eval)(i,j); |
| 182 |
(*divVel_eval)(i,j) = (*gradVelX_eval)(i,j,0) + (*gradVelY_eval)(i,j,1); |
| 183 |
} |
| 184 |
} |
| 185 |
// Negative pressure |
| 186 |
Intrepid::RealSpaceTools<Real>::scale(*valPres_eval,static_cast<Real>(-1)); |
| 187 |
|
| 188 |
// Multiply velocity gradients with viscosity. |
| 189 |
Intrepid::FunctionSpaceTools::tensorMultiplyDataData<Real>(*nuGradVelX_eval, |
| 190 |
*nu, |
| 191 |
*gradVelX_eval); |
| 192 |
Intrepid::FunctionSpaceTools::tensorMultiplyDataData<Real>(*nuGradVelY_eval, |
| 193 |
*nu, |
| 194 |
*gradVelY_eval); |
| 195 |
|
| 196 |
// Compute nonlinear terms in the Navier-Stokes equations. |
| 197 |
Intrepid::FunctionSpaceTools::dotMultiplyDataData<Real>(*valVelDotgradVelX_eval, *valVel_eval, *gradVelX_eval); |
| 198 |
Intrepid::FunctionSpaceTools::dotMultiplyDataData<Real>(*valVelDotgradVelY_eval, *valVel_eval, *gradVelY_eval); |
| 199 |
|
| 200 |
/*** Evaluate weak form of the residual. ***/ |
| 201 |
// X component of velocity equation. |
| 202 |
Intrepid::FunctionSpaceTools::integrate<Real>(velX_res, |
| 203 |
*nuGradVelX_eval, // nu gradUX |
| 204 |
*(feVel_->gradNdetJ()), // gradPhi |
| 205 |
Intrepid::COMP_CPP, |
| 206 |
false); |
| 207 |
Intrepid::FunctionSpaceTools::integrate<Real>(velX_res, |
| 208 |
*valVelDotgradVelX_eval, // (U . gradUX) |
| 209 |
*(feVel_->NdetJ()), // Phi |
| 210 |
Intrepid::COMP_CPP, |
| 211 |
true); |
| 212 |
Intrepid::FunctionSpaceTools::integrate<Real>(velX_res, |
| 213 |
*valPres_eval, // p |
| 214 |
*(feVel_->DNDdetJ(0)), // dPhi/dx |
| 215 |
Intrepid::COMP_CPP, |
| 216 |
true); |
| 217 |
// Y component of velocity equation. |
| 218 |
Intrepid::FunctionSpaceTools::integrate<Real>(velY_res, |
| 219 |
*nuGradVelY_eval, // nu gradUY |
| 220 |
*(feVel_->gradNdetJ()), // gradPhi |
| 221 |
Intrepid::COMP_CPP, |
| 222 |
false); |
| 223 |
Intrepid::FunctionSpaceTools::integrate<Real>(velY_res, |
| 224 |
*valVelDotgradVelY_eval, // (U . gradUY) |
| 225 |
*(feVel_->NdetJ()), // Phi |
| 226 |
Intrepid::COMP_CPP, |
| 227 |
true); |
| 228 |
Intrepid::FunctionSpaceTools::integrate<Real>(velY_res, |
| 229 |
*valPres_eval, // p |
| 230 |
*(feVel_->DNDdetJ(1)), // dPhi/dy |
| 231 |
Intrepid::COMP_CPP, |
| 232 |
true); |
| 233 |
// Pressure equation. |
| 234 |
Intrepid::FunctionSpaceTools::integrate<Real>(pres_res, |
| 235 |
*divVel_eval, // divU |
| 236 |
*(fePrs_->NdetJ()), // Phi |
| 237 |
Intrepid::COMP_CPP, |
| 238 |
false); |
| 239 |
Intrepid::RealSpaceTools<Real>::scale(pres_res,static_cast<Real>(-1)); |
| 240 |
// Combine the residuals. |
| 241 |
fieldHelper_->combineFieldCoeff(res, R); |
| 242 |
} |
| 243 |
|
| 244 |
void Jacobian_1(ROL::Ptr<Intrepid::FieldContainer<Real>> & jac, |
| 245 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 246 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 247 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 248 |
// Retrieve dimensions. |
| 249 |
int c = u_coeff->dimension(0); |
| 250 |
int p = cellCub_->getNumPoints(); |
| 251 |
int fv = basisPtrVel_->getCardinality(); |
| 252 |
int fp = basisPtrPrs_->getCardinality(); |
| 253 |
int d = cellCub_->getDimension(); |
| 254 |
|
| 255 |
// Initialize residuals. |
| 256 |
Intrepid::FieldContainer<Real> velXvelX_jac(c, fv, fv); |
| 257 |
Intrepid::FieldContainer<Real> velXvelY_jac(c, fv, fv); |
| 258 |
Intrepid::FieldContainer<Real> velXpres_jac(c, fv, fp); |
| 259 |
Intrepid::FieldContainer<Real> velYvelX_jac(c, fv, fv); |
| 260 |
Intrepid::FieldContainer<Real> velYvelY_jac(c, fv, fv); |
| 261 |
Intrepid::FieldContainer<Real> velYpres_jac(c, fv, fp); |
| 262 |
Intrepid::FieldContainer<Real> presvelX_jac(c, fp, fv); |
| 263 |
Intrepid::FieldContainer<Real> presvelY_jac(c, fp, fv); |
| 264 |
Intrepid::FieldContainer<Real> prespres_jac(c, fp, fp); |
| 265 |
std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>>> J; |
| 266 |
J.resize(numFields_); |
| 267 |
J[0].resize(numFields_); |
| 268 |
J[1].resize(numFields_); |
| 269 |
J[2].resize(numFields_); |
| 270 |
J[0][0] = ROL::makePtrFromRef(velXvelX_jac); J[0][1] = ROL::makePtrFromRef(velXvelY_jac); J[0][2] = ROL::makePtrFromRef(velXpres_jac); |
| 271 |
J[1][0] = ROL::makePtrFromRef(velYvelX_jac); J[1][1] = ROL::makePtrFromRef(velYvelY_jac); J[1][2] = ROL::makePtrFromRef(velYpres_jac); |
| 272 |
J[2][0] = ROL::makePtrFromRef(presvelX_jac); J[2][1] = ROL::makePtrFromRef(presvelY_jac); J[2][2] = ROL::makePtrFromRef(prespres_jac); |
| 273 |
|
| 274 |
// Split u_coeff into components. |
| 275 |
std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> U; |
| 276 |
fieldHelper_->splitFieldCoeff(U, u_coeff); |
| 277 |
|
| 278 |
// Evaluate/interpolate finite element fields on cells. |
| 279 |
ROL::Ptr<Intrepid::FieldContainer<Real>> nu = |
| 280 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 281 |
ROL::Ptr<Intrepid::FieldContainer<Real>> nuGradPhiX_eval = |
| 282 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv, p, d); |
| 283 |
ROL::Ptr<Intrepid::FieldContainer<Real>> nuGradPhiY_eval = |
| 284 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv, p, d); |
| 285 |
ROL::Ptr<Intrepid::FieldContainer<Real>> valVel_eval = |
| 286 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d); |
| 287 |
ROL::Ptr<Intrepid::FieldContainer<Real>> valVelX_eval = |
| 288 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 289 |
ROL::Ptr<Intrepid::FieldContainer<Real>> valVelY_eval = |
| 290 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 291 |
ROL::Ptr<Intrepid::FieldContainer<Real>> gradVelX_eval = |
| 292 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d); |
| 293 |
ROL::Ptr<Intrepid::FieldContainer<Real>> ddxVelX_eval = |
| 294 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 295 |
ROL::Ptr<Intrepid::FieldContainer<Real>> ddyVelX_eval = |
| 296 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 297 |
ROL::Ptr<Intrepid::FieldContainer<Real>> ddxVelXPhiX_eval = |
| 298 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv, p); |
| 299 |
ROL::Ptr<Intrepid::FieldContainer<Real>> ddyVelXPhiY_eval = |
| 300 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv, p); |
| 301 |
ROL::Ptr<Intrepid::FieldContainer<Real>> gradVelY_eval = |
| 302 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d); |
| 303 |
ROL::Ptr<Intrepid::FieldContainer<Real>> ddxVelY_eval = |
| 304 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 305 |
ROL::Ptr<Intrepid::FieldContainer<Real>> ddyVelY_eval = |
| 306 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 307 |
ROL::Ptr<Intrepid::FieldContainer<Real>> ddyVelYPhiY_eval = |
| 308 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv, p); |
| 309 |
ROL::Ptr<Intrepid::FieldContainer<Real>> ddxVelYPhiX_eval = |
| 310 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv, p); |
| 311 |
ROL::Ptr<Intrepid::FieldContainer<Real>> valVelDotgradPhiX_eval = |
| 312 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv, p); |
| 313 |
ROL::Ptr<Intrepid::FieldContainer<Real>> valVelDotgradPhiY_eval = |
| 314 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv, p); |
| 315 |
feVel_->evaluateValue(valVelX_eval, U[0]); |
| 316 |
feVel_->evaluateValue(valVelY_eval, U[1]); |
| 317 |
feVel_->evaluateGradient(gradVelX_eval, U[0]); |
| 318 |
feVel_->evaluateGradient(gradVelY_eval, U[1]); |
| 319 |
computeViscosity(nu); |
| 320 |
|
| 321 |
// Assemble the velocity vector and its divergence. |
| 322 |
for (int i = 0; i < c; ++i) { |
| 323 |
for (int j = 0; j < p; ++j) { |
| 324 |
(*valVel_eval)(i,j,0) = (*valVelX_eval)(i,j); |
| 325 |
(*valVel_eval)(i,j,1) = (*valVelY_eval)(i,j); |
| 326 |
(*ddxVelX_eval)(i,j) = (*gradVelX_eval)(i,j,0); |
| 327 |
(*ddyVelX_eval)(i,j) = (*gradVelX_eval)(i,j,1); |
| 328 |
(*ddxVelY_eval)(i,j) = (*gradVelY_eval)(i,j,0); |
| 329 |
(*ddyVelY_eval)(i,j) = (*gradVelY_eval)(i,j,1); |
| 330 |
} |
| 331 |
} |
| 332 |
|
| 333 |
// Multiply velocity gradients with viscosity. |
| 334 |
Intrepid::FunctionSpaceTools::tensorMultiplyDataField<Real>(*nuGradPhiX_eval, |
| 335 |
*nu, |
| 336 |
*(feVel_->gradN())); |
| 337 |
Intrepid::FunctionSpaceTools::tensorMultiplyDataField<Real>(*nuGradPhiY_eval, |
| 338 |
*nu, |
| 339 |
*(feVel_->gradN())); |
| 340 |
|
| 341 |
// Compute nonlinear terms in the Navier-Stokes equations. |
| 342 |
Intrepid::FunctionSpaceTools::dotMultiplyDataField<Real>(*valVelDotgradPhiX_eval, *valVel_eval, *(feVel_->gradN())); |
| 343 |
Intrepid::FunctionSpaceTools::dotMultiplyDataField<Real>(*valVelDotgradPhiY_eval, *valVel_eval, *(feVel_->gradN())); |
| 344 |
Intrepid::FunctionSpaceTools::scalarMultiplyDataField<Real>(*ddxVelXPhiX_eval, *ddxVelX_eval, *(feVel_->N())); |
| 345 |
Intrepid::FunctionSpaceTools::scalarMultiplyDataField<Real>(*ddyVelXPhiY_eval, *ddyVelX_eval, *(feVel_->N())); |
| 346 |
Intrepid::FunctionSpaceTools::scalarMultiplyDataField<Real>(*ddxVelYPhiX_eval, *ddxVelY_eval, *(feVel_->N())); |
| 347 |
Intrepid::FunctionSpaceTools::scalarMultiplyDataField<Real>(*ddyVelYPhiY_eval, *ddyVelY_eval, *(feVel_->N())); |
| 348 |
|
| 349 |
// Negative pressure basis. |
| 350 |
Intrepid::FieldContainer<Real> negPrsN(*(fePrs_->N())); |
| 351 |
Intrepid::RealSpaceTools<Real>::scale(negPrsN,static_cast<Real>(-1)); |
| 352 |
|
| 353 |
/*** Evaluate weak form of the Jacobian. ***/ |
| 354 |
// X component of velocity equation. |
| 355 |
Intrepid::FunctionSpaceTools::integrate<Real>(velXvelX_jac, |
| 356 |
*nuGradPhiX_eval, // nu gradPsi |
| 357 |
*(feVel_->gradNdetJ()), // gradPhi |
| 358 |
Intrepid::COMP_CPP, |
| 359 |
false); |
| 360 |
Intrepid::FunctionSpaceTools::integrate<Real>(velXvelX_jac, |
| 361 |
*(feVel_->NdetJ()), // Phi |
| 362 |
*valVelDotgradPhiX_eval, // (U . gradPhiX) |
| 363 |
Intrepid::COMP_CPP, |
| 364 |
true); |
| 365 |
Intrepid::FunctionSpaceTools::integrate<Real>(velXvelX_jac, |
| 366 |
*(feVel_->NdetJ()), // Phi |
| 367 |
*ddxVelXPhiX_eval, // (Phi . gradU) |
| 368 |
Intrepid::COMP_CPP, |
| 369 |
true); |
| 370 |
Intrepid::FunctionSpaceTools::integrate<Real>(velXvelY_jac, |
| 371 |
*(feVel_->NdetJ()), // Phi |
| 372 |
*ddyVelXPhiY_eval, // (Phi . gradU) |
| 373 |
Intrepid::COMP_CPP, |
| 374 |
false); |
| 375 |
Intrepid::FunctionSpaceTools::integrate<Real>(velXpres_jac, |
| 376 |
*(feVel_->DNDdetJ(0)), // dPhi/dx |
| 377 |
negPrsN, // -Phi |
| 378 |
Intrepid::COMP_CPP, |
| 379 |
false); |
| 380 |
// Y component of velocity equation. |
| 381 |
Intrepid::FunctionSpaceTools::integrate<Real>(velYvelY_jac, |
| 382 |
*nuGradPhiY_eval, // nu gradPsi |
| 383 |
*(feVel_->gradNdetJ()), // gradPhi |
| 384 |
Intrepid::COMP_CPP, |
| 385 |
false); |
| 386 |
Intrepid::FunctionSpaceTools::integrate<Real>(velYvelY_jac, |
| 387 |
*(feVel_->NdetJ()), // Phi |
| 388 |
*valVelDotgradPhiY_eval, // (U . gradPhiX) |
| 389 |
Intrepid::COMP_CPP, |
| 390 |
true); |
| 391 |
Intrepid::FunctionSpaceTools::integrate<Real>(velYvelY_jac, |
| 392 |
*(feVel_->NdetJ()), // Phi |
| 393 |
*ddyVelYPhiY_eval, // (Phi . gradU) |
| 394 |
Intrepid::COMP_CPP, |
| 395 |
true); |
| 396 |
Intrepid::FunctionSpaceTools::integrate<Real>(velYvelX_jac, |
| 397 |
*(feVel_->NdetJ()), // Phi |
| 398 |
*ddxVelYPhiX_eval, // (Phi . gradU) |
| 399 |
Intrepid::COMP_CPP, |
| 400 |
false); |
| 401 |
Intrepid::FunctionSpaceTools::integrate<Real>(velYpres_jac, |
| 402 |
*(feVel_->DNDdetJ(1)), // dPhi/dx |
| 403 |
negPrsN, // -Phi |
| 404 |
Intrepid::COMP_CPP, |
| 405 |
false); |
| 406 |
// Pressure equation. |
| 407 |
Intrepid::FunctionSpaceTools::integrate<Real>(presvelX_jac, |
| 408 |
*(fePrs_->NdetJ()), // Phi |
| 409 |
*(feVel_->DND(0)), // dPhi/dx |
| 410 |
Intrepid::COMP_CPP, |
| 411 |
false); |
| 412 |
Intrepid::FunctionSpaceTools::integrate<Real>(presvelY_jac, |
| 413 |
*(fePrs_->NdetJ()), // Phi |
| 414 |
*(feVel_->DND(1)), // dPhi/dx |
| 415 |
Intrepid::COMP_CPP, |
| 416 |
false); |
| 417 |
Intrepid::RealSpaceTools<Real>::scale(presvelX_jac,static_cast<Real>(-1)); |
| 418 |
Intrepid::RealSpaceTools<Real>::scale(presvelY_jac,static_cast<Real>(-1)); |
| 419 |
// Combine the jacobians. |
| 420 |
fieldHelper_->combineFieldCoeff(jac, J); |
| 421 |
|
| 422 |
} |
| 423 |
|
| 424 |
|
| 425 |
void Jacobian_2(ROL::Ptr<Intrepid::FieldContainer<Real>> & jac, |
| 426 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 427 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 428 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 429 |
if (z_coeff != ROL::nullPtr) { |
| 430 |
// Retrieve dimensions. |
| 431 |
int c = u_coeff->dimension(0); |
| 432 |
jac = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, numDofs_, numDofs_); |
| 433 |
} |
| 434 |
else { |
| 435 |
throw Exception::Zero(">>> (PDE_NavierStokes::Jacobian_2): Jacobian is zero."); |
| 436 |
} |
| 437 |
/* |
| 438 |
int fv = basisPtrVel_->getCardinality(); |
| 439 |
int fp = basisPtrPrs_->getCardinality(); |
| 440 |
|
| 441 |
// Initialize residuals. |
| 442 |
Intrepid::FieldContainer<Real> velXvelX_jac(c, fv, fv); |
| 443 |
Intrepid::FieldContainer<Real> velXvelY_jac(c, fv, fv); |
| 444 |
Intrepid::FieldContainer<Real> velXpres_jac(c, fv, fp); |
| 445 |
Intrepid::FieldContainer<Real> velYvelX_jac(c, fv, fv); |
| 446 |
Intrepid::FieldContainer<Real> velYvelY_jac(c, fv, fv); |
| 447 |
Intrepid::FieldContainer<Real> velYpres_jac(c, fv, fp); |
| 448 |
Intrepid::FieldContainer<Real> presvelX_jac(c, fp, fv); |
| 449 |
Intrepid::FieldContainer<Real> presvelY_jac(c, fp, fv); |
| 450 |
Intrepid::FieldContainer<Real> prespres_jac(c, fp, fp); |
| 451 |
std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>>> J; |
| 452 |
J.resize(numFields_); |
| 453 |
J[0].resize(numFields_); |
| 454 |
J[1].resize(numFields_); |
| 455 |
J[2].resize(numFields_); |
| 456 |
J[0][0] = ROL::makePtrFromRef(velXvelX_jac); J[0][1] = ROL::makePtrFromRef(velXvelY_jac); J[0][2] = ROL::makePtrFromRef(velXpres_jac); |
| 457 |
J[1][0] = ROL::makePtrFromRef(velYvelX_jac); J[1][1] = ROL::makePtrFromRef(velYvelY_jac); J[1][2] = ROL::makePtrFromRef(velYpres_jac); |
| 458 |
J[2][0] = ROL::makePtrFromRef(presvelX_jac); J[2][1] = ROL::makePtrFromRef(presvelY_jac); J[2][2] = ROL::makePtrFromRef(prespres_jac); |
| 459 |
// Combine the jacobians. |
| 460 |
fieldHelper_->combineFieldCoeff(jac, J); |
| 461 |
*/ |
| 462 |
} |
| 463 |
|
| 464 |
void Jacobian_3(std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> & jac, |
| 465 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 466 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 467 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 468 |
if (z_param != ROL::nullPtr) { |
| 469 |
// Retrieve dimensions. |
| 470 |
int size = z_param->size(); |
| 471 |
int c = u_coeff->dimension(0); |
| 472 |
jac.resize(size,ROL::nullPtr); |
| 473 |
for (int i = 0; i < size; ++i) { |
| 474 |
jac[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, numDofs_); |
| 475 |
} |
| 476 |
} |
| 477 |
else { |
| 478 |
throw Exception::Zero(">>> (PDE_NavierStokes::Jacobian_3): Jacobian is zero."); |
| 479 |
} |
| 480 |
} |
| 481 |
|
| 482 |
void Hessian_11(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess, |
| 483 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff, |
| 484 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 485 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 486 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 487 |
// throw Exception::NotImplemented(""); |
| 488 |
// Retrieve dimensions. |
| 489 |
int c = u_coeff->dimension(0); |
| 490 |
int p = cellCub_->getNumPoints(); |
| 491 |
int fv = basisPtrVel_->getCardinality(); |
| 492 |
int fp = basisPtrPrs_->getCardinality(); |
| 493 |
|
| 494 |
// Initialize residuals. |
| 495 |
Intrepid::FieldContainer<Real> velXvelX_jac(c, fv, fv); |
| 496 |
Intrepid::FieldContainer<Real> velXvelY_jac(c, fv, fv); |
| 497 |
Intrepid::FieldContainer<Real> velXpres_jac(c, fv, fp); |
| 498 |
Intrepid::FieldContainer<Real> velYvelX_jac(c, fv, fv); |
| 499 |
Intrepid::FieldContainer<Real> velYvelY_jac(c, fv, fv); |
| 500 |
Intrepid::FieldContainer<Real> velYpres_jac(c, fv, fp); |
| 501 |
Intrepid::FieldContainer<Real> presvelX_jac(c, fp, fv); |
| 502 |
Intrepid::FieldContainer<Real> presvelY_jac(c, fp, fv); |
| 503 |
Intrepid::FieldContainer<Real> prespres_jac(c, fp, fp); |
| 504 |
std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>>> J; |
| 505 |
J.resize(numFields_); |
| 506 |
J[0].resize(numFields_); |
| 507 |
J[1].resize(numFields_); |
| 508 |
J[2].resize(numFields_); |
| 509 |
J[0][0] = ROL::makePtrFromRef(velXvelX_jac); J[0][1] = ROL::makePtrFromRef(velXvelY_jac); J[0][2] = ROL::makePtrFromRef(velXpres_jac); |
| 510 |
J[1][0] = ROL::makePtrFromRef(velYvelX_jac); J[1][1] = ROL::makePtrFromRef(velYvelY_jac); J[1][2] = ROL::makePtrFromRef(velYpres_jac); |
| 511 |
J[2][0] = ROL::makePtrFromRef(presvelX_jac); J[2][1] = ROL::makePtrFromRef(presvelY_jac); J[2][2] = ROL::makePtrFromRef(prespres_jac); |
| 512 |
|
| 513 |
// Split l_coeff into components. |
| 514 |
std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> L; |
| 515 |
fieldHelper_->splitFieldCoeff(L, l_coeff); |
| 516 |
|
| 517 |
// Evaluate/interpolate finite element fields on cells. |
| 518 |
ROL::Ptr<Intrepid::FieldContainer<Real>> valVelX_eval = |
| 519 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 520 |
ROL::Ptr<Intrepid::FieldContainer<Real>> valVelY_eval = |
| 521 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 522 |
ROL::Ptr<Intrepid::FieldContainer<Real>> valVelXPhi_eval = |
| 523 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv, p); |
| 524 |
ROL::Ptr<Intrepid::FieldContainer<Real>> valVelYPhi_eval = |
| 525 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv, p); |
| 526 |
feVel_->evaluateValue(valVelX_eval, L[0]); |
| 527 |
feVel_->evaluateValue(valVelY_eval, L[1]); |
| 528 |
|
| 529 |
// Compute nonlinear terms in the Navier-Stokes equations. |
| 530 |
Intrepid::FunctionSpaceTools::scalarMultiplyDataField<Real>(*valVelXPhi_eval, *valVelX_eval, *(feVel_->N())); |
| 531 |
Intrepid::FunctionSpaceTools::scalarMultiplyDataField<Real>(*valVelYPhi_eval, *valVelY_eval, *(feVel_->N())); |
| 532 |
|
| 533 |
/*** Evaluate weak form of the Hessian. ***/ |
| 534 |
// X component of velocity equation. |
| 535 |
Intrepid::FunctionSpaceTools::integrate<Real>(velXvelX_jac, |
| 536 |
*valVelXPhi_eval, // L Phi |
| 537 |
*(feVel_->DNDdetJ(0)), // dPhi/dx |
| 538 |
Intrepid::COMP_CPP, |
| 539 |
false); |
| 540 |
Intrepid::FunctionSpaceTools::integrate<Real>(velXvelX_jac, |
| 541 |
*(feVel_->DNDdetJ(0)), // dPhi/dx |
| 542 |
*valVelXPhi_eval, // L Phi |
| 543 |
Intrepid::COMP_CPP, |
| 544 |
true); |
| 545 |
Intrepid::FunctionSpaceTools::integrate<Real>(velXvelY_jac, |
| 546 |
*(feVel_->DNDdetJ(1)), // dPhi/dy |
| 547 |
*valVelXPhi_eval, // L Phi |
| 548 |
Intrepid::COMP_CPP, |
| 549 |
false); |
| 550 |
Intrepid::FunctionSpaceTools::integrate<Real>(velXvelY_jac, |
| 551 |
*valVelYPhi_eval, // L Phi |
| 552 |
*(feVel_->DNDdetJ(0)), // dPhi/dx |
| 553 |
Intrepid::COMP_CPP, |
| 554 |
true); |
| 555 |
// Y component of velocity equation. |
| 556 |
Intrepid::FunctionSpaceTools::integrate<Real>(velYvelY_jac, |
| 557 |
*valVelYPhi_eval, // L Phi |
| 558 |
*(feVel_->DNDdetJ(1)), // dPhi/dy |
| 559 |
Intrepid::COMP_CPP, |
| 560 |
false); |
| 561 |
Intrepid::FunctionSpaceTools::integrate<Real>(velYvelY_jac, |
| 562 |
*(feVel_->DNDdetJ(1)), // dPhi/dy |
| 563 |
*valVelYPhi_eval, // L Phi |
| 564 |
Intrepid::COMP_CPP, |
| 565 |
true); |
| 566 |
Intrepid::FunctionSpaceTools::integrate<Real>(velYvelX_jac, |
| 567 |
*(feVel_->DNDdetJ(0)), // dPhi/dx |
| 568 |
*valVelYPhi_eval, // L Phi |
| 569 |
Intrepid::COMP_CPP, |
| 570 |
false); |
| 571 |
Intrepid::FunctionSpaceTools::integrate<Real>(velYvelX_jac, |
| 572 |
*valVelXPhi_eval, // L Phi |
| 573 |
*(feVel_->DNDdetJ(1)), // dPhi/dy |
| 574 |
Intrepid::COMP_CPP, |
| 575 |
true); |
| 576 |
|
| 577 |
// Combine the Hessians. |
| 578 |
fieldHelper_->combineFieldCoeff(hess, J); |
| 579 |
|
| 580 |
} |
| 581 |
|
| 582 |
void Hessian_12(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess, |
| 583 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff, |
| 584 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_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_12): Hessian is zero."); |
| 588 |
} |
| 589 |
|
| 590 |
void Hessian_13(std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> & hess, |
| 591 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff, |
| 592 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 593 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 594 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 595 |
throw Exception::Zero(">>> (PDE_NavierStokes::Hessian_13): Hessian is zero."); |
| 596 |
} |
| 597 |
|
| 598 |
void Hessian_21(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess, |
| 599 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff, |
| 600 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 601 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 602 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 603 |
throw Exception::Zero(">>> (PDE_NavierStokes::Hessian_21): Hessian is zero."); |
| 604 |
} |
| 605 |
|
| 606 |
void Hessian_22(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess, |
| 607 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff, |
| 608 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 609 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 610 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 611 |
throw Exception::Zero(">>> (PDE_NavierStokes::Hessian_22): Hessian is zero."); |
| 612 |
} |
| 613 |
|
| 614 |
void Hessian_23(std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> & hess, |
| 615 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff, |
| 616 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 617 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 618 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 619 |
throw Exception::Zero(">>> (PDE_NavierStokes::Hessian_23): Hessian is zero."); |
| 620 |
} |
| 621 |
|
| 622 |
void Hessian_31(std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> & hess, |
| 623 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff, |
| 624 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 625 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 626 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 627 |
throw Exception::Zero(">>> (PDE_NavierStokes::Hessian_31): Hessian is zero."); |
| 628 |
} |
| 629 |
|
| 630 |
void Hessian_32(std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> & hess, |
| 631 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff, |
| 632 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 633 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 634 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 635 |
throw Exception::Zero(">>> (PDE_NavierStokes::Hessian_32): Hessian is zero."); |
| 636 |
} |
| 637 |
|
| 638 |
void Hessian_33(std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>>> & hess, |
| 639 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff, |
| 640 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 641 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 642 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 643 |
if (z_param != ROL::nullPtr) { |
| 644 |
// Retrieve dimensions. |
| 645 |
int size = z_param->size(); |
| 646 |
int c = u_coeff->dimension(0); |
| 647 |
std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> tmp(size,ROL::nullPtr); |
| 648 |
hess.clear(); hess.resize(size,tmp); |
| 649 |
for (int i = 0; i < size; ++i) { |
| 650 |
for (int j = 0; j < size; ++j) { |
| 651 |
hess[i][j] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, numDofs_); |
| 652 |
} |
| 653 |
} |
| 654 |
} |
| 655 |
else { |
| 656 |
throw Exception::Zero(">>> (PDE_NavierStokes::Hessian_33): Hessian is zero."); |
| 657 |
} |
| 658 |
} |
| 659 |
|
| 660 |
void RieszMap_1(ROL::Ptr<Intrepid::FieldContainer<Real>> & riesz) { |
| 661 |
// Retrieve dimensions. |
| 662 |
int c = feVel_->N()->dimension(0); |
| 663 |
int fv = basisPtrVel_->getCardinality(); |
| 664 |
int fp = basisPtrPrs_->getCardinality(); |
| 665 |
|
| 666 |
// Initialize residuals. |
| 667 |
Intrepid::FieldContainer<Real> velXvelX_jac(c, fv, fv); |
| 668 |
Intrepid::FieldContainer<Real> velXvelY_jac(c, fv, fv); |
| 669 |
Intrepid::FieldContainer<Real> velXpres_jac(c, fv, fp); |
| 670 |
Intrepid::FieldContainer<Real> velYvelX_jac(c, fv, fv); |
| 671 |
Intrepid::FieldContainer<Real> velYvelY_jac(c, fv, fv); |
| 672 |
Intrepid::FieldContainer<Real> velYpres_jac(c, fv, fp); |
| 673 |
Intrepid::FieldContainer<Real> presvelX_jac(c, fp, fv); |
| 674 |
Intrepid::FieldContainer<Real> presvelY_jac(c, fp, fv); |
| 675 |
Intrepid::FieldContainer<Real> prespres_jac(c, fp, fp); |
| 676 |
std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>>> J; |
| 677 |
J.resize(numFields_); |
| 678 |
J[0].resize(numFields_); |
| 679 |
J[1].resize(numFields_); |
| 680 |
J[2].resize(numFields_); |
| 681 |
J[0][0] = ROL::makePtrFromRef(velXvelX_jac); J[0][1] = ROL::makePtrFromRef(velXvelY_jac); J[0][2] = ROL::makePtrFromRef(velXpres_jac); |
| 682 |
J[1][0] = ROL::makePtrFromRef(velYvelX_jac); J[1][1] = ROL::makePtrFromRef(velYvelY_jac); J[1][2] = ROL::makePtrFromRef(velYpres_jac); |
| 683 |
J[2][0] = ROL::makePtrFromRef(presvelX_jac); J[2][1] = ROL::makePtrFromRef(presvelY_jac); J[2][2] = ROL::makePtrFromRef(prespres_jac); |
| 684 |
|
| 685 |
*(J[0][0]) = *(feVel_->stiffMat()); |
| 686 |
Intrepid::RealSpaceTools<Real>::add(*(J[0][0]),*(feVel_->massMat())); |
| 687 |
*(J[1][1]) = *(feVel_->stiffMat()); |
| 688 |
Intrepid::RealSpaceTools<Real>::add(*(J[1][1]),*(feVel_->massMat())); |
| 689 |
*(J[2][2]) = *(fePrs_->massMat()); |
| 690 |
|
| 691 |
// Combine the jacobians. |
| 692 |
fieldHelper_->combineFieldCoeff(riesz, J); |
| 693 |
} |
| 694 |
|
| 695 |
void RieszMap_2(ROL::Ptr<Intrepid::FieldContainer<Real>> & riesz) { |
| 696 |
// Retrieve dimensions. |
| 697 |
int c = feVel_->N()->dimension(0); |
| 698 |
int fv = basisPtrVel_->getCardinality(); |
| 699 |
int fp = basisPtrPrs_->getCardinality(); |
| 700 |
|
| 701 |
// Initialize residuals. |
| 702 |
Intrepid::FieldContainer<Real> velXvelX_jac(c, fv, fv); |
| 703 |
Intrepid::FieldContainer<Real> velXvelY_jac(c, fv, fv); |
| 704 |
Intrepid::FieldContainer<Real> velXpres_jac(c, fv, fp); |
| 705 |
Intrepid::FieldContainer<Real> velYvelX_jac(c, fv, fv); |
| 706 |
Intrepid::FieldContainer<Real> velYvelY_jac(c, fv, fv); |
| 707 |
Intrepid::FieldContainer<Real> velYpres_jac(c, fv, fp); |
| 708 |
Intrepid::FieldContainer<Real> presvelX_jac(c, fp, fv); |
| 709 |
Intrepid::FieldContainer<Real> presvelY_jac(c, fp, fv); |
| 710 |
Intrepid::FieldContainer<Real> prespres_jac(c, fp, fp); |
| 711 |
std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>>> J; |
| 712 |
J.resize(numFields_); |
| 713 |
J[0].resize(numFields_); |
| 714 |
J[1].resize(numFields_); |
| 715 |
J[2].resize(numFields_); |
| 716 |
J[0][0] = ROL::makePtrFromRef(velXvelX_jac); J[0][1] = ROL::makePtrFromRef(velXvelY_jac); J[0][2] = ROL::makePtrFromRef(velXpres_jac); |
| 717 |
J[1][0] = ROL::makePtrFromRef(velYvelX_jac); J[1][1] = ROL::makePtrFromRef(velYvelY_jac); J[1][2] = ROL::makePtrFromRef(velYpres_jac); |
| 718 |
J[2][0] = ROL::makePtrFromRef(presvelX_jac); J[2][1] = ROL::makePtrFromRef(presvelY_jac); J[2][2] = ROL::makePtrFromRef(prespres_jac); |
| 719 |
|
| 720 |
*(J[0][0]) = *(feVel_->stiffMat()); |
| 721 |
Intrepid::RealSpaceTools<Real>::add(*(J[0][0]),*(feVel_->massMat())); |
| 722 |
*(J[1][1]) = *(feVel_->stiffMat()); |
| 723 |
Intrepid::RealSpaceTools<Real>::add(*(J[1][1]),*(feVel_->massMat())); |
| 724 |
*(J[2][2]) = *(fePrs_->massMat()); |
| 725 |
|
| 726 |
// Combine the jacobians. |
| 727 |
fieldHelper_->combineFieldCoeff(riesz, J); |
| 728 |
} |
| 729 |
|
| 730 |
std::vector<ROL::Ptr<Intrepid::Basis<Real, Intrepid::FieldContainer<Real>>>> getFields() { |
| 731 |
return basisPtrs_; |
| 732 |
} |
| 733 |
|
| 734 |
void setCellNodes(const ROL::Ptr<Intrepid::FieldContainer<Real>> &volCellNodes, |
| 735 |
const std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>>> &bdryCellNodes, |
| 736 |
const std::vector<std::vector<std::vector<int>>> &bdryCellLocIds) { |
| 737 |
volCellNodes_ = volCellNodes; |
| 738 |
bdryCellLocIds_ = bdryCellLocIds; |
| 739 |
// Finite element definition. |
| 740 |
feVel_ = ROL::makePtr<FE<Real>>(volCellNodes,basisPtrVel_,cellCub_); |
| 741 |
fePrs_ = ROL::makePtr<FE<Real>>(volCellNodes,basisPtrPrs_,cellCub_); |
| 742 |
fvidx_ = feVel_->getBoundaryDofs(); |
| 743 |
fpidx_ = fePrs_->getBoundaryDofs(); |
| 744 |
// Construct control boundary FE |
| 745 |
int numSideSets = bdryCellNodes.size();; |
| 746 |
feVelBdry_.resize(numSideSets); |
| 747 |
for (int i = 0; i < numSideSets; ++i) { |
| 748 |
int numLocSides = bdryCellNodes[i].size(); |
| 749 |
feVelBdry_[i].resize(numLocSides); |
| 750 |
for (int j = 0; j < numLocSides; ++j) { |
| 751 |
if (bdryCellNodes[i][j] != ROL::nullPtr) { |
| 752 |
feVelBdry_[i][j] = ROL::makePtr<FE<Real>>(bdryCellNodes[i][j],basisPtrVel_,bdryCub_,j); |
| 753 |
} |
| 754 |
} |
| 755 |
} |
| 756 |
} |
| 757 |
|
| 758 |
void setFieldPattern(const std::vector<std::vector<int>> & fieldPattern) { |
| 759 |
fieldPattern_ = fieldPattern; |
| 760 |
fieldHelper_ = ROL::makePtr<FieldHelper<Real>>(numFields_, numDofs_, numFieldDofs_, fieldPattern_); |
| 761 |
} |
| 762 |
|
| 763 |
const ROL::Ptr<FE<Real>> getVelocityFE(void) const { |
| 764 |
return feVel_; |
| 765 |
} |
| 766 |
|
| 767 |
const ROL::Ptr<FE<Real>> getPressureFE(void) const { |
| 768 |
return fePrs_; |
| 769 |
} |
| 770 |
|
| 771 |
const ROL::Ptr<Intrepid::FieldContainer<Real> > getCellNodes(void) const { |
| 772 |
return volCellNodes_; |
| 773 |
} |
| 774 |
|
| 775 |
const std::vector<ROL::Ptr<FE<Real>>> getVelocityBdryFE(const int sideset = -1) const { |
| 776 |
int side = (sideset < 0 ? 4 : sideset); |
| 777 |
return feVelBdry_[side]; |
| 778 |
} |
| 779 |
|
| 780 |
const std::vector<std::vector<int>> getBdryCellLocIds(const int sideset = -1) const { |
| 781 |
int side = (sideset < 0 ? 4 : sideset); |
| 782 |
return bdryCellLocIds_[side]; |
| 783 |
} |
| 784 |
|
| 785 |
const ROL::Ptr<FieldHelper<Real>> getFieldHelper(void) const { |
| 786 |
return fieldHelper_; |
| 787 |
} |
| 788 |
|
| 789 |
}; // PDE_NavierStokes |
| 790 |
|
| 791 |
#endif |