Debian Codegraph @

packages/rol/example/PDE-OPT/dynamic/thermal-fluids/initial_condition.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 THERMALFLUIDS_POTENTIALFLOW_HPP
11 #define THERMALFLUIDS_POTENTIALFLOW_HPP
12
13 #include "../../TOOLS/fe.hpp"
14 #include "../../TOOLS/fieldhelper.hpp"
15 #include "Tpetra_MultiVector.hpp"
16 #include "ROL_ParameterList.hpp"
17 #include "ROL_Ptr.hpp"
18
19 template <class Real>
20 class PotentialFlow {
21 private:
22 typedef Tpetra::Map<>::global_ordinal_type GO;
23
24 const ROL::Ptr<FE<Real>> feVel_, fePrs_, feThr_;
25 const ROL::Ptr<Intrepid::FieldContainer<Real>> cellNodes_;
26 const ROL::Ptr<Intrepid::FieldContainer<int>> cellDofs_;
27 const Teuchos::Array<GO> cellIds_;
28 const ROL::Ptr<FieldHelper<Real>> fieldHelper_;
29 Real cx_, cy_, r_;
30
31 public:
32 PotentialFlow(const ROL::Ptr<FE<Real>> &feVel,
33 const ROL::Ptr<FE<Real>> &fePrs,
34 const ROL::Ptr<FE<Real>> &feThr,
35 const ROL::Ptr<Intrepid::FieldContainer<Real>> &cellNodes,
36 const ROL::Ptr<Intrepid::FieldContainer<int>> &cellDofs,
37 const Teuchos::Array<GO> &cellIds,
38 const ROL::Ptr<FieldHelper<Real>> &fieldHelper,
39 ROL::ParameterList &parlist)
40 : feVel_(feVel), fePrs_(fePrs), feThr_(feThr),
41 cellNodes_(cellNodes), cellDofs_(cellDofs), cellIds_(cellIds),
42 fieldHelper_(fieldHelper) {
43 // Get parameters from parameter list
44 cx_ = parlist.sublist("Problem").get("Cylinder Center X", 0.0);
45 cy_ = parlist.sublist("Problem").get("Cylinder Center Y", 0.0);
46 r_ = parlist.sublist("Problem").get("Cylinder Radius", 0.5);
47 }
48
49 Real evalVelocity(const std::vector<Real> &x, const int dir) const {
50 const Real one(1);
51 Real px = x[0] - cx_;
52 Real py = x[1] - cy_;
53 Real rad = std::sqrt(std::pow(px,2) + std::pow(py,2));
54 Real arg = std::atan2(py,px);
55 Real rdt = (one - std::pow(r_/rad,2))*std::cos(arg);
56 Real adt = -(one + std::pow(r_/rad,2))*std::sin(arg);
57 return (dir == 0 ? rdt*std::cos(arg) - adt*std::sin(arg)
58 : rdt*std::sin(arg) + adt*std::cos(arg));
59 }
60
61 Real evalPressure(const std::vector<Real> &x) const {
62 const Real half(0.5), one(1);
63 Real vx = evalVelocity(x,0);
64 Real vy = evalVelocity(x,1);
65 return half*(one-(std::pow(vx,2)+std::pow(vy,2)));
66 }
67
68 Real evalThermal(const std::vector<Real> &x) const {
69 return static_cast<Real>(0);
70 }
71
72 void build(const ROL::Ptr<Tpetra::MultiVector<>> &vec) const {
73 const int c = feVel_->gradN()->dimension(0);
74 const int fv = feVel_->gradN()->dimension(1);
75 const int fp = fePrs_->gradN()->dimension(1);
76 const int fh = feThr_->gradN()->dimension(1);
77 const int d = feVel_->gradN()->dimension(3);
78 // Grab DOF coordinates
79 ROL::Ptr<Intrepid::FieldContainer<Real>> dofPointsVel, dofPointsPrs, dofPointsThr, u;
80 dofPointsVel = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,fv,d);
81 dofPointsPrs = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,fp,d);
82 dofPointsThr = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,fh,d);
83 feVel_->computeDofCoords(dofPointsVel, cellNodes_);
84 fePrs_->computeDofCoords(dofPointsPrs, cellNodes_);
85 feThr_->computeDofCoords(dofPointsThr, cellNodes_);
86 // Initialize velocity and pressure vectors
87 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> U(d+2);
88 for (int i = 0; i < d; ++i) {
89 U[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,fv);
90 }
91 U[d] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,fp);
92 U[d+1] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,fh);
93 // Evaluate velocity and pressure
94 std::vector<Real> coord(d);
95 for (int i = 0; i < c; ++i) {
96 for (int j = 0; j < fv; ++j) {
97 for (int k = 0; k < d; ++k) {
98 coord[k] = (*dofPointsVel)(i,j,k);
99 }
100 for (int k = 0; k < d; ++k) {
101 (*U[k])(i,j) = evalVelocity(coord,k);
102 }
103 }
104 for (int j = 0; j < fp; ++j) {
105 for (int k = 0; k < d; ++k) {
106 coord[k] = (*dofPointsPrs)(i,j,k);
107 }
108 (*U[d])(i,j) = evalPressure(coord);
109 }
110 for (int j = 0; j < fh; ++j) {
111 for (int k = 0; k < d; ++k) {
112 coord[k] = (*dofPointsThr)(i,j,k);
113 }
114 (*U[d+1])(i,j) = evalThermal(coord);
115 }
116 }
117 // Combine velocity and pressure into a single vector
118 fieldHelper_->combineFieldCoeff(u,U);
119 // Add velocity and pressure values to input vector
120 int numDofs = u->dimension(1);
121 for (int i = 0; i < c; ++i) {
122 for (int j = 0; j < numDofs; ++j) {
123 vec->replaceGlobalValue((*cellDofs_)(cellIds_[i],j),0,(*u)(i,j));
124 }
125 }
126 }
127 };
128
129 #endif