Debian Codegraph @

packages/rol/example/PDE-OPT/poisson-boltzmann/doping.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 #ifndef DOPING_HPP
11 #define DOPING_HPP
12
13 #include "../TOOLS/fe.hpp"
14 #include "Teuchos_ParameterList.hpp"
15 #include "Tpetra_MultiVector.hpp"
16 #include "ROL_Types.hpp"
17
18 template <class Real>
19 class Doping {
20 private:
21 typedef Tpetra::Map<>::global_ordinal_type GO;
22
23 const ROL::Ptr<FE<Real> > fe_;
24 const ROL::Ptr<Intrepid::FieldContainer<Real> > cellNodes_;
25 const ROL::Ptr<Intrepid::FieldContainer<int> > cellDofs_;
26 const Teuchos::Array<GO> cellIds_;
27 Real a_, b_, wx_, wy_;
28
29 public:
30 Doping(const ROL::Ptr<FE<Real> > &fe,
31 const ROL::Ptr<Intrepid::FieldContainer<Real> > & cellNodes,
32 const ROL::Ptr<Intrepid::FieldContainer<int> > & cellDofs,
33 const Teuchos::Array<GO> & cellIds,
34 Teuchos::ParameterList &parlist)
35 : fe_(fe), cellNodes_(cellNodes), cellDofs_(cellDofs), cellIds_(cellIds) {
36 // Get parameters from parameter list
37 a_ = parlist.sublist("Problem").get("Desired Lower Doping Value", 0.3);
38 b_ = parlist.sublist("Problem").get("Desired Upper Doping Value", 1.0);
39 wx_ = parlist.sublist("Geometry").get("Width",0.6);
40 wy_ = parlist.sublist("Geometry").get("Height",0.2);
41 }
42
43 Real evaluate(const std::vector<Real> &x) const {
44 Real zero(0), dx(wx_/6.0), dy(wy_/4.0);
45 Real eps = std::sqrt(ROL::ROL_EPSILON<Real>());
46 bool inRegion1 = ((x[0] > zero-eps) && (x[0] < dx+eps) && (x[1] > wy_-dy-eps) && (x[1] < wy_+eps));
47 bool inRegion2 = ((x[0] > wx_-dx-eps) && (x[0] < wx_+eps) && (x[1] > wy_-dy-eps) && (x[1] < wy_+eps));
48 return (inRegion1 || inRegion2 ? b_ : a_);
49 }
50
51 void build(const ROL::Ptr<Tpetra::MultiVector<> > &dpVec) const {
52 int c = fe_->gradN()->dimension(0);
53 int f = fe_->gradN()->dimension(1);
54 int d = fe_->gradN()->dimension(3);
55 ROL::Ptr<Intrepid::FieldContainer<Real> > dofPoints =
56 ROL::makePtr<Intrepid::FieldContainer<Real>>(c,f,d);
57 fe_->computeDofCoords(dofPoints, cellNodes_);
58
59 std::vector<Real> coord(d);
60 for (int i = 0; i < c; ++i) {
61 for (int j = 0; j < f; ++j) {
62 int fidx = (*cellDofs_)(cellIds_[i],j);
63 if (dpVec->getMap()->isNodeGlobalElement(fidx)) {
64 for (int k = 0; k < d; ++k) {
65 coord[k] = (*dofPoints)(i,j,k);
66 }
67 dpVec->replaceGlobalValue(fidx,
68 0,
69 evaluate(coord));
70 }
71 }
72 }
73 }
74 };
75
76 template <class Real>
77 class DopingBounds {
78 private:
79 typedef Tpetra::Map<>::global_ordinal_type GO;
80
81 const ROL::Ptr<FE<Real> > fe_;
82 const ROL::Ptr<Intrepid::FieldContainer<Real> > cellNodes_;
83 const ROL::Ptr<Intrepid::FieldContainer<int> > cellDofs_;
84 const Teuchos::Array<GO> cellIds_;
85 Real a_, b_, wx_, wy_, lo_, hi_;
86 bool useConstant_;
87
88 public:
89 DopingBounds(const ROL::Ptr<FE<Real> > &fe,
90 const ROL::Ptr<Intrepid::FieldContainer<Real> > & cellNodes,
91 const ROL::Ptr<Intrepid::FieldContainer<int> > & cellDofs,
92 const Teuchos::Array<GO> & cellIds,
93 Teuchos::ParameterList &parlist)
94 : fe_(fe), cellNodes_(cellNodes), cellDofs_(cellDofs), cellIds_(cellIds) {
95 // Get parameters from parameter list
96 a_ = parlist.sublist("Problem").get("Desired Lower Doping Value", 0.3);
97 b_ = parlist.sublist("Problem").get("Desired Upper Doping Value", 1.0);
98 wx_ = parlist.sublist("Geometry").get("Width",0.6);
99 wy_ = parlist.sublist("Geometry").get("Height",0.2);
100 lo_ = parlist.sublist("Problem").get("Lower Bound Value", 0.0);
101 hi_ = parlist.sublist("Problem").get("Upper Bound Value", 10.0);
102 useConstant_ = parlist.sublist("Problem").get("Use Constant Bounds",true);
103 }
104
105 Real evaluateLower(const std::vector<Real> &x) const {
106 if (!useConstant_) {
107 const Real zero(0), two(2), four(4), dx(wx_/6.0);
108 const Real eps = std::sqrt(ROL::ROL_EPSILON<Real>());
109 const bool inRegion1 = ((x[0] > zero-eps) && (x[0] < dx+eps) && (x[1] > wy_-eps) && (x[1] < wy_+eps));
110 const bool inRegion2 = ((x[0] > two*dx-eps) && (x[0] < four*dx+eps) && (x[1] > wy_-eps) && (x[1] < wy_+eps));
111 const bool inRegion3 = ((x[0] > wx_-dx-eps) && (x[0] < wx_+eps) && (x[1] > wy_-eps) && (x[1] < wy_+eps));
112 return (inRegion1 || inRegion3 ? b_ : (inRegion2 ? a_ : lo_));
113 }
114 return lo_;
115 }
116
117 Real evaluateUpper(const std::vector<Real> &x) const {
118 if (!useConstant_) {
119 const Real zero(0), two(2), four(4), dx(wx_/6.0);
120 const Real eps = std::sqrt(ROL::ROL_EPSILON<Real>());
121 const bool inRegion1 = ((x[0] > zero-eps) && (x[0] < dx+eps) && (x[1] > wy_-eps) && (x[1] < wy_+eps));
122 const bool inRegion2 = ((x[0] > two*dx-eps) && (x[0] < four*dx+eps) && (x[1] > wy_-eps) && (x[1] < wy_+eps));
123 const bool inRegion3 = ((x[0] > wx_-dx-eps) && (x[0] < wx_+eps) && (x[1] > wy_-eps) && (x[1] < wy_+eps));
124 return (inRegion1 || inRegion3 ? b_ : (inRegion2 ? a_ : hi_));
125 }
126 return hi_;
127 }
128
129 void build(const ROL::Ptr<Tpetra::MultiVector<> > &loVec,
130 const ROL::Ptr<Tpetra::MultiVector<> > &hiVec) const {
131 int c = fe_->gradN()->dimension(0);
132 int f = fe_->gradN()->dimension(1);
133 int d = fe_->gradN()->dimension(3);
134 ROL::Ptr<Intrepid::FieldContainer<Real> > dofPoints =
135 ROL::makePtr<Intrepid::FieldContainer<Real>>(c,f,d);
136 fe_->computeDofCoords(dofPoints, cellNodes_);
137
138 std::vector<Real> coord(d);
139 for (int i = 0; i < c; ++i) {
140 for (int j = 0; j < f; ++j) {
141 int fidx = (*cellDofs_)(cellIds_[i],j);
142 if (loVec->getMap()->isNodeGlobalElement(fidx)) {
143 for (int k = 0; k < d; ++k) {
144 coord[k] = (*dofPoints)(i,j,k);
145 }
146 loVec->replaceGlobalValue(fidx,
147 0,
148 evaluateLower(coord));
149 }
150 if (hiVec->getMap()->isNodeGlobalElement(fidx)) {
151 for (int k = 0; k < d; ++k) {
152 coord[k] = (*dofPoints)(i,j,k);
153 }
154 hiVec->replaceGlobalValue(fidx,
155 0,
156 evaluateUpper(coord));
157 }
158 }
159 }
160 }
161 };
162
163 #endif