Debian Codegraph @

packages/rol/example/PDE-OPT/dynamic/navier-stokes/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 POTENTIALFLOW_HPP
11 #define 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_;
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<Intrepid::FieldContainer<Real>> &cellNodes,
35 const ROL::Ptr<Intrepid::FieldContainer<int>> &cellDofs,
36 const Teuchos::Array<GO> &cellIds,
37 const ROL::Ptr<FieldHelper<Real>> &fieldHelper,
38 ROL::ParameterList &parlist)
39 : feVel_(feVel), fePrs_(fePrs),
40 cellNodes_(cellNodes), cellDofs_(cellDofs), cellIds_(cellIds),
41 fieldHelper_(fieldHelper) {
42 // Get parameters from parameter list
43 cx_ = parlist.sublist("Problem").get("Cylinder Center X", 0.0);
44 cy_ = parlist.sublist("Problem").get("Cylinder Center Y", 0.0);
45 r_ = parlist.sublist("Problem").get("Cylinder Radius", 0.5);
46 }
47
48 Real evalVelocity(const std::vector<Real> &x, const int dir) const {
49 const Real one(1);
50 Real px = x[0] - cx_;
51 Real py = x[1] - cy_;
52 Real rad = std::sqrt(std::pow(px,2) + std::pow(py,2));
53 Real arg = std::atan2(py,px);
54 Real rdt = (one - std::pow(r_/rad,2))*std::cos(arg);
55 Real adt = -(one + std::pow(r_/rad,2))*std::sin(arg);
56 return (dir == 0 ? rdt*std::cos(arg) - adt*std::sin(arg)
57 : rdt*std::sin(arg) + adt*std::cos(arg));
58 }
59
60 Real evalPressure(const std::vector<Real> &x) const {
61 const Real half(0.5), one(1);
62 Real vx = evalVelocity(x,0);
63 Real vy = evalVelocity(x,1);
64 return half*(one-(std::pow(vx,2)+std::pow(vy,2)));
65 }
66
67 void build(const ROL::Ptr<Tpetra::MultiVector<>> &vec) const {
68 const int c = feVel_->gradN()->dimension(0);
69 const int fv = feVel_->gradN()->dimension(1);
70 const int fp = fePrs_->gradN()->dimension(1);
71 const int d = feVel_->gradN()->dimension(3);
72 // Grab DOF coordinates
73 ROL::Ptr<Intrepid::FieldContainer<Real>> dofPointsVel, dofPointsPrs, u;
74 dofPointsVel = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,fv,d);
75 dofPointsPrs = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,fp,d);
76 feVel_->computeDofCoords(dofPointsVel, cellNodes_);
77 fePrs_->computeDofCoords(dofPointsPrs, cellNodes_);
78 // Initialize velocity and pressure vectors
79 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> U(d+1);
80 for (int i = 0; i < d; ++i) {
81 U[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,fv);
82 }
83 U[d] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,fp);
84 // Evaluate velocity and pressure
85 std::vector<Real> coord(d);
86 for (int i = 0; i < c; ++i) {
87 for (int j = 0; j < fv; ++j) {
88 for (int k = 0; k < d; ++k) {
89 coord[k] = (*dofPointsVel)(i,j,k);
90 }
91 for (int k = 0; k < d; ++k) {
92 (*U[k])(i,j) = evalVelocity(coord,k);
93 }
94 }
95 for (int j = 0; j < fp; ++j) {
96 for (int k = 0; k < d; ++k) {
97 coord[k] = (*dofPointsPrs)(i,j,k);
98 }
99 (*U[d])(i,j) = evalPressure(coord);
100 }
101 }
102 // Combine velocity and pressure into a single vector
103 fieldHelper_->combineFieldCoeff(u,U);
104 // Add velocity and pressure values to input vector
105 int numDofs = u->dimension(1);
106 for (int i = 0; i < c; ++i) {
107 for (int j = 0; j < numDofs; ++j) {
108 vec->replaceGlobalValue((*cellDofs_)(cellIds_[i],j),0,(*u)(i,j));
109 }
110 }
111 }
112 };
113
114 #endif