Debian Codegraph @

packages/rol/example/PDE-OPT/poisson-boltzmann/pde_poisson_boltzmann_ex02.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 PDE_POISSON_BOLTZMANN_EX02_HPP
15 #define PDE_POISSON_BOLTZMANN_EX02_HPP
16
17 #include "../TOOLS/pde.hpp"
18 #include "../TOOLS/fe.hpp"
19
20 #include "Intrepid_HGRAD_QUAD_C1_FEM.hpp"
21 #include "Intrepid_HGRAD_QUAD_C2_FEM.hpp"
22 #include "Intrepid_DefaultCubatureFactory.hpp"
23 #include "Intrepid_FunctionSpaceTools.hpp"
24 #include "Intrepid_CellTools.hpp"
25
26 #include "ROL_Ptr.hpp"
27
28 template <class Real>
29 class PDE_Poisson_Boltzmann_ex02 : public PDE<Real> {
30 private:
31 // Finite element basis information
32 ROL::Ptr<Intrepid::Basis<Real, Intrepid::FieldContainer<Real> > > basisPtr_;
33 std::vector<ROL::Ptr<Intrepid::Basis<Real, Intrepid::FieldContainer<Real> > > > basisPtrs_;
34 // Cell cubature information
35 ROL::Ptr<Intrepid::Cubature<Real> > cellCub_;
36 ROL::Ptr<Intrepid::Cubature<Real> > bdryCub_;
37 // Cell node information
38 ROL::Ptr<Intrepid::FieldContainer<Real> > volCellNodes_;
39 std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > > bdryCellNodes_;
40 std::vector<std::vector<std::vector<int> > > bdryCellLocIds_;
41 // Finite element definition
42 ROL::Ptr<FE<Real> > fe_vol_;
43 std::vector<std::vector<ROL::Ptr<FE<Real> > > > fe_bdry_;
44 // Local degrees of freedom on boundary, for each side of the reference cell (first index).
45 std::vector<std::vector<int> > fidx_;
46
47 Real wx_, wy_, dx_;
48 Real uScale_, vScale_;
49 bool useRobin_;
50 Real robinCoeff_;
51
52 public:
53 PDE_Poisson_Boltzmann_ex02(Teuchos::ParameterList &parlist) {
54 // Finite element fields.
55 int basisOrder = parlist.sublist("Problem").get("Order of FE discretization",1);
56 if (basisOrder == 1) {
57 basisPtr_ = ROL::makePtr<Intrepid::Basis_HGRAD_QUAD_C1_FEM<Real, Intrepid::FieldContainer<Real> >>();
58 }
59 else if (basisOrder == 2) {
60 basisPtr_ = ROL::makePtr<Intrepid::Basis_HGRAD_QUAD_C2_FEM<Real, Intrepid::FieldContainer<Real> >>();
61 }
62 basisPtrs_.clear(); basisPtrs_.push_back(basisPtr_);
63 // Quadrature rules.
64 shards::CellTopology cellType = basisPtr_->getBaseCellTopology(); // get the cell type from any basis
65 Intrepid::DefaultCubatureFactory<Real> cubFactory; // create cubature factory
66 int cubDegree = parlist.sublist("PDE Poisson Boltzmann").get("Cubature Degree",2); // set cubature degree, e.g., 2
67 cellCub_ = cubFactory.create(cellType, cubDegree); // create default cubature
68
69 int d = cellType.getDimension();
70 shards::CellTopology bdryCellType = cellType.getCellTopologyData(d-1, 0);
71 int bdryCubDegree = parlist.sublist("Problem").get("Boundary Cubature Degree",2); // set cubature degree, e.g., 2
72 bdryCub_ = cubFactory.create(bdryCellType, bdryCubDegree);
73
74 wx_ = parlist.sublist("Geometry").get("Width",0.6);
75 wy_ = parlist.sublist("Geometry").get("Height",0.2);
76 dx_ = wx_/static_cast<Real>(6);
77 uScale_ = parlist.sublist("Problem").get("Electron Density",1.0);
78 vScale_ = parlist.sublist("Problem").get("Hole Density",1.0);
79
80 useRobin_ = parlist.sublist("Problem").get("Use Robin Conditions",false);
81 robinCoeff_ = parlist.sublist("Problem").get("Robin Coefficient",1e2);
82 }
83
84 void residual(ROL::Ptr<Intrepid::FieldContainer<Real> > & res,
85 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
86 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
87 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
88 // GET DIMENSIONS
89 const int c = fe_vol_->gradN()->dimension(0);
90 const int f = fe_vol_->gradN()->dimension(1);
91 const int p = fe_vol_->gradN()->dimension(2);
92 const int d = fe_vol_->gradN()->dimension(3);
93 // INITIALIZE RESIDUAL
94 res = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f);
95 // COMPUTE PDE COEFFICIENTS
96 Intrepid::FieldContainer<Real> lambda2(c, p), delta2(c, p), scale(c, p);
97 computeCoefficients(lambda2,delta2,scale);
98 // ADD STIFFNESS TERM TO RESIDUAL
99 ROL::Ptr<Intrepid::FieldContainer<Real> > gradU_eval =
100 ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d);
101 fe_vol_->evaluateGradient(gradU_eval, u_coeff);
102 Intrepid::FieldContainer<Real> lambda2_gradU_eval(c, p, d);
103 Intrepid::FunctionSpaceTools::tensorMultiplyDataData<Real>(lambda2_gradU_eval,
104 lambda2,
105 *gradU_eval);
106 Intrepid::FunctionSpaceTools::integrate<Real>(*res,
107 lambda2_gradU_eval,
108 *(fe_vol_->gradNdetJ()),
109 Intrepid::COMP_CPP, false);
110 // ADD NONLINEAR TERM TO RESIDUAL
111 ROL::Ptr<Intrepid::FieldContainer<Real> > valU_eval =
112 ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
113 fe_vol_->evaluateValue(valU_eval, u_coeff);
114 Intrepid::FieldContainer<Real> phi_valU_eval(c, p);
115 for (int i = 0; i < c; ++i) {
116 for (int j = 0; j < p; ++j) {
117 phi_valU_eval(i,j) = delta2(i,j)*(uScale_*std::exp((*valU_eval)(i,j)) - vScale_*std::exp(-(*valU_eval)(i,j)));
118 }
119 }
120 Intrepid::FunctionSpaceTools::integrate<Real>(*res,
121 phi_valU_eval,
122 *(fe_vol_->NdetJ()),
123 Intrepid::COMP_CPP, true);
124 // ADD CONTROL TERM TO RESIDUAL
125 ROL::Ptr<Intrepid::FieldContainer<Real> > valZ_eval =
126 ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
127 fe_vol_->evaluateValue(valZ_eval, z_coeff);
128 ROL::Ptr<Intrepid::FieldContainer<Real> > valZ_scal =
129 ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
130 Intrepid::FunctionSpaceTools::scalarMultiplyDataData<Real>(*valZ_scal,scale,*valZ_eval);
131 Intrepid::FunctionSpaceTools::integrate<Real>(*res,
132 *valZ_scal,
133 *(fe_vol_->NdetJ()),
134 Intrepid::COMP_CPP, true);
135 // APPLY DIRICHLET CONDITIONS
136 std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > > bdryCellDofValues;
137 computeDirichlet(bdryCellDofValues);
138 const int numSideSets = bdryCellLocIds_.size();
139 for (int i = 0; i < numSideSets; ++i) {
140 if ( i==1 || i==2 || i==3 ) {
141 int numLocalSideIds = bdryCellLocIds_[i].size();
142 for (int j = 0; j < numLocalSideIds; ++j) {
143 int numCellsSide = bdryCellLocIds_[i][j].size();
144 if (!useRobin_) {
145 int numBdryDofs = fidx_[j].size();
146 for (int k = 0; k < numCellsSide; ++k) {
147 int cidx = bdryCellLocIds_[i][j][k];
148 for (int l = 0; l < numBdryDofs; ++l) {
149 (*res)(cidx,fidx_[j][l])
150 = (*u_coeff)(cidx,fidx_[j][l]) - (*bdryCellDofValues[i][j])(k,l);
151 }
152 }
153 }
154 else {
155 const int numCubPerSide = bdryCub_->getNumPoints();
156 if (numCellsSide) {
157 // Get U and Z coefficients on Robin boundary
158 ROL::Ptr<Intrepid::FieldContainer<Real > > u_coeff_bdry, z_coeff_bdry;
159 u_coeff_bdry = getBoundaryCoeff(*u_coeff, i, j);
160 z_coeff_bdry = getBoundaryCoeff(*z_coeff, i, j);
161 // Evaluate U and Z on FE basis
162 ROL::Ptr<Intrepid::FieldContainer<Real > > valU_eval_bdry, valZ_eval_bdry;
163 valU_eval_bdry = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide);
164 valZ_eval_bdry = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide);
165 fe_bdry_[i][j]->evaluateValue(valU_eval_bdry, u_coeff_bdry);
166 fe_bdry_[i][j]->evaluateValue(valZ_eval_bdry, z_coeff_bdry);
167 // Compute Robin residual
168 Intrepid::FieldContainer<Real> robinRes(numCellsSide, f);
169 ROL::Ptr< Intrepid::FieldContainer<Real> > robinVal
170 = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide);
171 computeRobin(robinVal,valU_eval_bdry,valZ_eval_bdry,i,j,0);
172 Intrepid::FunctionSpaceTools::integrate<Real>(robinRes,
173 *robinVal,
174 *(fe_bdry_[i][j]->NdetJ()),
175 Intrepid::COMP_CPP, false);
176 // Add Stefan-Boltzmann residual to volume residual
177 for (int k = 0; k < numCellsSide; ++k) {
178 int cidx = bdryCellLocIds_[i][j][k];
179 for (int l = 0; l < f; ++l) {
180 (*res)(cidx,l) += robinRes(k,l);
181 }
182 }
183 }
184 }
185 }
186 }
187 }
188 }
189
190 void Jacobian_1(ROL::Ptr<Intrepid::FieldContainer<Real> > & jac,
191 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
192 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
193 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
194 // GET DIMENSIONS
195 const int c = fe_vol_->gradN()->dimension(0);
196 const int f = fe_vol_->gradN()->dimension(1);
197 const int p = fe_vol_->gradN()->dimension(2);
198 const int d = fe_vol_->gradN()->dimension(3);
199 // INITIALIZE JACOBIAN
200 jac = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, f);
201 // COMPUTE PDE COEFFICIENTS
202 Intrepid::FieldContainer<Real> lambda2(c, p), delta2(c, p), scale(c, p);
203 computeCoefficients(lambda2,delta2,scale);
204 // ADD STIFFNESS TERM TO JACOBIAN
205 Intrepid::FieldContainer<Real> lambda2_gradN_eval(c, f, p, d);
206 Intrepid::FunctionSpaceTools::tensorMultiplyDataField<Real>(lambda2_gradN_eval,
207 lambda2,
208 *(fe_vol_->gradN()));
209 // COMPUTE STIFFNESS TERM
210 Intrepid::FunctionSpaceTools::integrate<Real>(*jac,
211 lambda2_gradN_eval,
212 *(fe_vol_->gradNdetJ()),
213 Intrepid::COMP_CPP, false);
214 // ADD NONLINEAR TERM
215 ROL::Ptr<Intrepid::FieldContainer<Real> > valU_eval =
216 ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
217 fe_vol_->evaluateValue(valU_eval, u_coeff);
218 Intrepid::FieldContainer<Real> dphi_valU_eval(c, p);
219 for (int i = 0; i < c; ++i) {
220 for (int j = 0; j < p; ++j) {
221 dphi_valU_eval(i,j) = delta2(i,j)*(uScale_*std::exp((*valU_eval)(i,j)) + vScale_*std::exp(-(*valU_eval)(i,j)));
222 }
223 }
224 Intrepid::FieldContainer<Real> NexpU(c, f, p);
225 Intrepid::FunctionSpaceTools::scalarMultiplyDataField<Real>(NexpU,
226 dphi_valU_eval,
227 *(fe_vol_->N()));
228 Intrepid::FunctionSpaceTools::integrate<Real>(*jac,
229 NexpU,
230 *(fe_vol_->NdetJ()),
231 Intrepid::COMP_CPP, true);
232 // APPLY DIRICHLET CONDITIONS
233 const int numSideSets = bdryCellLocIds_.size();
234 for (int i = 0; i < numSideSets; ++i) {
235 if ( i==1 || i==2 || i==3 ) {
236 int numLocalSideIds = bdryCellLocIds_[i].size();
237 for (int j = 0; j < numLocalSideIds; ++j) {
238 int numCellsSide = bdryCellLocIds_[i][j].size();
239 if (!useRobin_) {
240 int numBdryDofs = fidx_[j].size();
241 for (int k = 0; k < numCellsSide; ++k) {
242 int cidx = bdryCellLocIds_[i][j][k];
243 for (int l = 0; l < numBdryDofs; ++l) {
244 //std::cout << "\n j=" << j << " l=" << l << " " << fidx[j][l];
245 for (int m = 0; m < f; ++m) {
246 (*jac)(cidx,fidx_[j][l],m) = static_cast<Real>(0);
247 }
248 (*jac)(cidx,fidx_[j][l],fidx_[j][l]) = static_cast<Real>(1);
249 }
250 }
251 }
252 else {
253 const int numCubPerSide = bdryCub_->getNumPoints();
254 if (numCellsSide) {
255 // Get U and Z coefficients on Robin boundary
256 ROL::Ptr<Intrepid::FieldContainer<Real > > u_coeff_bdry, z_coeff_bdry;
257 u_coeff_bdry = getBoundaryCoeff(*u_coeff, i, j);
258 z_coeff_bdry = getBoundaryCoeff(*z_coeff, i, j);
259 // Evaluate U and Z on FE basis
260 ROL::Ptr<Intrepid::FieldContainer<Real > > valU_eval_bdry, valZ_eval_bdry;
261 valU_eval_bdry = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide);
262 valZ_eval_bdry = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide);
263 fe_bdry_[i][j]->evaluateValue(valU_eval_bdry, u_coeff_bdry);
264 fe_bdry_[i][j]->evaluateValue(valZ_eval_bdry, z_coeff_bdry);
265 // Compute Robin residual
266 Intrepid::FieldContainer<Real> robinVal_N(numCellsSide, f, numCubPerSide);
267 Intrepid::FieldContainer<Real> robinJac(numCellsSide, f, f);
268 ROL::Ptr< Intrepid::FieldContainer<Real> > robinVal
269 = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide);
270 computeRobin(robinVal,valU_eval_bdry,valZ_eval_bdry,i,j,1,1);
271 Intrepid::FunctionSpaceTools::scalarMultiplyDataField<Real>(robinVal_N,
272 *robinVal,
273 *(fe_bdry_[i][j]->N()));
274 Intrepid::FunctionSpaceTools::integrate<Real>(robinJac,
275 robinVal_N,
276 *(fe_bdry_[i][j]->NdetJ()),
277 Intrepid::COMP_CPP, false);
278 // Add Stefan-Boltzmann residual to volume residual
279 for (int k = 0; k < numCellsSide; ++k) {
280 int cidx = bdryCellLocIds_[i][j][k];
281 for (int l = 0; l < f; ++l) {
282 for (int m = 0; m < f; ++m) {
283 (*jac)(cidx,l,m) += robinJac(k,l,m);
284 }
285 }
286 }
287 }
288 }
289 }
290 }
291 }
292 }
293
294 void Jacobian_2(ROL::Ptr<Intrepid::FieldContainer<Real> > & jac,
295 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
296 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
297 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
298 // GET DIMENSIONS
299 const int c = fe_vol_->gradN()->dimension(0);
300 const int f = fe_vol_->gradN()->dimension(1);
301 const int p = fe_vol_->gradN()->dimension(2);
302 // INITIALIZE JACOBIAN
303 jac = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, f);
304 // COMPUTE PDE COEFFICIENTS
305 Intrepid::FieldContainer<Real> lambda2(c, p), delta2(c, p), scale(c, p);
306 computeCoefficients(lambda2,delta2,scale);
307 // ADD CONTROL TERM
308 Intrepid::FieldContainer<Real> valN_scal(c, f, p);
309 Intrepid::FunctionSpaceTools::scalarMultiplyDataField<Real>(valN_scal,scale,*(fe_vol_->N()));
310 Intrepid::FunctionSpaceTools::integrate<Real>(*jac,
311 valN_scal,
312 *(fe_vol_->NdetJ()),
313 Intrepid::COMP_CPP, false);
314 // APPLY DIRICHLET CONDITIONS
315 const int numSideSets = bdryCellLocIds_.size();
316 for (int i = 0; i < numSideSets; ++i) {
317 if ( i==1 || i==2 || i==3 ) {
318 int numLocalSideIds = bdryCellLocIds_[i].size();
319 for (int j = 0; j < numLocalSideIds; ++j) {
320 int numCellsSide = bdryCellLocIds_[i][j].size();
321 if (!useRobin_) {
322 int numBdryDofs = fidx_[j].size();
323 for (int k = 0; k < numCellsSide; ++k) {
324 int cidx = bdryCellLocIds_[i][j][k];
325 for (int l = 0; l < numBdryDofs; ++l) {
326 //std::cout << "\n j=" << j << " l=" << l << " " << fidx[j][l];
327 for (int m = 0; m < f; ++m) {
328 (*jac)(cidx,fidx_[j][l],m) = static_cast<Real>(0);
329 }
330 }
331 }
332 }
333 else {
334 const int numCubPerSide = bdryCub_->getNumPoints();
335 if (numCellsSide) {
336 // Get U and Z coefficients on Robin boundary
337 ROL::Ptr<Intrepid::FieldContainer<Real > > u_coeff_bdry, z_coeff_bdry;
338 u_coeff_bdry = getBoundaryCoeff(*u_coeff, i, j);
339 z_coeff_bdry = getBoundaryCoeff(*z_coeff, i, j);
340 // Evaluate U and Z on FE basis
341 ROL::Ptr<Intrepid::FieldContainer<Real > > valU_eval_bdry, valZ_eval_bdry;
342 valU_eval_bdry = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide);
343 valZ_eval_bdry = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide);
344 fe_bdry_[i][j]->evaluateValue(valU_eval_bdry, u_coeff_bdry);
345 fe_bdry_[i][j]->evaluateValue(valZ_eval_bdry, z_coeff_bdry);
346 // Compute Robin residual
347 Intrepid::FieldContainer<Real> robinVal_N(numCellsSide, f, numCubPerSide);
348 Intrepid::FieldContainer<Real> robinJac(numCellsSide, f, f);
349 ROL::Ptr< Intrepid::FieldContainer<Real> > robinVal
350 = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide);
351 computeRobin(robinVal,valU_eval_bdry,valZ_eval_bdry,i,j,1,2);
352 Intrepid::FunctionSpaceTools::scalarMultiplyDataField<Real>(robinVal_N,
353 *robinVal,
354 *(fe_bdry_[i][j]->N()));
355 Intrepid::FunctionSpaceTools::integrate<Real>(robinJac,
356 robinVal_N,
357 *(fe_bdry_[i][j]->NdetJ()),
358 Intrepid::COMP_CPP, false);
359 // Add Stefan-Boltzmann residual to volume residual
360 for (int k = 0; k < numCellsSide; ++k) {
361 int cidx = bdryCellLocIds_[i][j][k];
362 for (int l = 0; l < f; ++l) {
363 for (int m = 0; m < f; ++m) {
364 (*jac)(cidx,l,m) += robinJac(k,l,m);
365 }
366 }
367 }
368 }
369 }
370 }
371 }
372 }
373 }
374
375 void Hessian_11(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess,
376 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & l_coeff,
377 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
378 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
379 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
380 // GET DIMENSIONS
381 const int c = fe_vol_->gradN()->dimension(0);
382 const int f = fe_vol_->gradN()->dimension(1);
383 const int p = fe_vol_->gradN()->dimension(2);
384 // INITIALIZE HESSIAN
385 hess = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, f);
386 // COMPUTE PDE COEFFICIENTS
387 Intrepid::FieldContainer<Real> lambda2(c, p), delta2(c, p), scale(c, p);
388 computeCoefficients(lambda2,delta2,scale);
389 // APPLY DIRICHLET CONDITIONS
390 ROL::Ptr<Intrepid::FieldContainer<Real> > l_dbc
391 = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
392 *l_dbc = *l_coeff;
393 const int numSideSets = bdryCellLocIds_.size();
394 for (int i = 0; i < numSideSets; ++i) {
395 if ( i==1 || i==2 || i==3 ) {
396 int numLocalSideIds = bdryCellLocIds_[i].size();
397 for (int j = 0; j < numLocalSideIds; ++j) {
398 int numCellsSide = bdryCellLocIds_[i][j].size();
399 int numBdryDofs = fidx_[j].size();
400 for (int k = 0; k < numCellsSide; ++k) {
401 int cidx = bdryCellLocIds_[i][j][k];
402 for (int l = 0; l < numBdryDofs; ++l) {
403 (*l_dbc)(cidx,fidx_[j][l]) = static_cast<Real>(0);
404 }
405 }
406 }
407 }
408 }
409 // COMPUTE NONLINEAR TERM
410 ROL::Ptr<Intrepid::FieldContainer<Real> > valU_eval =
411 ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
412 fe_vol_->evaluateValue(valU_eval, u_coeff);
413 ROL::Ptr<Intrepid::FieldContainer<Real> > valL_eval =
414 ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
415 fe_vol_->evaluateValue(valL_eval, l_dbc);
416 Intrepid::FieldContainer<Real> d2phi_valU_eval(c, p);
417 for (int i = 0; i < c; ++i) {
418 for (int j = 0; j < p; ++j) {
419 d2phi_valU_eval(i,j) = (*valL_eval)(i,j)*delta2(i,j)
420 *(uScale_*std::exp((*valU_eval)(i,j))-vScale_*std::exp(-(*valU_eval)(i,j)));
421 }
422 }
423 Intrepid::FieldContainer<Real> NLexpU(c,f,p);
424 Intrepid::FunctionSpaceTools::scalarMultiplyDataField<Real>(NLexpU,
425 d2phi_valU_eval,
426 *(fe_vol_->N()));
427 Intrepid::FunctionSpaceTools::integrate<Real>(*hess,
428 NLexpU,
429 *(fe_vol_->NdetJ()),
430 Intrepid::COMP_CPP, false);
431 }
432
433 void Hessian_12(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess,
434 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & l_coeff,
435 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
436 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
437 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
438 throw Exception::Zero(">>> (PDE_Poisson_Boltzmann_ex02:Hessian_12: Hessian is zero.");
439 }
440
441 void Hessian_21(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess,
442 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & l_coeff,
443 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
444 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
445 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
446 throw Exception::Zero(">>> (PDE_Poisson_Boltzmann_ex02:Hessian_21: Hessian is zero.");
447 }
448
449 void Hessian_22(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess,
450 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & l_coeff,
451 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
452 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
453 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
454 throw Exception::Zero(">>> (PDE_Poisson_Boltzmann_ex02:Hessian_22: Hessian is zero.");
455 }
456
457 void RieszMap_1(ROL::Ptr<Intrepid::FieldContainer<Real> > & riesz) {
458 // GET DIMENSIONS
459 const int c = fe_vol_->N()->dimension(0);
460 const int f = fe_vol_->N()->dimension(1);
461 // INITIALIZE RIESZ
462 riesz = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, f);
463 *riesz = *fe_vol_->stiffMat();
464 Intrepid::RealSpaceTools<Real>::add(*riesz,*(fe_vol_->massMat()));
465 }
466
467 void RieszMap_2(ROL::Ptr<Intrepid::FieldContainer<Real> > & riesz) {
468 // GET DIMENSIONS
469 const int c = fe_vol_->N()->dimension(0);
470 const int f = fe_vol_->N()->dimension(1);
471 // INITIALIZE RIESZ
472 riesz = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, f);
473 *riesz = *fe_vol_->stiffMat();
474 Intrepid::RealSpaceTools<Real>::add(*riesz,*(fe_vol_->massMat()));
475 }
476
477 std::vector<ROL::Ptr<Intrepid::Basis<Real, Intrepid::FieldContainer<Real> > > > getFields() {
478 return basisPtrs_;
479 }
480
481 void setCellNodes(const ROL::Ptr<Intrepid::FieldContainer<Real> > &volCellNodes,
482 const std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > > &bdryCellNodes,
483 const std::vector<std::vector<std::vector<int> > > &bdryCellLocIds) {
484 volCellNodes_ = volCellNodes;
485 bdryCellNodes_ = bdryCellNodes;
486 bdryCellLocIds_ = bdryCellLocIds;
487 // Finite element definition.
488 fe_vol_ = ROL::makePtr<FE<Real>>(volCellNodes_,basisPtr_,cellCub_);
489 // Set local boundary DOFs.
490 fidx_ = fe_vol_->getBoundaryDofs();
491 // Construct boundary FEs
492 const int numSidesets = bdryCellNodes.size();
493 fe_bdry_.resize(numSidesets);
494 for(int i = 0; i < numSidesets; ++i) {
495 int numLocSides = bdryCellNodes[i].size();
496 fe_bdry_[i].resize(numLocSides);
497 for (int j = 0; j < numLocSides; ++j) {
498 if (bdryCellNodes_[i][j] != ROL::nullPtr) {
499 fe_bdry_[i][j] = ROL::makePtr<FE<Real>>(bdryCellNodes_[i][j],basisPtr_,bdryCub_,j);
500 }
501 }
502 }
503 }
504
505 const ROL::Ptr<FE<Real> > getFE(void) const {
506 return fe_vol_;
507 }
508
509 const std::vector<std::vector<ROL::Ptr<FE<Real> > > > getBdryFE(void) const {
510 return fe_bdry_;
511 }
512
513 const ROL::Ptr<Intrepid::FieldContainer<Real> > getCellNodes(void) const {
514 return volCellNodes_;
515 }
516
517 const std::vector<std::vector<std::vector<int> > > getBdryCellLocIds(void) const {
518 return bdryCellLocIds_;
519 }
520
521 private:
522
523 Real evaluateLambda2(const std::vector<Real> &x) const {
524 const std::vector<Real> param = PDE<Real>::getParameter();
525 Real p0 = (param.size()>0 ? param[0] : static_cast<Real>(-1.5));
526 return static_cast<Real>(2.5)*std::pow(static_cast<Real>(10),p0);
527 }
528
529 Real evaluateDelta2(const std::vector<Real> &x) const {
530 const std::vector<Real> param = PDE<Real>::getParameter();
531 Real p1 = (param.size()>1 ? param[1] : static_cast<Real>(-0.5));
532 return static_cast<Real>(1.45)*std::pow(static_cast<Real>(10),p1);
533 }
534
535 Real evaluateScale(const std::vector<Real> &x) const {
536 return 1;
537 // const std::vector<Real> param = PDE<Real>::getParameter();
538 // const Real Y1 = static_cast<Real>(1) + static_cast<Real>(5)*(wy_-x[1])*param[2];
539 // const Real Y2 = static_cast<Real>(1) + static_cast<Real>(5)*(wy_-x[1])*param[3];
540 // const Real X1 = phi(x[0]);
541 // const Real X2 = static_cast<Real>(1)-X1;
542 // return Y1*X1 + Y2*X2;
543 }
544
545 Real phi(const Real x) const {
546 const Real zero(0), one(1), two(2);
547 const Real eps = std::sqrt(ROL::ROL_EPSILON<Real>());
548 const Real m = one/(wx_-two*dx_);
549 const Real v = (x < dx_+eps ? zero
550 : (x > wx_-dx_-eps ? one
551 : m*(x-dx_)));
552 return v;
553 }
554
555 void computeCoefficients(Intrepid::FieldContainer<Real> &lambda2,
556 Intrepid::FieldContainer<Real> &delta2,
557 Intrepid::FieldContainer<Real> &scale) const {
558 // GET DIMENSIONS
559 const int c = fe_vol_->gradN()->dimension(0);
560 const int p = fe_vol_->gradN()->dimension(2);
561 const int d = fe_vol_->gradN()->dimension(3);
562 std::vector<Real> pt(d);
563 for (int i = 0; i < c; ++i) {
564 for (int j = 0; j < p; ++j) {
565 for ( int k = 0; k < d; ++k) {
566 pt[k] = (*fe_vol_->cubPts())(i,j,k);
567 }
568 // Compute scaled Debye length
569 lambda2(i,j) = evaluateLambda2(pt);
570 delta2(i,j) = evaluateDelta2(pt);
571 scale(i,j) = -evaluateScale(pt);
572 }
573 }
574 }
575
576 Real evaluateRobin(const Real u, const Real z, const std::vector<Real> &x,
577 const int sideset, const int locSideId,
578 const int deriv = 0, const int component = 1) const {
579 const Real four(4), two(2), one(1);
580 Real C(0);
581 if (sideset==1 || sideset==3) {
582 C = static_cast<Real>(1);
583 }
584 if (sideset==2) {
585 C = static_cast<Real>(0.3);
586 }
587 Real f0 = std::log((C+std::sqrt(C*C+four))/two);
588 Real f1 = one/std::sqrt(C*C+four);
589 if ( deriv == 1 ) {
590 return (component==1) ? robinCoeff_ : -robinCoeff_ * f1;
591 }
592 if ( deriv > 1 ) {
593 return static_cast<Real>(0);
594 }
595 return robinCoeff_ * (u - (f0 + f1*(z-C)));
596 }
597
598 void computeRobin(ROL::Ptr<Intrepid::FieldContainer<Real> > &robin,
599 const ROL::Ptr<Intrepid::FieldContainer<Real> > &u,
600 const ROL::Ptr<Intrepid::FieldContainer<Real> > &z,
601 const int sideset,
602 const int locSideId,
603 const int deriv = 0,
604 const int component = 1) const {
605 const int c = u->dimension(0);
606 const int p = u->dimension(1);
607 const int d = fe_vol_->gradN()->dimension(3);
608 std::vector<Real> pt(d);
609 for (int i = 0; i < c; ++i) {
610 for (int j = 0; j < p; ++j) {
611 for (int k = 0; k < d; ++k) {
612 pt[k] = (*fe_bdry_[sideset][locSideId]->cubPts())(i,j,k);
613 }
614 (*robin)(i,j) = evaluateRobin((*u)(i,j),(*z)(i,j),pt,sideset,locSideId,deriv,component);
615 }
616 }
617 }
618
619 Real evaluateDirichlet(const std::vector<Real> & coords, int sideset, int locSideId) const {
620 Real val(0);
621 if (sideset==1) {
622 val = static_cast<Real>(0.436);
623 }
624 if (sideset==2) {
625 val = static_cast<Real>(0.407);
626 }
627 if (sideset==3) {
628 val = static_cast<Real>(0.436);
629 }
630 return val;
631 }
632
633 void computeDirichlet(std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > > & bdryCellDofValues) const {
634 // Compute Dirichlet values at DOFs.
635 int d = basisPtr_->getBaseCellTopology().getDimension();
636 int numSidesets = bdryCellLocIds_.size();
637 bdryCellDofValues.resize(numSidesets);
638 for (int i=0; i<numSidesets; ++i) {
639 int numLocSides = bdryCellLocIds_[i].size();
640 bdryCellDofValues[i].resize(numLocSides);
641 for (int j=0; j<numLocSides; ++j) {
642 int c = bdryCellLocIds_[i][j].size();
643 int f = basisPtr_->getCardinality();
644 bdryCellDofValues[i][j] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f);
645 ROL::Ptr<Intrepid::FieldContainer<Real> > coords =
646 ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, d);
647 if (c > 0) {
648 fe_vol_->computeDofCoords(coords, bdryCellNodes_[i][j]);
649 }
650 for (int k=0; k<c; ++k) {
651 for (int l=0; l<f; ++l) {
652 std::vector<Real> dofpoint(d);
653 for (int m=0; m<d; ++m) {
654 dofpoint[m] = (*coords)(k, l, m);
655 }
656 (*bdryCellDofValues[i][j])(k, l) = evaluateDirichlet(dofpoint, i, j);
657 }
658 }
659 }
660 }
661 }
662
663 ROL::Ptr<Intrepid::FieldContainer<Real> > getBoundaryCoeff(
664 const Intrepid::FieldContainer<Real> & cell_coeff,
665 int sideSet, int cell) const {
666 std::vector<int> bdryCellLocId = bdryCellLocIds_[sideSet][cell];
667 const int numCellsSide = bdryCellLocId.size();
668 const int f = basisPtr_->getCardinality();
669
670 ROL::Ptr<Intrepid::FieldContainer<Real > > bdry_coeff =
671 ROL::makePtr<Intrepid::FieldContainer<Real >>(numCellsSide, f);
672 for (int i = 0; i < numCellsSide; ++i) {
673 for (int j = 0; j < f; ++j) {
674 (*bdry_coeff)(i, j) = cell_coeff(bdryCellLocId[i], j);
675 }
676 }
677 return bdry_coeff;
678 }
679
680 }; // PDE_Poisson_Boltzmann
681
682 template <class Real>
683 class PDE_Doping : public PDE<Real> {
684 private:
685 // Finite element basis information
686 ROL::Ptr<Intrepid::Basis<Real, Intrepid::FieldContainer<Real> > > basisPtr_;
687 std::vector<ROL::Ptr<Intrepid::Basis<Real, Intrepid::FieldContainer<Real> > > > basisPtrs_;
688 // Cell cubature information
689 ROL::Ptr<Intrepid::Cubature<Real> > cellCub_;
690 ROL::Ptr<Intrepid::Cubature<Real> > bdryCub_;
691 // Cell node information
692 ROL::Ptr<Intrepid::FieldContainer<Real> > volCellNodes_;
693 std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > > bdryCellNodes_;
694 std::vector<std::vector<std::vector<int> > > bdryCellLocIds_;
695 // Finite element definition
696 ROL::Ptr<FE<Real> > fe_vol_;
697 std::vector<std::vector<ROL::Ptr<FE<Real> > > > fe_bdry_;
698 // Local degrees of freedom on boundary, for each side of the reference cell (first index).
699 std::vector<std::vector<int> > fidx_;
700 Real a_, b_;
701
702 public:
703 PDE_Doping(Teuchos::ParameterList &parlist) {
704 // Finite element fields.
705 int basisOrder = parlist.sublist("Problem").get("Order of FE discretization",1);
706 if (basisOrder == 1) {
707 basisPtr_ = ROL::makePtr<Intrepid::Basis_HGRAD_QUAD_C1_FEM<Real, Intrepid::FieldContainer<Real> >>();
708 }
709 else if (basisOrder == 2) {
710 basisPtr_ = ROL::makePtr<Intrepid::Basis_HGRAD_QUAD_C2_FEM<Real, Intrepid::FieldContainer<Real> >>();
711 }
712 basisPtrs_.clear(); basisPtrs_.push_back(basisPtr_);
713 // Quadrature rules.
714 shards::CellTopology cellType = basisPtr_->getBaseCellTopology(); // get the cell type from any basis
715 Intrepid::DefaultCubatureFactory<Real> cubFactory; // create cubature factory
716 int cubDegree = parlist.sublist("PDE Poisson Boltzmann").get("Cubature Degree",2); // set cubature degree, e.g., 2
717 cellCub_ = cubFactory.create(cellType, cubDegree); // create default cubature
718
719 int d = cellType.getDimension();
720 shards::CellTopology bdryCellType = cellType.getCellTopologyData(d-1, 0);
721 int bdryCubDegree = parlist.sublist("Problem").get("Boundary Cubature Degree",2); // set cubature degree, e.g., 2
722 bdryCub_ = cubFactory.create(bdryCellType, bdryCubDegree);
723 a_ = parlist.sublist("Problem").get("Desired Lower Doping Value", 0.3);
724 b_ = parlist.sublist("Problem").get("Desired Upper Doping Value", 1.0);
725 }
726
727 void residual(ROL::Ptr<Intrepid::FieldContainer<Real> > & res,
728 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
729 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
730 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
731 const std::vector<Real> param = PDE<Real>::getParameter();
732 Real cond = (param.size()>2 ? param[2] : static_cast<Real>(2e-5));
733 // GET DIMENSIONS
734 const int c = fe_vol_->gradN()->dimension(0);
735 const int f = fe_vol_->gradN()->dimension(1);
736 const int p = fe_vol_->gradN()->dimension(2);
737 const int d = fe_vol_->gradN()->dimension(3);
738 // INITIALIZE RESIDUAL
739 res = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f);
740 // EVALUATE STATE AND CONTROL OF FEM BASIS
741 ROL::Ptr<Intrepid::FieldContainer<Real> > valU_eval, valZ_eval, gradU_eval;
742 valU_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
743 valZ_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
744 gradU_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d);
745 fe_vol_->evaluateValue(valU_eval, u_coeff);
746 fe_vol_->evaluateValue(valZ_eval, z_coeff);
747 fe_vol_->evaluateGradient(gradU_eval, u_coeff);
748 // ADD STIFFNESS TERM TO RESIDUAL
749 Intrepid::FieldContainer<Real> lambda2_gradU_eval(c, p, d);
750 Intrepid::RealSpaceTools<Real>::scale(lambda2_gradU_eval,*gradU_eval,cond);
751 Intrepid::FunctionSpaceTools::integrate<Real>(*res,
752 lambda2_gradU_eval,
753 *(fe_vol_->gradNdetJ()),
754 Intrepid::COMP_CPP, false);
755 // ADD REACTION TERM TO RESIDUAL
756 Intrepid::FunctionSpaceTools::integrate<Real>(*res,
757 *valU_eval,
758 *(fe_vol_->NdetJ()),
759 Intrepid::COMP_CPP, true);
760 // ADD CONTROL TERM TO RESIDUAL
761 Intrepid::FieldContainer<Real> valZ_scal(c, p);
762 Intrepid::RealSpaceTools<Real>::scale(valZ_scal,*valZ_eval,static_cast<Real>(-1));
763 Intrepid::FunctionSpaceTools::integrate<Real>(*res,
764 valZ_scal,
765 *(fe_vol_->NdetJ()),
766 Intrepid::COMP_CPP, true);
767 // APPLY DIRICHLET CONDITIONS
768 std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > > bdryCellDofValues;
769 computeDirichlet(bdryCellDofValues);
770 const int numSideSets = bdryCellLocIds_.size();
771 for (int i = 0; i < numSideSets; ++i) {
772 if ( i==1 || i==2 || i==3 ) {
773 int numLocalSideIds = bdryCellLocIds_[i].size();
774 for (int j = 0; j < numLocalSideIds; ++j) {
775 int numCellsSide = bdryCellLocIds_[i][j].size();
776 int numBdryDofs = fidx_[j].size();
777 for (int k = 0; k < numCellsSide; ++k) {
778 int cidx = bdryCellLocIds_[i][j][k];
779 for (int l = 0; l < numBdryDofs; ++l) {
780 (*res)(cidx,fidx_[j][l]) = (*u_coeff)(cidx,fidx_[j][l]) - (*bdryCellDofValues[i][j])(k,l);
781 }
782 }
783 }
784 }
785 }
786 }
787
788 void Jacobian_1(ROL::Ptr<Intrepid::FieldContainer<Real> > & jac,
789 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
790 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
791 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
792 const std::vector<Real> param = PDE<Real>::getParameter();
793 Real cond = (param.size()>2 ? param[2] : static_cast<Real>(2e-5));
794 // GET DIMENSIONS
795 const int c = fe_vol_->gradN()->dimension(0);
796 const int f = fe_vol_->gradN()->dimension(1);
797 const int p = fe_vol_->gradN()->dimension(2);
798 const int d = fe_vol_->gradN()->dimension(3);
799 // INITIALIZE JACOBIAN
800 jac = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, f);
801 // ADD STIFFNESS TERM TO JACOBIAN
802 Intrepid::FieldContainer<Real> lambda2_gradN_eval(c, f, p, d);
803 Intrepid::RealSpaceTools<Real>::scale(lambda2_gradN_eval,*(fe_vol_->gradN()),cond);
804 Intrepid::FunctionSpaceTools::integrate<Real>(*jac,
805 lambda2_gradN_eval,
806 *(fe_vol_->gradNdetJ()),
807 Intrepid::COMP_CPP, false);
808 // ADD REACTION TERM TO JACOBIAN
809 Intrepid::FunctionSpaceTools::integrate<Real>(*jac,
810 *(fe_vol_->N()),
811 *(fe_vol_->NdetJ()),
812 Intrepid::COMP_CPP, true);
813 // APPLY DIRICHLET CONDITIONS
814 const int numSideSets = bdryCellLocIds_.size();
815 for (int i = 0; i < numSideSets; ++i) {
816 if ( i==1 || i==2 || i==3 ) {
817 int numLocalSideIds = bdryCellLocIds_[i].size();
818 for (int j = 0; j < numLocalSideIds; ++j) {
819 int numCellsSide = bdryCellLocIds_[i][j].size();
820 int numBdryDofs = fidx_[j].size();
821 for (int k = 0; k < numCellsSide; ++k) {
822 int cidx = bdryCellLocIds_[i][j][k];
823 for (int l = 0; l < numBdryDofs; ++l) {
824 //std::cout << "\n j=" << j << " l=" << l << " " << fidx[j][l];
825 for (int m = 0; m < f; ++m) {
826 (*jac)(cidx,fidx_[j][l],m) = static_cast<Real>(0);
827 }
828 (*jac)(cidx,fidx_[j][l],fidx_[j][l]) = static_cast<Real>(1);
829 }
830 }
831 }
832 }
833 }
834 }
835
836 void Jacobian_2(ROL::Ptr<Intrepid::FieldContainer<Real> > & jac,
837 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
838 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
839 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
840 // GET DIMENSIONS
841 const int c = fe_vol_->gradN()->dimension(0);
842 const int f = fe_vol_->gradN()->dimension(1);
843 const int p = fe_vol_->gradN()->dimension(2);
844 // INITIALIZE JACOBIAN
845 jac = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, f);
846 // ADD CONTROL TERM
847 Intrepid::FieldContainer<Real> valN_scal(c, f, p);
848 Intrepid::RealSpaceTools<Real>::scale(valN_scal,*(fe_vol_->N()),static_cast<Real>(-1));
849 Intrepid::FunctionSpaceTools::integrate<Real>(*jac,
850 valN_scal,
851 *(fe_vol_->NdetJ()),
852 Intrepid::COMP_CPP, false);
853 // APPLY DIRICHLET CONDITIONS
854 const int numSideSets = bdryCellLocIds_.size();
855 for (int i = 0; i < numSideSets; ++i) {
856 if ( i==1 || i==2 || i==3 ) {
857 int numLocalSideIds = bdryCellLocIds_[i].size();
858 for (int j = 0; j < numLocalSideIds; ++j) {
859 int numCellsSide = bdryCellLocIds_[i][j].size();
860 int numBdryDofs = fidx_[j].size();
861 for (int k = 0; k < numCellsSide; ++k) {
862 int cidx = bdryCellLocIds_[i][j][k];
863 for (int l = 0; l < numBdryDofs; ++l) {
864 //std::cout << "\n j=" << j << " l=" << l << " " << fidx[j][l];
865 for (int m = 0; m < f; ++m) {
866 (*jac)(cidx,fidx_[j][l],m) = static_cast<Real>(0);
867 }
868 }
869 }
870 }
871 }
872 }
873 }
874
875 void Hessian_11(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess,
876 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & l_coeff,
877 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
878 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
879 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
880 throw Exception::Zero(">>> (PDE_Poisson_Boltzmann_ex02:Hessian_11: Hessian is zero.");
881 }
882
883 void Hessian_12(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess,
884 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & l_coeff,
885 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
886 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
887 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
888 throw Exception::Zero(">>> (PDE_Poisson_Boltzmann_ex02:Hessian_12: Hessian is zero.");
889 }
890
891 void Hessian_21(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess,
892 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & l_coeff,
893 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
894 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
895 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
896 throw Exception::Zero(">>> (PDE_Poisson_Boltzmann_ex02:Hessian_21: Hessian is zero.");
897 }
898
899 void Hessian_22(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess,
900 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & l_coeff,
901 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
902 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
903 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
904 throw Exception::Zero(">>> (PDE_Poisson_Boltzmann_ex02:Hessian_22: Hessian is zero.");
905 }
906
907 void RieszMap_1(ROL::Ptr<Intrepid::FieldContainer<Real> > & riesz) {
908 // GET DIMENSIONS
909 const int c = fe_vol_->N()->dimension(0);
910 const int f = fe_vol_->N()->dimension(1);
911 // INITIALIZE RIESZ
912 riesz = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, f);
913 *riesz = *fe_vol_->stiffMat();
914 Intrepid::RealSpaceTools<Real>::add(*riesz,*(fe_vol_->massMat()));
915 }
916
917 void RieszMap_2(ROL::Ptr<Intrepid::FieldContainer<Real> > & riesz) {
918 // GET DIMENSIONS
919 const int c = fe_vol_->N()->dimension(0);
920 const int f = fe_vol_->N()->dimension(1);
921 // INITIALIZE RIESZ
922 riesz = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, f);
923 *riesz = *fe_vol_->stiffMat();
924 Intrepid::RealSpaceTools<Real>::add(*riesz,*(fe_vol_->massMat()));
925 }
926
927 std::vector<ROL::Ptr<Intrepid::Basis<Real, Intrepid::FieldContainer<Real> > > > getFields() {
928 return basisPtrs_;
929 }
930
931 void setCellNodes(const ROL::Ptr<Intrepid::FieldContainer<Real> > &volCellNodes,
932 const std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > > &bdryCellNodes,
933 const std::vector<std::vector<std::vector<int> > > &bdryCellLocIds) {
934 volCellNodes_ = volCellNodes;
935 bdryCellNodes_ = bdryCellNodes;
936 bdryCellLocIds_ = bdryCellLocIds;
937 // Finite element definition.
938 fe_vol_ = ROL::makePtr<FE<Real>>(volCellNodes_,basisPtr_,cellCub_);
939 // Set local boundary DOFs.
940 fidx_ = fe_vol_->getBoundaryDofs();
941 // Construct boundary FEs
942 const int numSidesets = bdryCellNodes.size();
943 fe_bdry_.resize(numSidesets);
944 for(int i = 0; i < numSidesets; ++i) {
945 int numLocSides = bdryCellNodes[i].size();
946 fe_bdry_[i].resize(numLocSides);
947 for (int j = 0; j < numLocSides; ++j) {
948 if (bdryCellNodes_[i][j] != ROL::nullPtr) {
949 fe_bdry_[i][j] = ROL::makePtr<FE<Real>>(bdryCellNodes_[i][j],basisPtr_,bdryCub_,j);
950 }
951 }
952 }
953 }
954
955 const ROL::Ptr<FE<Real> > getFE(void) const {
956 return fe_vol_;
957 }
958
959 const std::vector<std::vector<ROL::Ptr<FE<Real> > > > getBdryFE(void) const {
960 return fe_bdry_;
961 }
962
963 const ROL::Ptr<Intrepid::FieldContainer<Real> > getCellNodes(void) const {
964 return volCellNodes_;
965 }
966
967 const std::vector<std::vector<std::vector<int> > > getBdryCellLocIds(void) const {
968 return bdryCellLocIds_;
969 }
970
971 private:
972
973 Real evaluateDirichlet(const std::vector<Real> & coords, int sideset, int locSideId) const {
974 Real val(0);
975 if (sideset==1) {
976 val = a_;
977 }
978 if (sideset==2) {
979 val = b_;
980 }
981 if (sideset==3) {
982 val = a_;
983 }
984 return val;
985 }
986
987 void computeDirichlet(std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > > & bdryCellDofValues) const {
988 // Compute Dirichlet values at DOFs.
989 int d = basisPtr_->getBaseCellTopology().getDimension();
990 int numSidesets = bdryCellLocIds_.size();
991 bdryCellDofValues.resize(numSidesets);
992 for (int i=0; i<numSidesets; ++i) {
993 int numLocSides = bdryCellLocIds_[i].size();
994 bdryCellDofValues[i].resize(numLocSides);
995 for (int j=0; j<numLocSides; ++j) {
996 int c = bdryCellLocIds_[i][j].size();
997 int f = basisPtr_->getCardinality();
998 bdryCellDofValues[i][j] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f);
999 ROL::Ptr<Intrepid::FieldContainer<Real> > coords =
1000 ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, d);
1001 if (c > 0) {
1002 fe_vol_->computeDofCoords(coords, bdryCellNodes_[i][j]);
1003 }
1004 for (int k=0; k<c; ++k) {
1005 for (int l=0; l<f; ++l) {
1006 std::vector<Real> dofpoint(d);
1007 for (int m=0; m<d; ++m) {
1008 dofpoint[m] = (*coords)(k, l, m);
1009 }
1010 (*bdryCellDofValues[i][j])(k, l) = evaluateDirichlet(dofpoint, i, j);
1011 }
1012 }
1013 }
1014 }
1015 }
1016
1017 }; // PDE_Poisson_Boltzmann
1018
1019 #endif