Debian Codegraph @

packages/rol/example/PDE-OPT/thermal-fluids/pde_thermal-fluids_ex03.hpp

raw
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_thermal-fluids.hpp
11 \brief Implements the local PDE interface for the Navier-Stokes control problem.
12 */
13
14 #ifndef PDE_THERMALFLUIDS_EX03_HPP
15 #define PDE_THERMALFLUIDS_EX03_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_ThermalFluids_ex03 : 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 ROL::Ptr<Intrepid::Basis<Real, Intrepid::FieldContainer<Real> > > basisPtrThr_;
36 std::vector<ROL::Ptr<Intrepid::Basis<Real, Intrepid::FieldContainer<Real> > > > basisPtrs_;
37 // Cell cubature information
38 ROL::Ptr<Intrepid::Cubature<Real> > cellCub_;
39 ROL::Ptr<Intrepid::Cubature<Real> > bdryCub_;
40 // Cell node information
41 ROL::Ptr<Intrepid::FieldContainer<Real> > volCellNodes_;
42 std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > > bdryCellNodes_;
43 std::vector<std::vector<std::vector<int> > > bdryCellLocIds_;
44 // Finite element definition
45 ROL::Ptr<FE<Real> > feVel_;
46 ROL::Ptr<FE<Real> > fePrs_;
47 ROL::Ptr<FE<Real> > feThr_;
48 std::vector<std::vector<ROL::Ptr<FE<Real> > > > feVelBdry_;
49 std::vector<std::vector<ROL::Ptr<FE<Real> > > > fePrsBdry_;
50 std::vector<std::vector<ROL::Ptr<FE<Real> > > > feThrBdry_;
51 // Local degrees of freedom on boundary, for each side of the reference cell (first index).
52 std::vector<std::vector<int> > fvidx_;
53 std::vector<std::vector<int> > fpidx_;
54 std::vector<std::vector<int> > fhidx_;
55 // Coordinates of degrees freedom on boundary cells.
56 // Indexing: [sideset number][local side id](cell number, value at dof)
57 std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > > bdryCellVDofValues_;
58 std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > > bdryCellTDofValues_;
59 // Field pattern, offsets, etc.
60 std::vector<std::vector<int> > fieldPattern_; // local Field/DOF pattern; set from DOF manager
61 int numFields_; // number of fields (equations in the PDE)
62 int numDofs_; // total number of degrees of freedom for all (local) fields
63 std::vector<int> offset_; // for each field, a counting offset
64 std::vector<int> numFieldDofs_; // for each field, number of degrees of freedom
65
66 // Problem parameters.
67 Real Re_, Pr_, Gr_, h_;
68 const Real grav_;
69 int Nbottom_, Nleft_, Nright_;
70 Real ReScale_, PrScale_, GrScale_, hScale_, TScale_;
71 bool pinPressure_;
72
73 ROL::Ptr<FieldHelper<Real> > fieldHelper_;
74
75 Real velocityDirichletFunc(const std::vector<Real> & coords, int sideset, int locSideId, int dir) const {
76 Real val(0);
77 if ((sideset==3) && (dir==1)) {
78 const Real one(1), two(2), three(3), four(4), x = coords[0];
79 if (x <= one/three) {
80 val = two*(one/three - x)*x;
81 }
82 else if (x > one/three && x < two/three) {
83 val = -four*(x-one/three)*(two/three-x);
84 }
85 else if (x >= two/three) {
86 val = two*(x-two/three)*(one-x);
87 }
88 }
89 return val;
90 }
91
92 Real thermalDirichletFunc(const std::vector<Real> & coords, int sideset, int locSideId) const {
93 const std::vector<Real> param = PDE<Real>::getParameter();
94 Real val(0);
95 if (sideset==0) {
96 val = static_cast<Real>(1);
97 if (param.size()) {
98 Real root2(std::sqrt(2.0)), pi(M_PI), ln2(std::log(2.0));
99 for (int i = 0; i < Nbottom_; ++i) {
100 Real di(i+1);
101 val += TScale_ * param[i]/ln2 * (root2 * std::sin(di * pi * coords[0]))/(di * pi);
102 }
103 }
104 }
105 else if (sideset==5) {
106 val = static_cast<Real>(0);
107 }
108 return val;
109 }
110
111 void computeDirichlet(void) {
112 // Compute Dirichlet values at DOFs.
113 int d = basisPtrVel_->getBaseCellTopology().getDimension();
114 int fv = basisPtrVel_->getCardinality();
115 int ft = basisPtrThr_->getCardinality();
116 int numSidesets = bdryCellLocIds_.size();
117 bdryCellVDofValues_.resize(numSidesets);
118 bdryCellTDofValues_.resize(numSidesets);
119 for (int i=0; i<numSidesets; ++i) {
120 int numLocSides = bdryCellLocIds_[i].size();
121 bdryCellVDofValues_[i].resize(numLocSides);
122 bdryCellTDofValues_[i].resize(numLocSides);
123 for (int j=0; j<numLocSides; ++j) {
124 int c = bdryCellLocIds_[i][j].size();
125 bdryCellVDofValues_[i][j] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv, d);
126 bdryCellTDofValues_[i][j] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, ft);
127 ROL::Ptr<Intrepid::FieldContainer<Real> > Vcoords, Tcoords;
128 Vcoords = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv, d);
129 Tcoords = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, ft, d);
130 if (c > 0) {
131 feVel_->computeDofCoords(Vcoords, bdryCellNodes_[i][j]);
132 feThr_->computeDofCoords(Tcoords, bdryCellNodes_[i][j]);
133 }
134 for (int k=0; k<c; ++k) {
135 for (int l=0; l<fv; ++l) {
136 std::vector<Real> dofpoint(d);
137 //std::cout << "Sideset " << i << " LocalSide " << j << " Cell " << k << " Field " << l << " Coord ";
138 for (int m=0; m<d; ++m) {
139 dofpoint[m] = (*Vcoords)(k, l, m);
140 //std::cout << dofpoint[m] << " ";
141 }
142
143 for (int m=0; m<d; ++m) {
144 (*bdryCellVDofValues_[i][j])(k, l, m) = velocityDirichletFunc(dofpoint, i, j, m);
145 //std::cout << " " << m << "-Value " << DirichletFunc(dofpoint, i, j, m);
146 }
147 //std::cout << std::endl;
148 }
149 for (int l=0; l<ft; ++l) {
150 std::vector<Real> dofpoint(d);
151 //std::cout << "Sideset " << i << " LocalSide " << j << " Cell " << k << " Field " << l << " Coord ";
152 for (int m=0; m<d; ++m) {
153 dofpoint[m] = (*Tcoords)(k, l, m);
154 //std::cout << dofpoint[m] << " ";
155 }
156
157 (*bdryCellTDofValues_[i][j])(k, l) = thermalDirichletFunc(dofpoint, i, j);
158 //std::cout << " Value " << DirichletFunc(dofpoint, i, j);
159 //std::cout << std::endl;
160 }
161 }
162 }
163 }
164 }
165
166 Real ReynoldsNumber(void) const {
167 const std::vector<Real> param = PDE<Real>::getParameter();
168 Real val = Re_;
169 if (param.size()) {
170 int offset = Nbottom_ + Nright_ + Nleft_;
171 Real one(1);
172 val /= (one + ReScale_*param[offset]);
173 }
174 return val;
175 }
176
177 Real PrandtlNumber(void) const {
178 const std::vector<Real> param = PDE<Real>::getParameter();
179 Real val = Pr_;
180 if (param.size()) {
181 int offset = Nbottom_ + Nright_ + Nleft_;
182 Real one(1);
183 val *= (one + ReScale_*param[offset])/(one + PrScale_*param[offset+1]);
184 }
185 return val;
186 }
187
188 Real GrashofNumber(void) const {
189 const std::vector<Real> param = PDE<Real>::getParameter();
190 Real val = Gr_;
191 if (param.size()) {
192 int offset = Nbottom_ + Nright_ + Nleft_;
193 Real one(1), muscale = one + ReScale_*param[offset];
194 val *= (one + GrScale_*param[offset+2])/(muscale*muscale);
195 }
196 return val;
197 }
198
199 Real ThicknessNumber(const std::vector<Real> &x, const int sideset) const {
200 const std::vector<Real> param = PDE<Real>::getParameter();
201 Real val = h_;
202 if ( param.size()) {
203 if ( sideset == 2 ) {
204 int offset = Nbottom_;
205 Real root2(std::sqrt(2.0)), pi(M_PI), ln2(std::log(2.0));
206 for (int i = 0; i < Nleft_; ++i) {
207 Real di(i+1);
208 val += hScale_ * param[offset + i]/ln2 * (root2 * std::sin(di * pi * x[1]))/(di * pi);
209 }
210 }
211 else if ( sideset == 1 ) {
212 int offset = Nbottom_ + Nleft_;
213 Real root2(std::sqrt(2.0)), pi(M_PI), ln2(std::log(2.0));
214 for (int i = 0; i < Nright_; ++i) {
215 Real di(i+1);
216 val += hScale_ * param[offset + i]/ln2 * (root2 * std::sin(di * pi * x[1]))/(di * pi);
217 }
218 }
219 }
220 return val;
221 }
222
223 Real viscosityFunc(const std::vector<Real> &x) const {
224 Real ReynoldsNum = ReynoldsNumber();
225 return static_cast<Real>(1)/ReynoldsNum;
226 }
227
228 Real conductivityFunc(const std::vector<Real> &x) const {
229 Real ReynoldsNum = ReynoldsNumber();
230 Real PrandtlNum = PrandtlNumber();
231 return static_cast<Real>(1)/(ReynoldsNum*PrandtlNum);
232 }
233
234 Real gravityFunc(const std::vector<Real> &x) const {
235 Real ReynoldsNum = ReynoldsNumber();
236 Real GrashofNum = GrashofNumber();
237 return grav_*GrashofNum/(ReynoldsNum*ReynoldsNum);
238 }
239
240 Real thermalRobinFunc(const std::vector<Real> &x, const int sideset) const {
241 return ThicknessNumber(x, sideset) * conductivityFunc(x);
242 }
243
244 void computeCoefficients(const ROL::Ptr<Intrepid::FieldContainer<Real> > &nu,
245 const ROL::Ptr<Intrepid::FieldContainer<Real> > &grav,
246 const ROL::Ptr<Intrepid::FieldContainer<Real> > &kappa) const {
247 int c = feVel_->gradN()->dimension(0);
248 int p = feVel_->gradN()->dimension(2);
249 int d = feVel_->gradN()->dimension(3);
250 std::vector<Real> pt(d);
251 for (int i = 0; i < c; ++i) {
252 for (int j = 0; j < p; ++j) {
253 for ( int k = 0; k < d; ++k) {
254 pt[k] = (*feVel_->cubPts())(i,j,k);
255 }
256 // Compute spatially dependent coefficients
257 (*nu)(i,j) = viscosityFunc(pt);
258 (*grav)(i,j) = gravityFunc(pt);
259 (*kappa)(i,j) = conductivityFunc(pt);
260 }
261 }
262 }
263
264 void computeThermalRobin(ROL::Ptr<Intrepid::FieldContainer<Real> > &robin,
265 const ROL::Ptr<Intrepid::FieldContainer<Real> > &u,
266 const ROL::Ptr<Intrepid::FieldContainer<Real> > &z,
267 const int sideset,
268 const int locSideId,
269 const int deriv = 0,
270 const int component = 1) const {
271 const int c = u->dimension(0);
272 const int p = u->dimension(1);
273 const int d = feThr_->gradN()->dimension(3);
274 std::vector<Real> x(d);
275 Real h(0);
276 for (int i = 0; i < c; ++i) {
277 for (int j = 0; j < p; ++j) {
278 for (int k = 0; k < d; ++k) {
279 x[k] = (*feThrBdry_[sideset][locSideId]->cubPts())(i,j,k);
280 }
281 h = thermalRobinFunc(x, sideset);
282 if ( deriv == 0 ) {
283 (*robin)(i,j) = h * ((*u)(i,j) - (*z)(i,j));
284 }
285 else if ( deriv == 1 ) {
286 (*robin)(i,j) = ((component==0) ? h : -h);
287 }
288 else {
289 (*robin)(i,j) = static_cast<Real>(0);
290 }
291 }
292 }
293 }
294
295 ROL::Ptr<Intrepid::FieldContainer<Real> > getThermalBoundaryCoeff(
296 const Intrepid::FieldContainer<Real> & cell_coeff,
297 int sideSet, int cell) const {
298 std::vector<int> bdryCellLocId = bdryCellLocIds_[sideSet][cell];
299 const int numCellsSide = bdryCellLocId.size();
300 const int f = basisPtrThr_->getCardinality();
301
302 ROL::Ptr<Intrepid::FieldContainer<Real > > bdry_coeff
303 = ROL::makePtr<Intrepid::FieldContainer<Real >>(numCellsSide, f);
304 for (int i = 0; i < numCellsSide; ++i) {
305 for (int j = 0; j < f; ++j) {
306 (*bdry_coeff)(i, j) = cell_coeff(bdryCellLocId[i], j);
307 }
308 }
309 return bdry_coeff;
310 }
311
312 public:
313 PDE_ThermalFluids_ex03(Teuchos::ParameterList &parlist) : grav_(-1) {
314 // Finite element fields -- NOT DIMENSION INDEPENDENT!
315 basisPtrVel_ = ROL::makePtr<Intrepid::Basis_HGRAD_QUAD_C2_FEM<Real, Intrepid::FieldContainer<Real> >>();
316 basisPtrPrs_ = ROL::makePtr<Intrepid::Basis_HGRAD_QUAD_C1_FEM<Real, Intrepid::FieldContainer<Real> >>();
317 basisPtrThr_ = ROL::makePtr<Intrepid::Basis_HGRAD_QUAD_C2_FEM<Real, Intrepid::FieldContainer<Real> >>();
318 // Volume quadrature rules.
319 shards::CellTopology cellType = basisPtrVel_->getBaseCellTopology(); // get the cell type from any basis
320 Intrepid::DefaultCubatureFactory<Real> cubFactory; // create cubature factory
321 int cubDegree = parlist.sublist("Problem").get("Cubature Degree", 4); // set cubature degree, e.g., 4
322 cellCub_ = cubFactory.create(cellType, cubDegree); // create default cubature
323 // Boundary quadrature rules.
324 int d = cellType.getDimension();
325 shards::CellTopology bdryCellType = cellType.getCellTopologyData(d-1, 0);
326 int bdryCubDegree = parlist.sublist("Problem").get("Boundary Cubature Degree",4); // set cubature degree, e.g., 4
327 bdryCub_ = cubFactory.create(bdryCellType, bdryCubDegree);
328 // Fill finite element basis container
329 basisPtrs_.clear();
330 for (int i = 0; i < d; ++i) {
331 basisPtrs_.push_back(basisPtrVel_); // Velocity
332 }
333 basisPtrs_.push_back(basisPtrPrs_); // Pressure
334 basisPtrs_.push_back(basisPtrThr_); // Heat
335
336 // Other problem parameters.
337 Re_ = parlist.sublist("Problem").get("Reynolds Number", 200.0);
338 Pr_ = parlist.sublist("Problem").get("Prandtl Number", 0.72);
339 Gr_ = parlist.sublist("Problem").get("Grashof Number", 40000.0);
340 h_ = parlist.sublist("Problem").get("Robin Coefficient", 1.0);
341 // Stochastic Expansion Information.
342 Nbottom_ = parlist.sublist("Problem").get("Bottom KL Truncation Order",5);
343 Nleft_ = parlist.sublist("Problem").get("Left KL Truncation Order",5);
344 Nright_ = parlist.sublist("Problem").get("Right KL Truncation Order",5);
345 // Stochastic scales
346 ReScale_ = parlist.sublist("Problem").get("Reynolds Number Noise Scale",0.05);
347 PrScale_ = parlist.sublist("Problem").get("Prandtl Number Noise Scale",0.05);
348 GrScale_ = parlist.sublist("Problem").get("Grashof Number Noise Scale",0.05);
349 hScale_ = parlist.sublist("Problem").get("Robin Noise Scale",0.2);
350 TScale_ = parlist.sublist("Problem").get("Bottom Temperature Noise Scale",0.2);
351 // Pin pressure
352 pinPressure_ = parlist.sublist("Problem").get("Pin Pressure",true);
353
354 numDofs_ = 0;
355 numFields_ = basisPtrs_.size();
356 offset_.resize(numFields_);
357 numFieldDofs_.resize(numFields_);
358 for (int i=0; i<numFields_; ++i) {
359 if (i==0) {
360 offset_[i] = 0;
361 }
362 else {
363 offset_[i] = offset_[i-1] + basisPtrs_[i-1]->getCardinality();
364 }
365 numFieldDofs_[i] = basisPtrs_[i]->getCardinality();
366 numDofs_ += numFieldDofs_[i];
367 }
368 }
369
370 void residual(ROL::Ptr<Intrepid::FieldContainer<Real> > & res,
371 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
372 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
373 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
374 // Retrieve dimensions.
375 int c = u_coeff->dimension(0);
376 int p = cellCub_->getNumPoints();
377 int fv = basisPtrVel_->getCardinality();
378 int fp = basisPtrPrs_->getCardinality();
379 int fh = basisPtrThr_->getCardinality();
380 int d = cellCub_->getDimension();
381
382 // Initialize residuals.
383 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > R(d+2);
384 for (int i = 0; i < d; ++i) {
385 R[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv);
386 }
387 R[d] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fp);
388 R[d+1] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fh);
389
390 // Split u_coeff into components.
391 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > U, Z;
392 fieldHelper_->splitFieldCoeff(U, u_coeff);
393 fieldHelper_->splitFieldCoeff(Z, z_coeff);
394
395 // Evaluate problem coefficients at quadrature points.
396 ROL::Ptr<Intrepid::FieldContainer<Real> > nu, grav, kappa;
397 nu = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
398 grav = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
399 kappa = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
400 computeCoefficients(nu,grav,kappa);
401
402 // Evaluate/interpolate finite element fields on cells.
403 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > valVel_vec(d);
404 for (int i = 0; i < d; ++i) {
405 valVel_vec[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
406 feVel_->evaluateValue(valVel_vec[i], U[i]);
407 }
408 ROL::Ptr<Intrepid::FieldContainer<Real> > valPres_eval, valHeat_eval;
409 valPres_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
410 valHeat_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
411 fePrs_->evaluateValue(valPres_eval, U[d]);
412 feThr_->evaluateValue(valHeat_eval, U[d+1]);
413 // Evaluate/interpolate gradient of finite element fields on cells.
414 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > gradVel_vec(d);
415 for (int i = 0; i < d; ++i) {
416 gradVel_vec[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d);
417 feVel_->evaluateGradient(gradVel_vec[i], U[i]);
418 }
419 ROL::Ptr<Intrepid::FieldContainer<Real> > gradHeat_eval;
420 gradHeat_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d);
421 feThr_->evaluateGradient(gradHeat_eval, U[d+1]);
422
423 // Assemble the velocity vector and its divergence.
424 ROL::Ptr<Intrepid::FieldContainer<Real> > valVel_eval, divVel_eval;
425 valVel_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d);
426 divVel_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
427 for (int i = 0; i < c; ++i) {
428 for (int j = 0; j < p; ++j) {
429 (*divVel_eval)(i,j) = static_cast<Real>(0);
430 for (int k = 0; k < d; ++k) {
431 (*valVel_eval)(i,j,k) = (*valVel_vec[k])(i,j);
432 (*divVel_eval)(i,j) += (*gradVel_vec[k])(i,j,k);
433 }
434 }
435 }
436
437 /**************************************************************************/
438 /*** NAVIER STOKES ********************************************************/
439 /**************************************************************************/
440 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > nuGradVel_vec(d), valVelDotgradVel_vec(d);
441 for (int i = 0; i < d; ++i) {
442 // Multiply velocity gradients with viscosity.
443 nuGradVel_vec[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d);
444 Intrepid::FunctionSpaceTools::tensorMultiplyDataData<Real>(*nuGradVel_vec[i], *nu, *gradVel_vec[i]);
445 // Compute nonlinear terms in the Navier-Stokes equations.
446 valVelDotgradVel_vec[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
447 Intrepid::FunctionSpaceTools::dotMultiplyDataData<Real>(*valVelDotgradVel_vec[i], *valVel_eval, *gradVel_vec[i]);
448 }
449 // Negative pressure
450 Intrepid::RealSpaceTools<Real>::scale(*valPres_eval,static_cast<Real>(-1));
451 // Compute gravitational force.
452 ROL::Ptr<Intrepid::FieldContainer<Real> > gravForce;
453 gravForce = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
454 Intrepid::FunctionSpaceTools::scalarMultiplyDataData<Real>(*gravForce, *grav, *valHeat_eval);
455
456 /**************************************************************************/
457 /*** THERMAL **************************************************************/
458 /**************************************************************************/
459 ROL::Ptr<Intrepid::FieldContainer<Real> > kappaGradHeat_eval, velDotGradHeat_eval;
460 kappaGradHeat_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d);
461 velDotGradHeat_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
462 // Multiply temperature gradient with conductivity
463 Intrepid::FunctionSpaceTools::tensorMultiplyDataData<Real>(*kappaGradHeat_eval, *kappa, *gradHeat_eval);
464 // Dot multiply scaled velocity with temperature gradient
465 Intrepid::FunctionSpaceTools::dotMultiplyDataData<Real>(*velDotGradHeat_eval, *valVel_eval, *gradHeat_eval);
466
467 /**************************************************************************/
468 /*** EVALUATE WEAK FORM OF RESIDUAL ***************************************/
469 /**************************************************************************/
470 // Velocity equation.
471 for (int i = 0; i < d; ++i) {
472 Intrepid::FunctionSpaceTools::integrate<Real>((*R[i]),
473 *nuGradVel_vec[i], // nu gradUX
474 *(feVel_->gradNdetJ()), // gradPhi
475 Intrepid::COMP_CPP,
476 false);
477 Intrepid::FunctionSpaceTools::integrate<Real>((*R[i]),
478 *valVelDotgradVel_vec[i], // (U . gradUX)
479 *(feVel_->NdetJ()), // Phi
480 Intrepid::COMP_CPP,
481 true);
482 Intrepid::FunctionSpaceTools::integrate<Real>((*R[i]),
483 *valPres_eval, // p
484 *(feVel_->DNDdetJ(i)), // dPhi/dx
485 Intrepid::COMP_CPP,
486 true);
487 }
488 // Apply gravitational force.
489 Intrepid::FunctionSpaceTools::integrate<Real>((*R[d-1]),
490 *gravForce, // grav T
491 *(feVel_->NdetJ()), // Phi
492 Intrepid::COMP_CPP,
493 true);
494 // Pressure equation.
495 Intrepid::FunctionSpaceTools::integrate<Real>((*R[d]),
496 *divVel_eval, // divU
497 *(fePrs_->NdetJ()), // Phi
498 Intrepid::COMP_CPP,
499 false);
500 Intrepid::RealSpaceTools<Real>::scale((*R[d]),static_cast<Real>(-1));
501 // Heat equation.
502 Intrepid::FunctionSpaceTools::integrate<Real>((*R[d+1]),
503 *kappaGradHeat_eval, // kappa gradT
504 *(feThr_->gradNdetJ()), // gradPhi
505 Intrepid::COMP_CPP,
506 false);
507 Intrepid::FunctionSpaceTools::integrate<Real>((*R[d+1]),
508 *velDotGradHeat_eval, // U . gradT
509 *(feThr_->NdetJ()), // Phi
510 Intrepid::COMP_CPP,
511 true);
512
513 /**************************************************************************/
514 /*** APPLY BOUNDARY CONDITIONS ********************************************/
515 /**************************************************************************/
516 // --> Control boundaries: i=1,2
517 // --> No slip boundaries: i=0,1,2
518 // --> Outflow/Inflow boundaries: i=3
519 // --> Pressure Pin: i=4
520 int numSideSets = bdryCellLocIds_.size();
521 const int numCubPerSide = bdryCub_->getNumPoints();
522 if (numSideSets > 0) {
523 // ROBIN CONDITIONS
524 for (int i = 0; i < numSideSets; ++i) {
525 // Control boundaries
526 if (i==1 || i==2) {
527 int numLocalSideIds = bdryCellLocIds_[i].size();
528 for (int j = 0; j < numLocalSideIds; ++j) {
529 int numCellsSide = bdryCellLocIds_[i][j].size();
530 if (numCellsSide) {
531 // Get U and Z coefficients on Robin boundary
532 ROL::Ptr<Intrepid::FieldContainer<Real > > u_coeff_bdry, z_coeff_bdry;
533 u_coeff_bdry = getThermalBoundaryCoeff(*(U[d+1]), i, j);
534 z_coeff_bdry = getThermalBoundaryCoeff(*(Z[d+1]), i, j);
535 // Evaluate U and Z on FE basis
536 ROL::Ptr<Intrepid::FieldContainer<Real > > valU_eval_bdry, valZ_eval_bdry;
537 valU_eval_bdry = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide);
538 valZ_eval_bdry = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide);
539 feThrBdry_[i][j]->evaluateValue(valU_eval_bdry, u_coeff_bdry);
540 feThrBdry_[i][j]->evaluateValue(valZ_eval_bdry, z_coeff_bdry);
541 // Compute Stefan-Boltzmann residual
542 ROL::Ptr<Intrepid::FieldContainer<Real> > robinVal;
543 robinVal = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide);
544 computeThermalRobin(robinVal,valU_eval_bdry,valZ_eval_bdry,i,j,0);
545 // Evaluate boundary integral
546 ROL::Ptr<Intrepid::FieldContainer<Real> > robinRes;
547 robinRes = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, fh);
548 Intrepid::FunctionSpaceTools::integrate<Real>(*robinRes,
549 *robinVal,
550 *(feThrBdry_[i][j]->NdetJ()),
551 Intrepid::COMP_CPP, false);
552 for (int k = 0; k < numCellsSide; ++k) {
553 int cidx = bdryCellLocIds_[i][j][k];
554 // Thermal boundary conditions.
555 for (int l = 0; l < fh; ++l) {
556 (*R[d+1])(cidx,l) += (*robinRes)(k,l);
557 }
558 }
559 }
560 }
561 }
562 }
563 // DIRICHLET CONDITIONS
564 computeDirichlet();
565 // Velocity Boundary Conditions
566 for (int i = 0; i < numSideSets; ++i) {
567 if (i<4) {
568 int numLocalSideIds = bdryCellLocIds_[i].size();
569 for (int j = 0; j < numLocalSideIds; ++j) {
570 int numCellsSide = bdryCellLocIds_[i][j].size();
571 int numVBdryDofs = fvidx_[j].size();
572 for (int k = 0; k < numCellsSide; ++k) {
573 int cidx = bdryCellLocIds_[i][j][k];
574 for (int l = 0; l < numVBdryDofs; ++l) {
575 for (int m = 0; m < d; ++m) {
576 (*R[m])(cidx,fvidx_[j][l]) = (*U[m])(cidx,fvidx_[j][l]) - (*bdryCellVDofValues_[i][j])(k,fvidx_[j][l],m);
577 }
578 }
579 }
580 }
581 }
582 // Thermal Boundary Conditions
583 if ( (i==0) || (i==5) ) {
584 int numLocalSideIds = bdryCellLocIds_[i].size(); // Number of sides per cell
585 for (int j = 0; j < numLocalSideIds; ++j) { // Loop over sides of cell: Quad = {0, 1, 2, 3}
586 int numCellsSide = bdryCellLocIds_[i][j].size(); // Number of cells with side j
587 int numHBdryDofs = fhidx_[j].size(); // Number of thermal boundary DOFs
588 for (int k = 0; k < numCellsSide; ++k) { // Loop over cells with side j
589 int cidx = bdryCellLocIds_[i][j][k]; // Cell index
590 for (int l = 0; l < numHBdryDofs; ++l) { // Loop over all fields of cell k on side j
591 (*R[d+1])(cidx,fhidx_[j][l]) = (*U[d+1])(cidx,fhidx_[j][l]) - (*bdryCellTDofValues_[i][j])(k,fhidx_[j][l]);
592 }
593 }
594 }
595 }
596 // Pressure pinning
597 if (i==7 && pinPressure_) {
598 int numLocalSideIds = bdryCellLocIds_[i].size();
599 for (int j = 0; j < numLocalSideIds; ++j) {
600 int numCellsSide = bdryCellLocIds_[i][j].size();
601 for (int k = 0; k < numCellsSide; ++k) {
602 int l = 0, cidx = bdryCellLocIds_[i][j][k];
603 (*R[d])(cidx,fpidx_[j][l]) = (*U[d])(cidx,fpidx_[j][l]) - static_cast<Real>(0);
604 }
605 }
606 }
607 }
608 }
609
610 // Combine the residuals.
611 fieldHelper_->combineFieldCoeff(res, R);
612 }
613
614 void Jacobian_1(ROL::Ptr<Intrepid::FieldContainer<Real> > & jac,
615 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
616 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
617 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
618 // Retrieve dimensions.
619 int c = u_coeff->dimension(0);
620 int p = cellCub_->getNumPoints();
621 int fv = basisPtrVel_->getCardinality();
622 int fp = basisPtrPrs_->getCardinality();
623 int fh = basisPtrThr_->getCardinality();
624 int d = cellCub_->getDimension();
625
626 // Initialize jacobians.
627 std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > > J(d+2);
628 for (int i = 0; i < d+2; ++i) {
629 J[i].resize(d+2);
630 }
631 for (int i = 0; i < d; ++i) {
632 for (int j = 0; j < d; ++j) {
633 J[i][j] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv, fv);
634 }
635 J[d][i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fp, fv);
636 J[i][d] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv, fp);
637 J[d+1][i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fh, fv);
638 J[i][d+1] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv, fh);
639 }
640 J[d][d] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fp, fp);
641 J[d+1][d] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fh, fp);
642 J[d][d+1] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fp, fh);
643 J[d+1][d+1] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fh, fh);
644
645 // Split u_coeff into components.
646 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > U, Z;
647 fieldHelper_->splitFieldCoeff(U, u_coeff);
648 fieldHelper_->splitFieldCoeff(Z, z_coeff);
649
650 // Evaluate problem coefficients at quadrature points.
651 ROL::Ptr<Intrepid::FieldContainer<Real> > nu, grav, kappa;
652 nu = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
653 grav = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
654 kappa = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
655 computeCoefficients(nu,grav,kappa);
656
657 // Evaluate/interpolate finite element fields on cells.
658 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > valVel_vec(d);
659 for (int i = 0; i < d; ++i) {
660 valVel_vec[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
661 feVel_->evaluateValue(valVel_vec[i], U[i]);
662 }
663 // Evaluate/interpolate gradient of finite element fields on cells.
664 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > gradVel_vec(d);
665 for (int i = 0; i < d; ++i) {
666 gradVel_vec[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d);
667 feVel_->evaluateGradient(gradVel_vec[i], U[i]);
668 }
669 ROL::Ptr<Intrepid::FieldContainer<Real> > gradHeat_eval;
670 gradHeat_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d);
671 feThr_->evaluateGradient(gradHeat_eval, U[d+1]);
672
673 // Assemble the velocity vector and its divergence.
674 ROL::Ptr<Intrepid::FieldContainer<Real> > valVel_eval;
675 valVel_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d);
676 std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > > dVel_vec(d);
677 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > gradHeat_vec(d);
678 for (int k = 0; k < d; ++k) {
679 dVel_vec[k].resize(d);
680 for (int l = 0; l < d; ++l) {
681 dVel_vec[k][l] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
682 for (int i = 0; i < c; ++i) {
683 for (int j = 0; j < p; ++j) {
684 (*dVel_vec[k][l])(i,j) = (*gradVel_vec[k])(i,j,l);
685 }
686 }
687 }
688 gradHeat_vec[k] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
689 for (int i = 0; i < c; ++i) {
690 for (int j = 0; j < p; ++j) {
691 (*valVel_eval)(i,j,k) = (*valVel_vec[k])(i,j);
692 (*gradHeat_vec[k])(i,j) = (*gradHeat_eval)(i,j,k);
693 }
694 }
695 }
696
697 /**************************************************************************/
698 /*** NAVIER STOKES ********************************************************/
699 /**************************************************************************/
700 std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > > dVelPhi_vec(d);
701 for (int i = 0; i < d; ++i) {
702 // Compute nonlinear terms in the Navier-Stokes equations.
703 dVelPhi_vec[i].resize(d);
704 for (int j = 0; j < d; ++j) {
705 dVelPhi_vec[i][j] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv, p);
706 Intrepid::FunctionSpaceTools::scalarMultiplyDataField<Real>(*dVelPhi_vec[i][j], *dVel_vec[i][j], *(feVel_->N()));
707 }
708 }
709 // Multiply velocity gradients with viscosity.
710 ROL::Ptr<Intrepid::FieldContainer<Real> > nuGradPhi_eval;
711 nuGradPhi_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv, p, d);
712 Intrepid::FunctionSpaceTools::tensorMultiplyDataField<Real>(*nuGradPhi_eval, *nu, *(feVel_->gradN()));
713 // Compute nonlinear terms in the Navier-Stokes equations.
714 ROL::Ptr<Intrepid::FieldContainer<Real> > valVelDotgradPhi_eval;
715 valVelDotgradPhi_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv, p);
716 Intrepid::FunctionSpaceTools::dotMultiplyDataField<Real>(*valVelDotgradPhi_eval, *valVel_eval, *(feVel_->gradN()));
717 // Negative pressure basis.
718 Intrepid::FieldContainer<Real> negPrsPhi(*(fePrs_->N()));
719 Intrepid::RealSpaceTools<Real>::scale(negPrsPhi,static_cast<Real>(-1));
720 // Compute gravity Jacobian
721 ROL::Ptr<Intrepid::FieldContainer<Real> > gravPhi;
722 gravPhi = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fh, p);
723 Intrepid::FunctionSpaceTools::scalarMultiplyDataField<Real>(*gravPhi, *grav, *(feThr_->N()));
724
725 /**************************************************************************/
726 /*** THERMAL **************************************************************/
727 /**************************************************************************/
728 ROL::Ptr<Intrepid::FieldContainer<Real> > kappaGradPhi, VelPhi;
729 kappaGradPhi = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fh, p, d);
730 VelPhi = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fh, p);
731 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > dHeatPhi(d);
732 // Compute kappa times gradient of basis.
733 Intrepid::FunctionSpaceTools::tensorMultiplyDataField<Real>(*kappaGradPhi, *kappa, *(feThr_->gradN()));
734 // Compute scaled velocity.
735 Intrepid::FunctionSpaceTools::dotMultiplyDataField<Real>(*VelPhi, *valVel_eval, *feThr_->gradN());
736 // Thermal-velocity Jacobians.
737 for (int i = 0; i < d; ++i) {
738 dHeatPhi[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fh, p);
739 Intrepid::FunctionSpaceTools::scalarMultiplyDataField<Real>(*dHeatPhi[i], *gradHeat_vec[i], *feThr_->N());
740 }
741
742 /*** Evaluate weak form of the Jacobian. ***/
743 // X component of velocity equation.
744 for (int i = 0; i < d; ++i) {
745 // Velocity components
746 for (int j = 0; j < d; ++j) {
747 Intrepid::FunctionSpaceTools::integrate<Real>((*J[i][j]),
748 *(feVel_->NdetJ()), // Phi
749 *dVelPhi_vec[i][j], // (Phi . gradU)
750 Intrepid::COMP_CPP,
751 false);
752 }
753 Intrepid::FunctionSpaceTools::integrate<Real>((*J[i][i]),
754 *nuGradPhi_eval, // nu gradPhi
755 *(feVel_->gradNdetJ()), // gradPhi
756 Intrepid::COMP_CPP,
757 true);
758 Intrepid::FunctionSpaceTools::integrate<Real>((*J[i][i]),
759 *(feVel_->NdetJ()), // Phi
760 *valVelDotgradPhi_eval, // (U . gradPhiX)
761 Intrepid::COMP_CPP,
762 true);
763 // Pressure components
764 Intrepid::FunctionSpaceTools::integrate<Real>((*J[i][d]),
765 *(feVel_->DNDdetJ(i)), // dPhi/dx
766 negPrsPhi, // -Phi
767 Intrepid::COMP_CPP,
768 false);
769 Intrepid::FunctionSpaceTools::integrate<Real>((*J[d][i]),
770 *(fePrs_->NdetJ()), // Phi
771 *(feVel_->DND(i)), // dPhi/dx
772 Intrepid::COMP_CPP,
773 false);
774 Intrepid::RealSpaceTools<Real>::scale((*J[d][i]),static_cast<Real>(-1));
775 // Thermal components
776 Intrepid::FunctionSpaceTools::integrate<Real>((*J[d+1][i]),
777 *dHeatPhi[i], // gradT Phi
778 *(feVel_->NdetJ()), // Phi
779 Intrepid::COMP_CPP,
780 false);
781 }
782 // Gravitational component
783 Intrepid::FunctionSpaceTools::integrate<Real>((*J[d-1][d+1]),
784 *(feVel_->NdetJ()), // Phi
785 *gravPhi, // grav Phi
786 Intrepid::COMP_CPP,
787 false);
788 // Thermal components
789 Intrepid::FunctionSpaceTools::integrate<Real>((*J[d+1][d+1]),
790 *kappaGradPhi, // kappa gradPhi
791 *(feThr_->gradNdetJ()), // gradPhi
792 Intrepid::COMP_CPP,
793 false);
794 Intrepid::FunctionSpaceTools::integrate<Real>((*J[d+1][d+1]),
795 *(feThr_->NdetJ()), // Phi
796 *VelPhi, // U . gradPhi
797 Intrepid::COMP_CPP,
798 true);
799
800 // APPLY BOUNDARY CONDITIONS
801 int numSideSets = bdryCellLocIds_.size();
802 const int numCubPerSide = bdryCub_->getNumPoints();
803 if (numSideSets > 0) {
804 // ROBIN CONDITIONS
805 for (int i = 0; i < numSideSets; ++i) {
806 // Control boundaries
807 if (i==1 || i==2) {
808 int numLocalSideIds = bdryCellLocIds_[i].size();
809 for (int j = 0; j < numLocalSideIds; ++j) {
810 int numCellsSide = bdryCellLocIds_[i][j].size();
811 ROL::Ptr<Intrepid::FieldContainer<Real> > robinJac;
812 if (numCellsSide) {
813 // Get U and Z coefficients on Robin boundary
814 ROL::Ptr<Intrepid::FieldContainer<Real > > u_coeff_bdry, z_coeff_bdry;
815 u_coeff_bdry = getThermalBoundaryCoeff(*(U[d+1]), i, j);
816 z_coeff_bdry = getThermalBoundaryCoeff(*(Z[d+1]), i, j);
817 // Evaluate U and Z on FE basis
818 ROL::Ptr<Intrepid::FieldContainer<Real > > valU_eval_bdry, valZ_eval_bdry;
819 valU_eval_bdry = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide);
820 valZ_eval_bdry = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide);
821 feThrBdry_[i][j]->evaluateValue(valU_eval_bdry, u_coeff_bdry);
822 feThrBdry_[i][j]->evaluateValue(valZ_eval_bdry, z_coeff_bdry);
823 // Compute Stefan-Boltzmann residual
824 ROL::Ptr< Intrepid::FieldContainer<Real> > robinVal1
825 = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide);
826 Intrepid::FieldContainer<Real> robinVal(numCellsSide, fh, numCubPerSide);
827 computeThermalRobin(robinVal1,valU_eval_bdry,valZ_eval_bdry,i,j,1,0);
828 Intrepid::FunctionSpaceTools::scalarMultiplyDataField<Real>(robinVal,
829 *robinVal1,
830 *(feThrBdry_[i][j]->N()));
831 // Evaluate boundary integral
832 robinJac = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, fh, fh);
833 Intrepid::FunctionSpaceTools::integrate<Real>(*robinJac,
834 robinVal,
835 *(feThrBdry_[i][j]->NdetJ()),
836 Intrepid::COMP_CPP, false);
837 for (int k = 0; k < numCellsSide; ++k) {
838 int cidx = bdryCellLocIds_[i][j][k];
839 for (int l = 0; l < fh; ++l) {
840 for (int m = 0; m < fh; ++m) {
841 (*J[d+1][d+1])(cidx,l,m) += (*robinJac)(k,l,m);
842 }
843 }
844 }
845 }
846 }
847 }
848 }
849 // DIRICHLET CONDITIONS
850 for (int i = 0; i < numSideSets; ++i) {
851 // Velocity Boundary Conditions
852 if (i<4) {
853 int numLocalSideIds = bdryCellLocIds_[i].size();
854 for (int j = 0; j < numLocalSideIds; ++j) {
855 int numCellsSide = bdryCellLocIds_[i][j].size();
856 int numVBdryDofs = fvidx_[j].size();
857 for (int k = 0; k < numCellsSide; ++k) {
858 int cidx = bdryCellLocIds_[i][j][k];
859 for (int l = 0; l < numVBdryDofs; ++l) {
860 for (int m = 0; m < fv; ++m) {
861 for (int n = 0; n < d; ++n) {
862 for (int p = 0; p < d; ++p) {
863 (*J[n][p])(cidx,fvidx_[j][l],m) = static_cast<Real>(0);
864 }
865 (*J[n][n])(cidx,fvidx_[j][l],fvidx_[j][l]) = static_cast<Real>(1);
866 }
867 }
868 for (int m = 0; m < d; ++m) {
869 for (int n = 0; n < fp; ++n) {
870 (*J[m][d])(cidx,fvidx_[j][l],n) = static_cast<Real>(0);
871 }
872 for (int n = 0; n < fh; ++n) {
873 (*J[m][d+1])(cidx,fvidx_[j][l],n) = static_cast<Real>(0);
874 }
875 }
876 }
877 }
878 }
879 }
880 // Thermal boundary conditions
881 if ( (i==0) || (i==5) ) {
882 int numLocalSideIds = bdryCellLocIds_[i].size();
883 for (int j = 0; j < numLocalSideIds; ++j) {
884 int numCellsSide = bdryCellLocIds_[i][j].size();
885 int numHBdryDofs = fhidx_[j].size();
886 for (int k = 0; k < numCellsSide; ++k) {
887 int cidx = bdryCellLocIds_[i][j][k];
888 for (int l = 0; l < numHBdryDofs; ++l) {
889 for (int m = 0; m < fv; ++m) {
890 for (int n = 0; n < d; ++n) {
891 (*J[d+1][n])(cidx,fhidx_[j][l],m) = static_cast<Real>(0);
892 }
893 }
894 for (int m = 0; m < fp; ++m) {
895 (*J[d+1][d])(cidx,fhidx_[j][l],m) = static_cast<Real>(0);
896 }
897 for (int m = 0; m < fh; ++m) {
898 (*J[d+1][d+1])(cidx,fhidx_[j][l],m) = static_cast<Real>(0);
899 }
900 (*J[d+1][d+1])(cidx,fhidx_[j][l],fhidx_[j][l]) = static_cast<Real>(1);
901 }
902 }
903 }
904 }
905 // Pressure pinning
906 if (i==7 && pinPressure_) {
907 int numLocalSideIds = bdryCellLocIds_[i].size();
908 for (int j = 0; j < numLocalSideIds; ++j) {
909 int numCellsSide = bdryCellLocIds_[i][j].size();
910 for (int k = 0; k < numCellsSide; ++k) {
911 int l = 0, cidx = bdryCellLocIds_[i][j][k];
912 for (int m = 0; m < fv; ++m) {
913 for (int n = 0; n < d; ++n) {
914 (*J[d][n])(cidx,fpidx_[j][l],m) = static_cast<Real>(0);
915 }
916 }
917 for (int m = 0; m < fp; ++m) {
918 (*J[d][d])(cidx,fpidx_[j][l],m) = static_cast<Real>(0);
919 }
920 (*J[d][d])(cidx,fpidx_[j][l],fpidx_[j][l]) = static_cast<Real>(1);
921 for (int m = 0; m < fh; ++m) {
922 (*J[d][d+1])(cidx,fpidx_[j][l],m) = static_cast<Real>(0);
923 }
924 }
925 }
926 }
927 }
928 }
929
930 // Combine the jacobians.
931 fieldHelper_->combineFieldCoeff(jac, J);
932
933 }
934
935
936 void Jacobian_2(ROL::Ptr<Intrepid::FieldContainer<Real> > & jac,
937 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
938 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
939 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
940 // Retrieve dimensions.
941 int c = u_coeff->dimension(0);
942 int fv = basisPtrVel_->getCardinality();
943 int fp = basisPtrPrs_->getCardinality();
944 int fh = basisPtrThr_->getCardinality();
945 int d = cellCub_->getDimension();
946
947 // Initialize jacobians.
948 std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > > J(d+2);
949 for (int i = 0; i < d+2; ++i) {
950 J[i].resize(d+2);
951 }
952 for (int i = 0; i < d; ++i) {
953 for (int j = 0; j < d; ++j) {
954 J[i][j] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv, fv);
955 }
956 J[d][i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fp, fv);
957 J[i][d] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv, fp);
958 J[d+1][i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fh, fv);
959 J[i][d+1] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv, fh);
960 }
961 J[d][d] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fp, fp);
962 J[d+1][d] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fh, fp);
963 J[d][d+1] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fp, fh);
964 J[d+1][d+1] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fh, fh);
965
966 // Split u_coeff into components.
967 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > U, Z;
968 fieldHelper_->splitFieldCoeff(U, u_coeff);
969 fieldHelper_->splitFieldCoeff(Z, z_coeff);
970
971 // APPLY DIRICHLET CONDITIONS
972 int numSideSets = bdryCellLocIds_.size();
973 const int numCubPerSide = bdryCub_->getNumPoints();
974 if (numSideSets > 0) {
975 for (int i = 0; i < numSideSets; ++i) {
976 // Control boundaries
977 if (i==1 || i==2) {
978 int numLocalSideIds = bdryCellLocIds_[i].size();
979 for (int j = 0; j < numLocalSideIds; ++j) {
980 int numCellsSide = bdryCellLocIds_[i][j].size();
981 if (numCellsSide) {
982 // Get U and Z coefficients on Robin boundary
983 ROL::Ptr<Intrepid::FieldContainer<Real > > u_coeff_bdry
984 = getThermalBoundaryCoeff(*(U[d+1]), i, j);
985 ROL::Ptr<Intrepid::FieldContainer<Real > > z_coeff_bdry
986 = getThermalBoundaryCoeff(*(Z[d+1]), i, j);
987 // Evaluate U and Z on FE basis
988 ROL::Ptr<Intrepid::FieldContainer<Real > > valU_eval_bdry
989 = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide);
990 ROL::Ptr<Intrepid::FieldContainer<Real > > valZ_eval_bdry
991 = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide);
992 feThrBdry_[i][j]->evaluateValue(valU_eval_bdry, u_coeff_bdry);
993 feThrBdry_[i][j]->evaluateValue(valZ_eval_bdry, z_coeff_bdry);
994 // Compute Stefan-Boltzmann residual
995 ROL::Ptr< Intrepid::FieldContainer<Real> > robinVal1
996 = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide);
997 Intrepid::FieldContainer<Real> robinVal(numCellsSide, fh, numCubPerSide);
998 computeThermalRobin(robinVal1,valU_eval_bdry,valZ_eval_bdry,i,j,1,1);
999 Intrepid::FunctionSpaceTools::scalarMultiplyDataField<Real>(robinVal,
1000 *robinVal1,
1001 *(feThrBdry_[i][j]->N()));
1002 // Evaluate boundary integral
1003 Intrepid::FieldContainer<Real> robinJac(numCellsSide, fh, fh);
1004 Intrepid::FunctionSpaceTools::integrate<Real>(robinJac,
1005 robinVal,
1006 *(feThrBdry_[i][j]->NdetJ()),
1007 Intrepid::COMP_CPP, false);
1008 for (int k = 0; k < numCellsSide; ++k) {
1009 int cidx = bdryCellLocIds_[i][j][k];
1010 for (int l = 0; l < fh; ++l) {
1011 for (int m = 0; m < fh; ++m) {
1012 (*J[d+1][d+1])(cidx,l,m) += robinJac(k,l,m);
1013 }
1014 }
1015 }
1016 }
1017 }
1018 }
1019 }
1020 // DIRICHLET CONDITIONS
1021 for (int i = 0; i < numSideSets; ++i) {
1022 // Velocity Boundary Conditions
1023 if (i<4) {
1024 int numLocalSideIds = bdryCellLocIds_[i].size();
1025 for (int j = 0; j < numLocalSideIds; ++j) {
1026 int numCellsSide = bdryCellLocIds_[i][j].size();
1027 int numVBdryDofs = fvidx_[j].size();
1028 for (int k = 0; k < numCellsSide; ++k) {
1029 int cidx = bdryCellLocIds_[i][j][k];
1030 for (int l = 0; l < numVBdryDofs; ++l) {
1031 for (int m = 0; m < fv; ++m) {
1032 for (int n = 0; n < d; ++n) {
1033 for (int p = 0; p < d; ++p) {
1034 (*J[n][p])(cidx,fvidx_[j][l],m) = static_cast<Real>(0);
1035 }
1036 }
1037 }
1038 for (int m = 0; m < d; ++m) {
1039 for (int n = 0; n < fp; ++n) {
1040 (*J[m][d])(cidx,fvidx_[j][l],n) = static_cast<Real>(0);
1041 }
1042 for (int n = 0; n < fh; ++n) {
1043 (*J[m][d+1])(cidx,fvidx_[j][l],n) = static_cast<Real>(0);
1044 }
1045 }
1046 }
1047 }
1048 }
1049 }
1050 // Thermal boundary conditions
1051 if ( (i==0) || (i==5) ) {
1052 int numLocalSideIds = bdryCellLocIds_[i].size();
1053 for (int j = 0; j < numLocalSideIds; ++j) {
1054 int numCellsSide = bdryCellLocIds_[i][j].size();
1055 int numHBdryDofs = fhidx_[j].size();
1056 for (int k = 0; k < numCellsSide; ++k) {
1057 int cidx = bdryCellLocIds_[i][j][k];
1058 for (int l = 0; l < numHBdryDofs; ++l) {
1059 for (int m = 0; m < fv; ++m) {
1060 for (int n = 0; n < d; ++n) {
1061 (*J[d+1][n])(cidx,fhidx_[j][l],m) = static_cast<Real>(0);
1062 }
1063 }
1064 for (int m = 0; m < fp; ++m) {
1065 (*J[d+1][d])(cidx,fhidx_[j][l],m) = static_cast<Real>(0);
1066 }
1067 for (int m = 0; m < fh; ++m) {
1068 (*J[d+1][d+1])(cidx,fhidx_[j][l],m) = static_cast<Real>(0);
1069 }
1070 }
1071 }
1072 }
1073 }
1074 // Pressure pinning
1075 if (i==7 && pinPressure_) {
1076 int numLocalSideIds = bdryCellLocIds_[i].size();
1077 for (int j = 0; j < numLocalSideIds; ++j) {
1078 int numCellsSide = bdryCellLocIds_[i][j].size();
1079 for (int k = 0; k < numCellsSide; ++k) {
1080 int l = 0, cidx = bdryCellLocIds_[i][j][k];
1081 for (int m = 0; m < fv; ++m) {
1082 for (int n = 0; n < d; ++n) {
1083 (*J[d][n])(cidx,fpidx_[j][l],m) = static_cast<Real>(0);
1084 }
1085 }
1086 for (int m = 0; m < fp; ++m) {
1087 (*J[d][d])(cidx,fpidx_[j][l],m) = static_cast<Real>(0);
1088 }
1089 for (int m = 0; m < fh; ++m) {
1090 (*J[d][d+1])(cidx,fpidx_[j][l],m) = static_cast<Real>(0);
1091 }
1092 }
1093 }
1094 }
1095 }
1096 }
1097
1098 // Combine the jacobians.
1099 fieldHelper_->combineFieldCoeff(jac, J);
1100
1101 }
1102
1103 void Hessian_11(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess,
1104 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & l_coeff,
1105 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
1106 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
1107 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
1108 // throw Exception::NotImplemented("");
1109 // Retrieve dimensions.
1110 int c = u_coeff->dimension(0);
1111 int p = cellCub_->getNumPoints();
1112 int fv = basisPtrVel_->getCardinality();
1113 int fp = basisPtrPrs_->getCardinality();
1114 int fh = basisPtrThr_->getCardinality();
1115 int d = cellCub_->getDimension();
1116
1117 // Initialize jacobians.
1118 std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > > H(d+2);
1119 for (int i = 0; i < d+2; ++i) {
1120 H[i].resize(d+2);
1121 }
1122 for (int i = 0; i < d; ++i) {
1123 for (int j = 0; j < d; ++j) {
1124 H[i][j] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv, fv);
1125 }
1126 }
1127 for (int i = 0; i < d; ++i) {
1128 H[d][i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fp, fv);
1129 H[i][d] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv, fp);
1130 H[d+1][i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fh, fv);
1131 H[i][d+1] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv, fh);
1132 }
1133 H[d][d] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fp, fp);
1134 H[d+1][d] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fh, fp);
1135 H[d][d+1] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fp, fh);
1136 H[d+1][d+1] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fh, fh);
1137
1138 // Split l_coeff into components.
1139 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > L;
1140 fieldHelper_->splitFieldCoeff(L, l_coeff);
1141
1142 // APPLY DIRICHLET CONDITIONS
1143 int numSideSets = bdryCellLocIds_.size();
1144 if (numSideSets > 0) {
1145 // DIRICHLET CONDITIONS
1146 for (int i = 0; i < numSideSets; ++i) {
1147 // Velocity boundary conditions
1148 if (i<4) {
1149 int numLocalSideIds = bdryCellLocIds_[i].size();
1150 for (int j = 0; j < numLocalSideIds; ++j) {
1151 int numCellsSide = bdryCellLocIds_[i][j].size();
1152 int numVBdryDofs = fvidx_[j].size();
1153 for (int k = 0; k < numCellsSide; ++k) {
1154 int cidx = bdryCellLocIds_[i][j][k];
1155 for (int l = 0; l < numVBdryDofs; ++l) {
1156 for (int m = 0; m < d; ++m) {
1157 (*L[m])(cidx,fvidx_[j][l]) = static_cast<Real>(0);
1158 }
1159 }
1160 }
1161 }
1162 }
1163 // Thermal boundaries
1164 if ( (i==0) || (i==5) ) {
1165 int numLocalSideIds = bdryCellLocIds_[i].size();
1166 for (int j = 0; j < numLocalSideIds; ++j) {
1167 int numCellsSide = bdryCellLocIds_[i][j].size();
1168 int numHBdryDofs = fhidx_[j].size();
1169 for (int k = 0; k < numCellsSide; ++k) {
1170 int cidx = bdryCellLocIds_[i][j][k];
1171 for (int l = 0; l < numHBdryDofs; ++l) {
1172 (*L[d+1])(cidx,fhidx_[j][l]) = static_cast<Real>(0);
1173 }
1174 }
1175 }
1176 }
1177 // Pressure pinning
1178 if (i==7 && pinPressure_) {
1179 int numLocalSideIds = bdryCellLocIds_[i].size();
1180 for (int j = 0; j < numLocalSideIds; ++j) {
1181 int numCellsSide = bdryCellLocIds_[i][j].size();
1182 for (int k = 0; k < numCellsSide; ++k) {
1183 int l = 0, cidx = bdryCellLocIds_[i][j][k];
1184 (*L[d])(cidx,fpidx_[j][l]) = static_cast<Real>(0);
1185 }
1186 }
1187 }
1188 }
1189 }
1190
1191 // Evaluate/interpolate finite element fields on cells.
1192 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > valVel_vec(d);
1193 for (int i = 0; i < d; ++i) {
1194 valVel_vec[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
1195 feVel_->evaluateValue(valVel_vec[i], L[i]);
1196 }
1197 ROL::Ptr<Intrepid::FieldContainer<Real> > valHeat_eval;
1198 valHeat_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
1199 feThr_->evaluateValue(valHeat_eval, L[3]);
1200
1201 // Compute nonlinear terms in the Navier-Stokes equations.
1202 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > valVelPhi_vec(d);
1203 for (int i = 0; i < d; ++i) {
1204 valVelPhi_vec[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv, p);
1205 Intrepid::FunctionSpaceTools::scalarMultiplyDataField<Real>(*valVelPhi_vec[i], *valVel_vec[i], *(feVel_->N()));
1206 }
1207
1208 // Compute nonlinear terms in the thermal equation.
1209 ROL::Ptr<Intrepid::FieldContainer<Real> > valHeatVelPhi;
1210 valHeatVelPhi = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv, p);
1211 Intrepid::FunctionSpaceTools::scalarMultiplyDataField<Real>(*valHeatVelPhi, *valHeat_eval, *(feVel_->N()));
1212
1213 /*** Evaluate weak form of the Hessian. ***/
1214 for (int i = 0; i < d; ++i) {
1215 // velocity equation.
1216 for (int j = 0; j < d; ++j) {
1217 Intrepid::FunctionSpaceTools::integrate<Real>((*H[i][j]),
1218 *valVelPhi_vec[j], // L Phi
1219 *(feVel_->DNDdetJ(i)), // dPhi/dx
1220 Intrepid::COMP_CPP,
1221 false);
1222 Intrepid::FunctionSpaceTools::integrate<Real>((*H[i][j]),
1223 *(feVel_->DNDdetJ(j)), // dPhi/dx
1224 *valVelPhi_vec[i], // L Phi
1225 Intrepid::COMP_CPP,
1226 true);
1227 }
1228 Intrepid::FunctionSpaceTools::integrate<Real>((*H[i][d+1]),
1229 *valHeatVelPhi, // L Phi
1230 *(feThr_->DNDdetJ(i)), // dPhi/dx
1231 Intrepid::COMP_CPP,
1232 false);
1233 // Thermal equation.
1234 Intrepid::FunctionSpaceTools::integrate<Real>((*H[d+1][i]),
1235 *(feThr_->DNDdetJ(i)), // dPhi/dx
1236 *valHeatVelPhi, // L Phi
1237 Intrepid::COMP_CPP,
1238 false);
1239 }
1240
1241 // Combine the Hessians.
1242 fieldHelper_->combineFieldCoeff(hess, H);
1243
1244 }
1245
1246 void Hessian_12(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess,
1247 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & l_coeff,
1248 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
1249 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
1250 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
1251 throw Exception::Zero(">>> (PDE_ThermalFluids::Hessian_12): Hessian is zero.");
1252 }
1253
1254 void Hessian_21(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess,
1255 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & l_coeff,
1256 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
1257 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
1258 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
1259 throw Exception::Zero(">>> (PDE_ThermalFluids::Hessian_21): Hessian is zero.");
1260 }
1261
1262 void Hessian_22(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess,
1263 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & l_coeff,
1264 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
1265 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
1266 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
1267 throw Exception::Zero(">>> (PDE_ThermalFluids::Hessian_22): Hessian is zero.");
1268 }
1269
1270 void RieszMap_1(ROL::Ptr<Intrepid::FieldContainer<Real> > & riesz) {
1271 // Retrieve dimensions.
1272 int c = feVel_->N()->dimension(0);
1273 int fv = basisPtrVel_->getCardinality();
1274 int fp = basisPtrPrs_->getCardinality();
1275 int fh = basisPtrThr_->getCardinality();
1276 int d = cellCub_->getDimension();
1277
1278 // Initialize jacobians.
1279 std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > > J(d+2);
1280 for (int i = 0; i < d+2; ++i) {
1281 J[i].resize(d+2);
1282 }
1283 for (int i = 0; i < d; ++i) {
1284 for (int j = 0; j < d; ++j) {
1285 J[i][j] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv, fv);
1286 }
1287 J[d][i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fp, fv);
1288 J[i][d] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv, fp);
1289 J[d+1][i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fh, fv);
1290 J[i][d+1] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv, fh);
1291 }
1292 J[d][d] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fp, fp);
1293 J[d+1][d] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fh, fp);
1294 J[d][d+1] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fp, fh);
1295 J[d+1][d+1] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fh, fh);
1296
1297 for (int i = 0; i < d; ++i) {
1298 *(J[i][i]) = *(feVel_->stiffMat());
1299 Intrepid::RealSpaceTools<Real>::add(*(J[i][i]),*(feVel_->massMat()));
1300 }
1301 *(J[d][d]) = *(fePrs_->massMat());
1302 *(J[d+1][d+1]) = *(feThr_->stiffMat());
1303 Intrepid::RealSpaceTools<Real>::add(*(J[d+1][d+1]),*(feThr_->massMat()));
1304
1305 // Combine the jacobians.
1306 fieldHelper_->combineFieldCoeff(riesz, J);
1307 }
1308
1309 void RieszMap_2(ROL::Ptr<Intrepid::FieldContainer<Real> > & riesz) {
1310 // Retrieve dimensions.
1311 int c = feVel_->N()->dimension(0);
1312 int fv = basisPtrVel_->getCardinality();
1313 int fp = basisPtrPrs_->getCardinality();
1314 int fh = basisPtrThr_->getCardinality();
1315 int d = cellCub_->getDimension();
1316
1317 // Initialize jacobians.
1318 std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > > J(d+2);
1319 for (int i = 0; i < d+2; ++i) {
1320 J[i].resize(d+2);
1321 }
1322 for (int i = 0; i < d; ++i) {
1323 for (int j = 0; j < d; ++j) {
1324 J[i][j] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv, fv);
1325 }
1326 J[d][i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fp, fv);
1327 J[i][d] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv, fp);
1328 J[d+1][i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fh, fv);
1329 J[i][d+1] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv, fh);
1330 }
1331 J[d][d] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fp, fp);
1332 J[d+1][d] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fh, fp);
1333 J[d][d+1] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fp, fh);
1334 J[d+1][d+1] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fh, fh);
1335
1336
1337 for (int i = 0; i < d; ++i) {
1338 *(J[i][i]) = *(feVel_->massMat());
1339 }
1340 *(J[d][d]) = *(fePrs_->massMat());
1341 *(J[d+1][d+1]) = *(feThr_->massMat());
1342
1343 // Combine the jacobians.
1344 fieldHelper_->combineFieldCoeff(riesz, J);
1345 }
1346
1347 std::vector<ROL::Ptr<Intrepid::Basis<Real, Intrepid::FieldContainer<Real> > > > getFields() {
1348 return basisPtrs_;
1349 }
1350
1351 void setCellNodes(const ROL::Ptr<Intrepid::FieldContainer<Real> > &volCellNodes,
1352 const std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > > &bdryCellNodes,
1353 const std::vector<std::vector<std::vector<int> > > &bdryCellLocIds) {
1354 volCellNodes_ = volCellNodes;
1355 bdryCellNodes_ = bdryCellNodes;
1356 bdryCellLocIds_ = bdryCellLocIds;
1357 // Finite element definition.
1358 feVel_ = ROL::makePtr<FE<Real>>(volCellNodes_,basisPtrVel_,cellCub_);
1359 fePrs_ = ROL::makePtr<FE<Real>>(volCellNodes_,basisPtrPrs_,cellCub_);
1360 feThr_ = ROL::makePtr<FE<Real>>(volCellNodes_,basisPtrThr_,cellCub_);
1361 // Get boundary degrees of freedom.
1362 fvidx_ = feVel_->getBoundaryDofs();
1363 fpidx_ = fePrs_->getBoundaryDofs();
1364 fhidx_ = feThr_->getBoundaryDofs();
1365 // Construct boundary FEs
1366 const int numSideSets = bdryCellNodes.size();
1367 feVelBdry_.resize(numSideSets);
1368 fePrsBdry_.resize(numSideSets);
1369 feThrBdry_.resize(numSideSets);
1370 for (int i = 0; i < numSideSets; ++i) {
1371 int numLocSides = bdryCellNodes[i].size();
1372 feVelBdry_[i].resize(numLocSides);
1373 fePrsBdry_[i].resize(numLocSides);
1374 feThrBdry_[i].resize(numLocSides);
1375 for (int j = 0; j < numLocSides; ++j) {
1376 if (bdryCellNodes[i][j] != ROL::nullPtr) {
1377 feVelBdry_[i][j] = ROL::makePtr<FE<Real>>(bdryCellNodes[i][j],basisPtrVel_,bdryCub_,j);
1378 fePrsBdry_[i][j] = ROL::makePtr<FE<Real>>(bdryCellNodes[i][j],basisPtrPrs_,bdryCub_,j);
1379 feThrBdry_[i][j] = ROL::makePtr<FE<Real>>(bdryCellNodes[i][j],basisPtrThr_,bdryCub_,j);
1380 }
1381 }
1382 }
1383 }
1384
1385 void setFieldPattern(const std::vector<std::vector<int> > & fieldPattern) {
1386 fieldPattern_ = fieldPattern;
1387 fieldHelper_ = ROL::makePtr<FieldHelper<Real>>(numFields_, numDofs_, numFieldDofs_, fieldPattern_);
1388 }
1389
1390 const ROL::Ptr<FE<Real> > getVelocityFE(void) const {
1391 return feVel_;
1392 }
1393
1394 const ROL::Ptr<FE<Real> > getPressureFE(void) const {
1395 return fePrs_;
1396 }
1397
1398 const ROL::Ptr<FE<Real> > getThermalFE(void) const {
1399 return feThr_;
1400 }
1401
1402 const std::vector<std::vector<ROL::Ptr<FE<Real> > > > getVelocityBdryFE(void) const {
1403 return feVelBdry_;
1404 }
1405
1406 const std::vector<std::vector<ROL::Ptr<FE<Real> > > > getPressureBdryFE(void) const {
1407 return fePrsBdry_;
1408 }
1409
1410 const std::vector<std::vector<ROL::Ptr<FE<Real> > > > getThermalBdryFE(void) const {
1411 return feThrBdry_;
1412 }
1413
1414 const std::vector<std::vector<std::vector<int> > > getBdryCellLocIds(void) const {
1415 return bdryCellLocIds_;
1416 }
1417
1418 const ROL::Ptr<FieldHelper<Real> > getFieldHelper(void) const {
1419 return fieldHelper_;
1420 }
1421
1422 }; // PDE_ThermalFluids
1423
1424 #endif