Debian Codegraph @

packages/rol/example/PDE-OPT/dynamic/semilinear/dynpde_semilinear.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_SEMILINEAR_HPP
15 #define PDEOPT_DYNAMIC_SEMILINEAR_HPP
16
17 #include "../../TOOLS/dynpde.hpp"
18 #include "../../TOOLS/fe.hpp"
19 #include "pde_semilinear.hpp"
20
21 template <class Real>
22 class DynamicPDE_Semilinear : public DynamicPDE<Real> {
23 private:
24 // Finite element definition
25 ROL::Ptr<FE<Real>> fe_vol_;
26 // Steady PDE without Dirichlet BC
27 ROL::Ptr<PDE_Semilinear<Real>> pde_;
28 Real theta_;
29
30 public:
31 DynamicPDE_Semilinear(Teuchos::ParameterList &parlist) {
32 pde_ = ROL::makePtr<PDE_Semilinear<Real>>(parlist);
33 // Time-dependent coefficients
34 theta_ = parlist.sublist("Time Discretization").get("Theta",1.0);
35 }
36
37 void residual(ROL::Ptr<Intrepid::FieldContainer<Real>> & res,
38 const ROL::TimeStamp<Real> & ts,
39 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & uo_coeff,
40 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & un_coeff,
41 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
42 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
43 const Real one(1);
44 // GET DIMENSIONS
45 int c = fe_vol_->gradN()->dimension(0);
46 int f = fe_vol_->gradN()->dimension(1);
47 int p = fe_vol_->gradN()->dimension(2);
48 // GET TIME STEP INFORMATION
49 Real told = ts.t[0], tnew = ts.t[1], dt = tnew-told;
50 // INITIALIZE STORAGE
51 ROL::Ptr<Intrepid::FieldContainer<Real>> pde
52 = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f);
53 ROL::Ptr<Intrepid::FieldContainer<Real>> valU_eval
54 = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
55 // COMPUTE OLD RESIDUAL
56 pde_->setTime(told);
57 pde_->residual(res,uo_coeff,z_coeff,z_param);
58 // Integrate Uold * N
59 fe_vol_->evaluateValue(valU_eval, uo_coeff);
60 Intrepid::FunctionSpaceTools::integrate<Real>(*pde,
61 *valU_eval,
62 *(fe_vol_->NdetJ()),
63 Intrepid::COMP_CPP, false);
64 Intrepid::RealSpaceTools<Real>::scale(*res, (one-theta_)*dt);
65 Intrepid::RealSpaceTools<Real>::subtract(*res, *pde);
66 // COMPUTE NEW RESIDUAL
67 pde_->setTime(tnew);
68 pde_->residual(pde,un_coeff,z_coeff,z_param);
69 // Integrate Uold * N
70 valU_eval->initialize();
71 fe_vol_->evaluateValue(valU_eval, un_coeff);
72 Intrepid::FunctionSpaceTools::integrate<Real>(*res,
73 *valU_eval,
74 *(fe_vol_->NdetJ()),
75 Intrepid::COMP_CPP, true);
76 Intrepid::RealSpaceTools<Real>::scale(*pde, theta_*dt);
77 Intrepid::RealSpaceTools<Real>::add(*res, *pde);
78 }
79
80 void Jacobian_uo(ROL::Ptr<Intrepid::FieldContainer<Real>> & jac,
81 const ROL::TimeStamp<Real> & ts,
82 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & uo_coeff,
83 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & un_coeff,
84 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
85 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
86 const Real one(1);
87 // GET DIMENSIONS
88 int c = fe_vol_->gradN()->dimension(0);
89 int f = fe_vol_->gradN()->dimension(1);
90 // GET TIME STEP INFORMATION
91 Real told = ts.t[0], tnew = ts.t[1], dt = tnew-told;
92 // INITILAIZE JACOBIAN
93 ROL::Ptr<Intrepid::FieldContainer<Real>> pde
94 = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, f);
95 // COMPUTE OLD RESIDUAL
96 pde_->setTime(told);
97 pde_->Jacobian_1(jac,uo_coeff,z_coeff,z_param);
98 // Integrate N * N
99 Intrepid::FunctionSpaceTools::integrate<Real>(*pde,
100 *(fe_vol_->N()),
101 *(fe_vol_->NdetJ()),
102 Intrepid::COMP_CPP, false);
103 Intrepid::RealSpaceTools<Real>::scale(*jac, (one-theta_)*dt);
104 Intrepid::RealSpaceTools<Real>::subtract(*jac, *pde);
105 }
106
107 void Jacobian_un(ROL::Ptr<Intrepid::FieldContainer<Real>> & jac,
108 const ROL::TimeStamp<Real> & ts,
109 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & uo_coeff,
110 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & un_coeff,
111 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
112 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
113 // GET DIMENSIONS
114 int c = fe_vol_->gradN()->dimension(0);
115 int f = fe_vol_->gradN()->dimension(1);
116 // GET TIME STEP INFORMATION
117 Real told = ts.t[0], tnew = ts.t[1], dt = tnew-told;
118 // INITILAIZE JACOBIAN
119 jac = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, f);
120 ROL::Ptr<Intrepid::FieldContainer<Real>> pde;
121 // COMPUTE NEW RESIDUAL
122 pde_->setTime(tnew);
123 pde_->Jacobian_1(pde,un_coeff,z_coeff,z_param);
124 // Integrate N * N
125 Intrepid::FunctionSpaceTools::integrate<Real>(*jac,
126 *(fe_vol_->N()),
127 *(fe_vol_->NdetJ()),
128 Intrepid::COMP_CPP, false);
129 Intrepid::RealSpaceTools<Real>::scale(*pde, theta_*dt);
130 Intrepid::RealSpaceTools<Real>::add(*jac, *pde);
131 }
132
133 void Jacobian_zf(ROL::Ptr<Intrepid::FieldContainer<Real>> & jac,
134 const ROL::TimeStamp<Real> & ts,
135 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & uo_coeff,
136 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & un_coeff,
137 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
138 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
139 const Real one(1);
140 // GET DIMENSIONS
141 int c = fe_vol_->gradN()->dimension(0);
142 int f = fe_vol_->gradN()->dimension(1);
143 // GET TIME STEP INFORMATION
144 Real told = ts.t[0], tnew = ts.t[1], dt = tnew-told;
145 // INITILAIZE JACOBIAN
146 jac = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, f);
147 ROL::Ptr<Intrepid::FieldContainer<Real>> pde;
148 // ASSEMBLE OLD TIME JACOBIAN
149 pde_->setTime(told);
150 pde_->Jacobian_2(pde,uo_coeff,z_coeff,z_param);
151 // ASSEMBLE NEW TIME JACOBIAN
152 pde_->setTime(tnew);
153 pde_->Jacobian_2(jac,un_coeff,z_coeff,z_param);
154 // COMBINE JACOBIANS
155 Intrepid::RealSpaceTools<Real>::scale(*pde, (one-theta_)*dt);
156 Intrepid::RealSpaceTools<Real>::scale(*jac, theta_*dt);
157 Intrepid::RealSpaceTools<Real>::add(*jac, *pde);
158 }
159
160 void Jacobian_zp(std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> & jac,
161 const ROL::TimeStamp<Real> & ts,
162 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & uo_coeff,
163 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & un_coeff,
164 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
165 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
166 throw Exception::Zero(">>> (PDE_Semilinear::Jacobian_zp): Jacobian is zero.");
167 }
168
169 void Hessian_uo_uo(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess,
170 const ROL::TimeStamp<Real> & ts,
171 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff,
172 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & uo_coeff,
173 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & un_coeff,
174 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
175 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
176 const Real one(1);
177 // GET TIME STEP INFORMATION
178 Real told = ts.t[0], tnew = ts.t[1], dt = tnew-told;
179 // COMPUTE OLD RESIDUAL
180 pde_->setTime(told);
181 pde_->Hessian_11(hess,l_coeff,uo_coeff,z_coeff,z_param);
182 Intrepid::RealSpaceTools<Real>::scale(*hess, (one-theta_)*dt);
183 }
184
185 void Hessian_uo_un(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess,
186 const ROL::TimeStamp<Real> & ts,
187 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff,
188 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & uo_coeff,
189 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & un_coeff,
190 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
191 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
192 throw Exception::Zero(">>> (PDE_Semilinear::Hessian_uo_un): Hessian is zero.");
193 }
194
195 void Hessian_uo_zf(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess,
196 const ROL::TimeStamp<Real> & ts,
197 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff,
198 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & uo_coeff,
199 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & un_coeff,
200 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
201 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
202 throw Exception::Zero(">>> (PDE_Semilinear::Hessian_uo_zf): Hessian is zero.");
203 }
204
205 void Hessian_uo_zp(std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> & hess,
206 const ROL::TimeStamp<Real> & ts,
207 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff,
208 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & uo_coeff,
209 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & un_coeff,
210 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
211 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
212 throw Exception::Zero(">>> (PDE_Semilinear::Hessian_uo_zp): Hessian is zero.");
213 }
214
215 void Hessian_un_uo(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess,
216 const ROL::TimeStamp<Real> & ts,
217 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff,
218 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & uo_coeff,
219 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & un_coeff,
220 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
221 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
222 throw Exception::Zero(">>> (PDE_Semilinear::Hessian_un_uo): Hessian is zero.");
223 }
224
225 void Hessian_un_un(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess,
226 const ROL::TimeStamp<Real> & ts,
227 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff,
228 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & uo_coeff,
229 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & un_coeff,
230 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
231 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
232 // GET TIME STEP INFORMATION
233 Real told = ts.t[0], tnew = ts.t[1], dt = tnew-told;
234 // COMPUTE OLD RESIDUAL
235 pde_->setTime(tnew);
236 pde_->Hessian_11(hess,l_coeff,un_coeff,z_coeff,z_param);
237 Intrepid::RealSpaceTools<Real>::scale(*hess, theta_*dt);
238 }
239
240 void Hessian_un_zf(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess,
241 const ROL::TimeStamp<Real> & ts,
242 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff,
243 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & uo_coeff,
244 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & un_coeff,
245 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
246 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
247 throw Exception::Zero(">>> (PDE_Semilinear::Hessian_un_zf): Hessian is zero.");
248 }
249
250 void Hessian_un_zp(std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> & hess,
251 const ROL::TimeStamp<Real> & ts,
252 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff,
253 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & uo_coeff,
254 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & un_coeff,
255 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
256 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
257 throw Exception::Zero(">>> (PDE_Semilinear::Hessian_un_zp): Hessian is zero.");
258 }
259
260 void Hessian_zf_uo(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess,
261 const ROL::TimeStamp<Real> & ts,
262 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff,
263 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & uo_coeff,
264 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & un_coeff,
265 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
266 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
267 throw Exception::Zero(">>> (PDE_Semilinear::Hessian_zf_uo): Hessian is zero.");
268 }
269
270 void Hessian_zf_un(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess,
271 const ROL::TimeStamp<Real> & ts,
272 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff,
273 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & uo_coeff,
274 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & un_coeff,
275 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
276 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
277 throw Exception::Zero(">>> (PDE_Semilinear::Hessian_zf_un): Hessian is zero.");
278 }
279
280 void Hessian_zf_zf(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess,
281 const ROL::TimeStamp<Real> & ts,
282 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff,
283 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & uo_coeff,
284 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & un_coeff,
285 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
286 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
287 throw Exception::Zero(">>> (PDE_Semilinear::Hessian_zf_zf): Hessian is zero.");
288 }
289
290 void Hessian_zf_zp(std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> & hess,
291 const ROL::TimeStamp<Real> & ts,
292 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff,
293 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & uo_coeff,
294 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & un_coeff,
295 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
296 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
297 throw Exception::Zero(">>> (PDE_Semilinear::Hessian_zf_zp): Hessian is zero.");
298 }
299
300 void Hessian_zp_uo(std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> & hess,
301 const ROL::TimeStamp<Real> & ts,
302 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff,
303 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & uo_coeff,
304 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & un_coeff,
305 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
306 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
307 throw Exception::Zero(">>> (PDE_Semilinear::Hessian_zp_uo): Hessian is zero.");
308 }
309
310 void Hessian_zp_un(std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> & hess,
311 const ROL::TimeStamp<Real> & ts,
312 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff,
313 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & uo_coeff,
314 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & un_coeff,
315 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
316 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
317 throw Exception::Zero(">>> (PDE_Semilinear::Hessian_zp_un): Hessian is zero.");
318 }
319
320 void Hessian_zp_zf(std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> & hess,
321 const ROL::TimeStamp<Real> & ts,
322 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff,
323 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & uo_coeff,
324 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & un_coeff,
325 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
326 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
327 throw Exception::Zero(">>> (PDE_Semilinear::Hessian_zp_zf): Hessian is zero.");
328 }
329
330 void Hessian_zp_zp(std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>>> & hess,
331 const ROL::TimeStamp<Real> & ts,
332 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff,
333 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & uo_coeff,
334 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & un_coeff,
335 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
336 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
337 throw Exception::Zero(">>> (PDE_Semilinear::Hessian_zp_zp): Hessian is zero.");
338 }
339
340 void RieszMap_1(ROL::Ptr<Intrepid::FieldContainer<Real>> & riesz) {
341 pde_->RieszMap_1(riesz);
342 }
343
344 void RieszMap_2(ROL::Ptr<Intrepid::FieldContainer<Real>> & riesz) {
345 pde_->RieszMap_2(riesz);
346 }
347
348 std::vector<ROL::Ptr<Intrepid::Basis<Real, Intrepid::FieldContainer<Real>>>> getFields() {
349 return pde_->getFields();
350 }
351
352 void setCellNodes(const ROL::Ptr<Intrepid::FieldContainer<Real>> &volCellNodes,
353 const std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>>> &bdryCellNodes,
354 const std::vector<std::vector<std::vector<int>>> &bdryCellLocIds) {
355 pde_->setCellNodes(volCellNodes,bdryCellNodes,bdryCellLocIds);
356 fe_vol_ = pde_->getFE();
357 }
358
359 const ROL::Ptr<FE<Real>> getFE(void) const {
360 return fe_vol_;
361 }
362 }; // DynamicPDE_Semilinear
363
364 #endif