Debian Codegraph @

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