Debian Codegraph @

packages/rol/example/PDE-OPT/fractional/poisson/pde_fractional_poisson.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 fractional Poisson
12 control problem.
13 */
14
15 #ifndef PDE_FRACTIONAL_POISSON_HPP
16 #define PDE_FRACTIONAL_POISSON_HPP
17
18 #include "../../TOOLS/pde.hpp"
19 #include "../../TOOLS/fe.hpp"
20
21 #include "Intrepid_HGRAD_QUAD_C1_FEM.hpp"
22 #include "Intrepid_HGRAD_QUAD_C2_FEM.hpp"
23 #include "Intrepid_HGRAD_LINE_C1_FEM.hpp"
24 #include "Intrepid_HGRAD_LINE_Cn_FEM.hpp"
25 #include "Intrepid_DefaultCubatureFactory.hpp"
26 #include "Intrepid_FunctionSpaceTools.hpp"
27 #include "Intrepid_CellTools.hpp"
28
29 #include "ROL_Ptr.hpp"
30
31 template <class Real>
32 class PDE_Fractional_Poisson_Local : public PDE<Real> {
33 private:
34 // Finite element basis information
35 ROL::Ptr<Intrepid::Basis<Real, Intrepid::FieldContainer<Real> > > basisPtr_;
36 std::vector<ROL::Ptr<Intrepid::Basis<Real, Intrepid::FieldContainer<Real> > > > basisPtrs_;
37 // Cell cubature information
38 ROL::Ptr<Intrepid::Cubature<Real> > cellCub_;
39 // Cell node information
40 ROL::Ptr<Intrepid::FieldContainer<Real> > volCellNodes_;
41 std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > > bdryCellNodes_;
42 std::vector<std::vector<std::vector<int> > > bdryCellLocIds_;
43 // Finite element definition
44 ROL::Ptr<FE<Real> > fe_vol_;
45 // Local degrees of freedom on boundary, for each side of the reference cell (first index).
46 std::vector<std::vector<int> > fidx_;
47 // Coordinates of degrees freedom on boundary cells.
48 // Indexing: [sideset number][local side id](cell number, value at dof)
49 std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > > bdryCellDofValues_;
50 // Diffusivity Coefficient
51 ROL::Ptr<Intrepid::FieldContainer<Real> > kappa_;
52 // Right hand side
53 ROL::Ptr<Intrepid::FieldContainer<Real> > rhs_;
54
55 Real fracPower_;
56 Real alpha_;
57
58 public:
59 PDE_Fractional_Poisson_Local(Teuchos::ParameterList &parlist) {
60 // Finite element fields.
61 int basisOrder = parlist.sublist("Problem").get("Diffusion FE Basis Order",1);
62 if (basisOrder == 1) {
63 basisPtr_ = ROL::makePtr<Intrepid::Basis_HGRAD_QUAD_C1_FEM<Real, Intrepid::FieldContainer<Real> >>();
64 }
65 else if (basisOrder == 2) {
66 basisPtr_ = ROL::makePtr<Intrepid::Basis_HGRAD_QUAD_C2_FEM<Real, Intrepid::FieldContainer<Real> >>();
67 }
68 basisPtrs_.clear(); basisPtrs_.push_back(basisPtr_);
69 // Quadrature rules.
70 shards::CellTopology cellType = basisPtr_->getBaseCellTopology(); // get the cell type from any basis
71 Intrepid::DefaultCubatureFactory<Real> cubFactory; // create cubature factory
72 int cubDegree = parlist.sublist("Problem").get("Diffusion Cubature Degree",2); // set cubature degree, e.g., 2
73 cellCub_ = cubFactory.create(cellType, cubDegree); // create default cubature
74 // Coefficients
75 fracPower_ = parlist.sublist("Problem").get("Fractional Power",0.5);
76 alpha_ = static_cast<Real>(1) - static_cast<Real>(2)*fracPower_;
77 }
78
79 void residual(ROL::Ptr<Intrepid::FieldContainer<Real> > & res,
80 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
81 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
82 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
83 // GET DIMENSIONS
84 const int c = fe_vol_->gradN()->dimension(0);
85 const int f = fe_vol_->gradN()->dimension(1);
86 const int p = fe_vol_->gradN()->dimension(2);
87 const int d = fe_vol_->gradN()->dimension(3);
88 // INITIALIZE RESIDUAL
89 res = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f);
90 // COMPUTE STIFFNESS TERM
91 ROL::Ptr<Intrepid::FieldContainer<Real> > gradU_eval
92 = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d);
93 fe_vol_->evaluateGradient(gradU_eval, u_coeff);
94 ROL::Ptr<Intrepid::FieldContainer<Real> > kappa_gradU_eval
95 = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d);
96 Intrepid::FunctionSpaceTools::tensorMultiplyDataData<Real>(*kappa_gradU_eval,*kappa_,*gradU_eval);
97 Intrepid::FunctionSpaceTools::integrate<Real>(*res,
98 *kappa_gradU_eval,
99 *(fe_vol_->gradNdetJ()),
100 Intrepid::COMP_CPP,
101 false);
102 // ADD RHS TO RESIDUAL
103 Intrepid::FunctionSpaceTools::integrate<Real>(*res,
104 *rhs_,
105 *(fe_vol_->NdetJ()),
106 Intrepid::COMP_CPP,
107 true);
108 // ADD CONTROL TERM TO RESIDUAL
109 ROL::Ptr<Intrepid::FieldContainer<Real> > valZ_eval
110 = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
111 fe_vol_->evaluateValue(valZ_eval, z_coeff);
112 Intrepid::RealSpaceTools<Real>::scale(*valZ_eval,static_cast<Real>(-1));
113 Intrepid::FunctionSpaceTools::integrate<Real>(*res,
114 *valZ_eval,
115 *(fe_vol_->NdetJ()),
116 Intrepid::COMP_CPP,
117 true);
118 // APPLY DIRICHLET CONDITIONS
119 int numSideSets = bdryCellLocIds_.size();
120 if (numSideSets > 0) {
121 for (int i = 0; i < numSideSets; ++i) {
122 int numLocalSideIds = bdryCellLocIds_[i].size();
123 for (int j = 0; j < numLocalSideIds; ++j) {
124 int numCellsSide = bdryCellLocIds_[i][j].size();
125 int numBdryDofs = fidx_[j].size();
126 for (int k = 0; k < numCellsSide; ++k) {
127 int cidx = bdryCellLocIds_[i][j][k];
128 for (int l = 0; l < numBdryDofs; ++l) {
129 (*res)(cidx,fidx_[j][l]) = (*u_coeff)(cidx,fidx_[j][l]) - (*bdryCellDofValues_[i][j])(k,fidx_[j][l]);
130 }
131 }
132 }
133 }
134 }
135 }
136
137 void Jacobian_1(ROL::Ptr<Intrepid::FieldContainer<Real> > & jac,
138 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
139 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
140 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
141 // GET DIMENSIONS
142 const int c = fe_vol_->gradN()->dimension(0);
143 const int f = fe_vol_->gradN()->dimension(1);
144 const int p = fe_vol_->gradN()->dimension(2);
145 const int d = fe_vol_->gradN()->dimension(3);
146 // INITILAIZE JACOBIAN
147 jac = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, f);
148 // COMPUTE STIFFNESS TERM
149 ROL::Ptr<Intrepid::FieldContainer<Real> > kappa_gradN_eval
150 = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, p, d);
151 Intrepid::FunctionSpaceTools::tensorMultiplyDataField<Real>(*kappa_gradN_eval,*kappa_,*(fe_vol_->gradN()));
152 Intrepid::FunctionSpaceTools::integrate<Real>(*jac,
153 *kappa_gradN_eval,
154 *(fe_vol_->gradNdetJ()),
155 Intrepid::COMP_CPP,
156 false);
157 // APPLY DIRICHLET CONDITIONS
158 int numSideSets = bdryCellLocIds_.size();
159 if (numSideSets > 0) {
160 for (int i = 0; i < numSideSets; ++i) {
161 int numLocalSideIds = bdryCellLocIds_[i].size();
162 for (int j = 0; j < numLocalSideIds; ++j) {
163 int numCellsSide = bdryCellLocIds_[i][j].size();
164 int numBdryDofs = fidx_[j].size();
165 for (int k = 0; k < numCellsSide; ++k) {
166 int cidx = bdryCellLocIds_[i][j][k];
167 for (int l = 0; l < numBdryDofs; ++l) {
168 for (int m = 0; m < f; ++m) {
169 (*jac)(cidx,fidx_[j][l],m) = static_cast<Real>(0);
170 }
171 (*jac)(cidx,fidx_[j][l],fidx_[j][l]) = static_cast<Real>(1);
172 }
173 }
174 }
175 }
176 }
177 }
178
179 void Jacobian_2(ROL::Ptr<Intrepid::FieldContainer<Real> > & jac,
180 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
181 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
182 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
183 // GET DIMENSIONS
184 const int c = fe_vol_->gradN()->dimension(0);
185 const int f = fe_vol_->gradN()->dimension(1);
186 // INITIALIZE JACOBIAN
187 jac = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, f);
188 // ADD CONTROL TERM
189 *jac = *fe_vol_->massMat();
190 Intrepid::RealSpaceTools<Real>::scale(*jac, static_cast<Real>(-1));
191 // APPLY DIRICHLET CONDITIONS
192 int numSideSets = bdryCellLocIds_.size();
193 if (numSideSets > 0) {
194 for (int i = 0; i < numSideSets; ++i) {
195 int numLocalSideIds = bdryCellLocIds_[i].size();
196 for (int j = 0; j < numLocalSideIds; ++j) {
197 int numCellsSide = bdryCellLocIds_[i][j].size();
198 int numBdryDofs = fidx_[j].size();
199 for (int k = 0; k < numCellsSide; ++k) {
200 int cidx = bdryCellLocIds_[i][j][k];
201 for (int l = 0; l < numBdryDofs; ++l) {
202 for (int m = 0; m < f; ++m) {
203 (*jac)(cidx,fidx_[j][l],m) = static_cast<Real>(0);
204 }
205 }
206 }
207 }
208 }
209 }
210 }
211
212 void Hessian_11(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess,
213 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & l_coeff,
214 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_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 throw Exception::Zero(">>> (PDE_Poisson::Hessian_11): Hessian is zero.");
218 }
219
220 void Hessian_12(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess,
221 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & l_coeff,
222 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
223 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
224 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
225 throw Exception::Zero(">>> (PDE_Poisson::Hessian_12): Hessian is zero.");
226 }
227
228 void Hessian_21(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess,
229 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & l_coeff,
230 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
231 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
232 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
233 throw Exception::Zero(">>> (PDE_Poisson::Hessian_21): Hessian is zero.");
234 }
235
236 void Hessian_22(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess,
237 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & l_coeff,
238 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
239 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
240 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
241 throw Exception::Zero(">>> (PDE_Poisson::Hessian_22): Hessian is zero.");
242 }
243
244 void RieszMap_1(ROL::Ptr<Intrepid::FieldContainer<Real> > & riesz) {
245 // GET DIMENSIONS
246 const int c = fe_vol_->gradN()->dimension(0);
247 const int f = fe_vol_->gradN()->dimension(1);
248 // INITIALIZE RIESZ MAP
249 riesz = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, f);
250 *riesz = *fe_vol_->massMat();
251 // APPLY DIRICHLET CONDITIONS
252 int numSideSets = bdryCellLocIds_.size();
253 if (numSideSets > 0) {
254 for (int i = 0; i < numSideSets; ++i) {
255 int numLocalSideIds = bdryCellLocIds_[i].size();
256 for (int j = 0; j < numLocalSideIds; ++j) {
257 int numCellsSide = bdryCellLocIds_[i][j].size();
258 int numBdryDofs = fidx_[j].size();
259 for (int k = 0; k < numCellsSide; ++k) {
260 int cidx = bdryCellLocIds_[i][j][k];
261 for (int l = 0; l < numBdryDofs; ++l) {
262 for (int m = 0; m < f; ++m) {
263 (*riesz)(cidx,fidx_[j][l],m) = static_cast<Real>(0);
264 }
265 (*riesz)(cidx,fidx_[j][l],fidx_[j][l]) = static_cast<Real>(1);
266 }
267 }
268 }
269 }
270 }
271 }
272
273 void RieszMap_2(ROL::Ptr<Intrepid::FieldContainer<Real> > & riesz) {
274 // GET DIMENSIONS
275 const int c = fe_vol_->gradN()->dimension(0);
276 const int f = fe_vol_->gradN()->dimension(1);
277 // INITIALIZE RIESZ MAP
278 riesz = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, f);
279 *riesz = *fe_vol_->massMat();
280 }
281
282 std::vector<ROL::Ptr<Intrepid::Basis<Real, Intrepid::FieldContainer<Real> > > > getFields() {
283 return basisPtrs_;
284 }
285
286 void setCellNodes(const ROL::Ptr<Intrepid::FieldContainer<Real> > &volCellNodes,
287 const std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > > &bdryCellNodes,
288 const std::vector<std::vector<std::vector<int> > > &bdryCellLocIds) {
289 volCellNodes_ = volCellNodes;
290 bdryCellNodes_ = bdryCellNodes;
291 bdryCellLocIds_ = bdryCellLocIds;
292 // Finite element definition.
293 fe_vol_ = ROL::makePtr<FE<Real>>(volCellNodes_,basisPtr_,cellCub_);
294 // Set local boundary DOFs.
295 fidx_ = fe_vol_->getBoundaryDofs();
296 // Compute Dirichlet values at DOFs.
297 int d = basisPtr_->getBaseCellTopology().getDimension();
298 int numSidesets = bdryCellLocIds_.size();
299 bdryCellDofValues_.resize(numSidesets);
300 for (int i=0; i<numSidesets; ++i) {
301 int numLocSides = bdryCellLocIds_[i].size();
302 bdryCellDofValues_[i].resize(numLocSides);
303 for (int j=0; j<numLocSides; ++j) {
304 int c = bdryCellLocIds_[i][j].size();
305 int f = basisPtr_->getCardinality();
306 bdryCellDofValues_[i][j] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f);
307 ROL::Ptr<Intrepid::FieldContainer<Real> > coords =
308 ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, d);
309 if (c > 0) {
310 fe_vol_->computeDofCoords(coords, bdryCellNodes_[i][j]);
311 }
312 for (int k=0; k<c; ++k) {
313 for (int l=0; l<f; ++l) {
314 std::vector<Real> dofpoint(d);
315 for (int m=0; m<d; ++m) {
316 dofpoint[m] = (*coords)(k, l, m);
317 }
318 (*bdryCellDofValues_[i][j])(k, l) = DirichletFunc(dofpoint, i, j);
319 }
320 }
321 }
322 }
323 // Compute diffusivity coefficient
324 const int c = fe_vol_->gradN()->dimension(0);
325 const int p = fe_vol_->gradN()->dimension(2);
326 kappa_ = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p);
327 rhs_ = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p);
328 computeCoefficients(kappa_,rhs_);
329 }
330
331 const ROL::Ptr<FE<Real> > getFE(void) const {
332 return fe_vol_;
333 }
334
335 private:
336 Real diffusivityFunc(const std::vector<Real> &x) const {
337 return static_cast<Real>(1);
338 }
339
340 Real rhsFunc(const std::vector<Real> &x) const {
341 const Real lambda = M_PI*M_PI*static_cast<Real>(8);
342 const Real twoPi = static_cast<Real>(2) * M_PI;
343 return std::pow(lambda,fracPower_)*std::sin(twoPi*x[0])*std::sin(twoPi*x[1]);
344 }
345
346 Real DirichletFunc(const std::vector<Real> & coords, int sideset, int locSideId) const {
347 return 0;
348 }
349
350 void computeCoefficients(const ROL::Ptr<Intrepid::FieldContainer<Real> > &kappa,
351 const ROL::Ptr<Intrepid::FieldContainer<Real> > &rhs) const {
352 // GET DIMENSIONS
353 int c = fe_vol_->gradN()->dimension(0);
354 int p = fe_vol_->gradN()->dimension(2);
355 int d = fe_vol_->gradN()->dimension(3);
356 std::vector<Real> pt(d), adv(d);
357 for (int i = 0; i < c; ++i) {
358 for (int j = 0; j < p; ++j) {
359 for ( int k = 0; k < d; ++k) {
360 pt[k] = (*fe_vol_->cubPts())(i,j,k);
361 }
362 // Compute diffusivity kappa
363 (*kappa)(i,j) = diffusivityFunc(pt);
364 // Compute right hand side
365 (*rhs)(i,j) = -rhsFunc(pt);
366 }
367 }
368 }
369
370 }; // PDE_Fractional_Poisson_Local
371
372 template <class Real>
373 class PDE_Fractional_Poisson_Cylinder : public PDE<Real> {
374 private:
375 // Finite element basis information
376 ROL::Ptr<Intrepid::Basis<Real, Intrepid::FieldContainer<Real> > > basisPtr_;
377 std::vector<ROL::Ptr<Intrepid::Basis<Real, Intrepid::FieldContainer<Real> > > > basisPtrs_;
378 // Cell cubature information
379 ROL::Ptr<Intrepid::Cubature<Real> > cellCub_;
380 // Cell node information
381 ROL::Ptr<Intrepid::FieldContainer<Real> > volCellNodes_;
382 std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > > bdryCellNodes_;
383 std::vector<std::vector<std::vector<int> > > bdryCellLocIds_;
384 // Finite element definition
385 ROL::Ptr<FE<Real> > fe_vol_;
386 // Local degrees of freedom on boundary, for each side of the reference cell (first index).
387 std::vector<std::vector<int> > fidx_;
388 // Coordinates of degrees freedom on boundary cells.
389 // Indexing: [sideset number][local side id](cell number, value at dof)
390 std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > > bdryCellDofValues_;
391
392 Real fracPower_;
393 Real alpha_;
394
395 Real diffusivityFunc(const std::vector<Real> &x) const {
396 Real alpha = alpha_;
397 std::vector<Real> param = PDE<Real>::getParameter();
398 if (param.size()) {
399 alpha = static_cast<Real>(1) - static_cast<Real>(2)*param[0];
400 }
401 return std::pow(x[0],alpha);
402 }
403
404 Real DirichletFunc(const std::vector<Real> & coords, int sideset, int locSideId) const {
405 return 0;
406 }
407
408 void computeCoefficients(ROL::Ptr<Intrepid::FieldContainer<Real> > &kappa) const {
409 // GET DIMENSIONS
410 int c = fe_vol_->gradN()->dimension(0);
411 int p = fe_vol_->gradN()->dimension(2);
412 int d = fe_vol_->gradN()->dimension(3);
413 std::vector<Real> pt(d), adv(d);
414 for (int i = 0; i < c; ++i) {
415 for (int j = 0; j < p; ++j) {
416 for ( int k = 0; k < d; ++k) {
417 pt[k] = (*fe_vol_->cubPts())(i,j,k);
418 }
419 // Compute diffusivity kappa
420 (*kappa)(i,j) = diffusivityFunc(pt);
421 }
422 }
423 }
424
425 public:
426 PDE_Fractional_Poisson_Cylinder(Teuchos::ParameterList &parlist) {
427 // Finite element fields.
428 int basisOrder = parlist.sublist("Problem").get("Cylinder FE Basis Order",1);
429 if (basisOrder == 1) {
430 basisPtr_ = ROL::makePtr<Intrepid::Basis_HGRAD_LINE_C1_FEM<Real, Intrepid::FieldContainer<Real> >>();
431 }
432 else if (basisOrder >= 2) {
433 basisPtr_ = ROL::makePtr<Intrepid::Basis_HGRAD_LINE_Cn_FEM<Real, Intrepid::FieldContainer<Real> >>(basisOrder,Intrepid::POINTTYPE_EQUISPACED);
434 }
435 basisPtrs_.clear(); basisPtrs_.push_back(basisPtr_);
436 // Quadrature rules.
437 shards::CellTopology cellType = basisPtr_->getBaseCellTopology(); // get the cell type from any basis
438 Intrepid::DefaultCubatureFactory<Real> cubFactory; // create cubature factory
439 int cubDegree = parlist.sublist("Problem").get("Cylinder Cubature Degree",2); // set cubature degree, e.g., 2
440 cellCub_ = cubFactory.create(cellType, cubDegree); // create default cubature
441 // Coefficients
442 fracPower_ = parlist.sublist("Problem").get("Fractional Power",0.5);
443 alpha_ = static_cast<Real>(1) - static_cast<Real>(2)*fracPower_;
444 }
445
446 void residual(ROL::Ptr<Intrepid::FieldContainer<Real> > & res,
447 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
448 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
449 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
450 // GET DIMENSIONS
451 const int c = fe_vol_->gradN()->dimension(0);
452 const int f = fe_vol_->gradN()->dimension(1);
453 const int p = fe_vol_->gradN()->dimension(2);
454 const int d = fe_vol_->gradN()->dimension(3);
455 // INITIALIZE RESIDUAL
456 res = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f);
457 // EVALUATE DIFFUSIVITY
458 ROL::Ptr<Intrepid::FieldContainer<Real> > kappa
459 = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
460 computeCoefficients(kappa);
461 // COMPUTE STIFFNESS TERM
462 ROL::Ptr<Intrepid::FieldContainer<Real> > gradU_eval
463 = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d);
464 ROL::Ptr<Intrepid::FieldContainer<Real> > kappa_gradU_eval
465 = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d);
466 fe_vol_->evaluateGradient(gradU_eval, u_coeff);
467 Intrepid::FunctionSpaceTools::tensorMultiplyDataData<Real>(*kappa_gradU_eval,*kappa,*gradU_eval);
468 Intrepid::FunctionSpaceTools::integrate<Real>(*res,
469 *kappa_gradU_eval,
470 *(fe_vol_->gradNdetJ()),
471 Intrepid::COMP_CPP,
472 false);
473 // ADD CONTROL TERM TO RESIDUAL
474 ROL::Ptr<Intrepid::FieldContainer<Real> > valZ_eval
475 = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
476 fe_vol_->evaluateValue(valZ_eval, z_coeff);
477 Intrepid::RealSpaceTools<Real>::scale(*valZ_eval,static_cast<Real>(-1));
478 Intrepid::FunctionSpaceTools::integrate<Real>(*res,
479 *valZ_eval,
480 *(fe_vol_->NdetJ()),
481 Intrepid::COMP_CPP,
482 true);
483 // APPLY DIRICHLET CONDITIONS
484 int numSideSets = bdryCellLocIds_.size();
485 if (numSideSets > 0) {
486 for (int i = 0; i < numSideSets; ++i) {
487 if (i==1) {
488 int numLocalSideIds = bdryCellLocIds_[i].size();
489 for (int j = 0; j < numLocalSideIds; ++j) {
490 int numCellsSide = bdryCellLocIds_[i][j].size();
491 int numBdryDofs = fidx_[j].size();
492 for (int k = 0; k < numCellsSide; ++k) {
493 int cidx = bdryCellLocIds_[i][j][k];
494 for (int l = 0; l < numBdryDofs; ++l) {
495 (*res)(cidx,fidx_[j][l]) = (*u_coeff)(cidx,fidx_[j][l]) - (*bdryCellDofValues_[i][j])(k,fidx_[j][l]);
496 }
497 }
498 }
499 }
500 }
501 }
502 }
503
504 void Jacobian_1(ROL::Ptr<Intrepid::FieldContainer<Real> > & jac,
505 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
506 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
507 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
508 // GET DIMENSIONS
509 const int c = fe_vol_->gradN()->dimension(0);
510 const int f = fe_vol_->gradN()->dimension(1);
511 const int p = fe_vol_->gradN()->dimension(2);
512 const int d = fe_vol_->gradN()->dimension(3);
513 // INITILAIZE JACOBIAN
514 jac = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, f);
515 // EVALUATE DIFFUSIVITY
516 ROL::Ptr<Intrepid::FieldContainer<Real> > kappa
517 = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
518 computeCoefficients(kappa);
519 // COMPUTE STIFFNESS TERM
520 ROL::Ptr<Intrepid::FieldContainer<Real> > kappa_gradN_eval
521 = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, p, d);
522 Intrepid::FunctionSpaceTools::tensorMultiplyDataField<Real>(*kappa_gradN_eval,*kappa,*(fe_vol_->gradN()));
523 Intrepid::FunctionSpaceTools::integrate<Real>(*jac,
524 *kappa_gradN_eval,
525 *(fe_vol_->gradNdetJ()),
526 Intrepid::COMP_CPP,
527 false);
528 // APPLY DIRICHLET CONDITIONS
529 int numSideSets = bdryCellLocIds_.size();
530 if (numSideSets > 0) {
531 for (int i = 0; i < numSideSets; ++i) {
532 if (i==1) {
533 int numLocalSideIds = bdryCellLocIds_[i].size();
534 for (int j = 0; j < numLocalSideIds; ++j) {
535 int numCellsSide = bdryCellLocIds_[i][j].size();
536 int numBdryDofs = fidx_[j].size();
537 for (int k = 0; k < numCellsSide; ++k) {
538 int cidx = bdryCellLocIds_[i][j][k];
539 for (int l = 0; l < numBdryDofs; ++l) {
540 for (int m = 0; m < f; ++m) {
541 (*jac)(cidx,fidx_[j][l],m) = static_cast<Real>(0);
542 }
543 (*jac)(cidx,fidx_[j][l],fidx_[j][l]) = static_cast<Real>(1);
544 }
545 }
546 }
547 }
548 }
549 }
550 }
551
552 void Jacobian_2(ROL::Ptr<Intrepid::FieldContainer<Real> > & jac,
553 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
554 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
555 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
556 // GET DIMENSIONS
557 const int c = fe_vol_->gradN()->dimension(0);
558 const int f = fe_vol_->gradN()->dimension(1);
559 // INITIALIZE JACOBIAN
560 jac = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, f);
561 // ADD CONTROL TERM
562 *jac = *fe_vol_->massMat();
563 Intrepid::RealSpaceTools<Real>::scale(*jac, static_cast<Real>(-1));
564 // APPLY DIRICHLET CONDITIONS
565 int numSideSets = bdryCellLocIds_.size();
566 if (numSideSets > 0) {
567 for (int i = 0; i < numSideSets; ++i) {
568 int numLocalSideIds = bdryCellLocIds_[i].size();
569 for (int j = 0; j < numLocalSideIds; ++j) {
570 int numCellsSide = bdryCellLocIds_[i][j].size();
571 int numBdryDofs = fidx_[j].size();
572 for (int k = 0; k < numCellsSide; ++k) {
573 int cidx = bdryCellLocIds_[i][j][k];
574 for (int l = 0; l < numBdryDofs; ++l) {
575 for (int m = 0; m < f; ++m) {
576 (*jac)(cidx,fidx_[j][l],m) = static_cast<Real>(0);
577 }
578 }
579 }
580 }
581 }
582 }
583 }
584
585 void Hessian_11(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess,
586 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & l_coeff,
587 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
588 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
589 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
590 throw Exception::Zero(">>> (PDE_Fractional_Poisson_Cylinder::Hessian_11): Hessian is zero.");
591 }
592
593 void Hessian_12(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess,
594 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & l_coeff,
595 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
596 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
597 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
598 throw Exception::Zero(">>> (PDE_Fractional_Poisson_Cylinder::Hessian_12): Hessian is zero.");
599 }
600
601 void Hessian_21(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess,
602 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & l_coeff,
603 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
604 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
605 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
606 throw Exception::Zero(">>> (PDE_Fractional_Poisson_Cylinder::Hessian_21): Hessian is zero.");
607 }
608
609 void Hessian_22(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess,
610 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & l_coeff,
611 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
612 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
613 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
614 throw Exception::Zero(">>> (PDE_Fractional_Poisson_Cylinder::Hessian_22): Hessian is zero.");
615 }
616
617 void RieszMap_1(ROL::Ptr<Intrepid::FieldContainer<Real> > & riesz) {
618 // GET DIMENSIONS
619 const int c = fe_vol_->gradN()->dimension(0);
620 const int f = fe_vol_->gradN()->dimension(1);
621 const int p = fe_vol_->gradN()->dimension(2);
622 // INITIALIZE RIESZ MAP
623 riesz = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, f);
624 // EVALUATE DIFFUSIVITY
625 ROL::Ptr<Intrepid::FieldContainer<Real> > kappa
626 = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
627 computeCoefficients(kappa);
628 // COMPUTE RIESZ MAP
629 ROL::Ptr<Intrepid::FieldContainer<Real> > kappa_N_eval
630 = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, p);
631 Intrepid::FunctionSpaceTools::scalarMultiplyDataField<Real>(*kappa_N_eval,*kappa,*(fe_vol_->N()));
632 Intrepid::FunctionSpaceTools::integrate<Real>(*riesz,
633 *kappa_N_eval,
634 *(fe_vol_->NdetJ()),
635 Intrepid::COMP_CPP, false);
636 // APPLY DIRICHLET CONDITIONS
637 int numSideSets = bdryCellLocIds_.size();
638 if (numSideSets > 0) {
639 for (int i = 0; i < numSideSets; ++i) {
640 if (i==1) {
641 int numLocalSideIds = bdryCellLocIds_[i].size();
642 for (int j = 0; j < numLocalSideIds; ++j) {
643 int numCellsSide = bdryCellLocIds_[i][j].size();
644 int numBdryDofs = fidx_[j].size();
645 for (int k = 0; k < numCellsSide; ++k) {
646 int cidx = bdryCellLocIds_[i][j][k];
647 for (int l = 0; l < numBdryDofs; ++l) {
648 for (int m = 0; m < f; ++m) {
649 (*riesz)(cidx,fidx_[j][l],m) = static_cast<Real>(0);
650 }
651 (*riesz)(cidx,fidx_[j][l],fidx_[j][l]) = static_cast<Real>(1);
652 }
653 }
654 }
655 }
656 }
657 }
658 }
659
660 void RieszMap_2(ROL::Ptr<Intrepid::FieldContainer<Real> > & riesz) {
661 // GET DIMENSIONS
662 const int c = fe_vol_->gradN()->dimension(0);
663 const int f = fe_vol_->gradN()->dimension(1);
664 // INITIALIZE RIESZ MAP
665 riesz = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, f);
666 *riesz = *fe_vol_->massMat();
667 }
668
669 std::vector<ROL::Ptr<Intrepid::Basis<Real, Intrepid::FieldContainer<Real> > > > getFields() {
670 return basisPtrs_;
671 }
672
673 void setCellNodes(const ROL::Ptr<Intrepid::FieldContainer<Real> > &volCellNodes,
674 const std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > > &bdryCellNodes,
675 const std::vector<std::vector<std::vector<int> > > &bdryCellLocIds) {
676 volCellNodes_ = volCellNodes;
677 bdryCellNodes_ = bdryCellNodes;
678 bdryCellLocIds_ = bdryCellLocIds;
679 // Finite element definition.
680 fe_vol_ = ROL::makePtr<FE<Real>>(volCellNodes_,basisPtr_,cellCub_);
681 // Set local boundary DOFs.
682 fidx_ = fe_vol_->getBoundaryDofs();
683 // Compute Dirichlet values at DOFs.
684 int d = basisPtr_->getBaseCellTopology().getDimension();
685 int numSidesets = bdryCellLocIds_.size();
686 bdryCellDofValues_.resize(numSidesets);
687 for (int i=0; i<numSidesets; ++i) {
688 int numLocSides = bdryCellLocIds_[i].size();
689 bdryCellDofValues_[i].resize(numLocSides);
690 for (int j=0; j<numLocSides; ++j) {
691 int c = bdryCellLocIds_[i][j].size();
692 int f = basisPtr_->getCardinality();
693 bdryCellDofValues_[i][j] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f);
694 ROL::Ptr<Intrepid::FieldContainer<Real> > coords =
695 ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, d);
696 if (c > 0) {
697 fe_vol_->computeDofCoords(coords, bdryCellNodes_[i][j]);
698 }
699 for (int k=0; k<c; ++k) {
700 for (int l=0; l<f; ++l) {
701 std::vector<Real> dofpoint(d);
702 for (int m=0; m<d; ++m) {
703 dofpoint[m] = (*coords)(k, l, m);
704 }
705 (*bdryCellDofValues_[i][j])(k, l) = DirichletFunc(dofpoint, i, j);
706 }
707 }
708 }
709 }
710 }
711
712 const ROL::Ptr<FE<Real> > getFE(void) const {
713 return fe_vol_;
714 }
715
716 }; // PDE_Fractional_Poisson_Local
717
718 #endif