Debian Codegraph @

packages/rol/example/PDE-OPT/flow-opt/3dim/models/darcy/permeability.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 PERMEABILITY_HPP
11 #define PERMEABILITY_HPP
12
13 #include <vector>
14 #include "ROL_ParameterList.hpp"
15 #include "ROL_Ptr.hpp"
16 #include "Intrepid_FieldContainer.hpp"
17
18 template<class Real>
19 class Permeability {
20 private:
21 Real dRadius_, viscosity_, minPerm_, maxPerm_;
22 int type_;
23
24 Real value(const Real z) const {
25 if (type_==1) {
26 const Real a(minPerm_/viscosity_), b(std::log(maxPerm_/minPerm_));
27 return a * std::exp(b * z);
28 }
29 else {
30 const Real a(minPerm_/viscosity_), b(maxPerm_/viscosity_);
31 return a + z * (b - a);
32 }
33 }
34
35 Real deriv1(const Real z) const {
36 if (type_==1) {
37 const Real a(minPerm_/viscosity_), b(std::log(maxPerm_/minPerm_));
38 return a * b * std::exp(b * z);
39 }
40 else {
41 const Real a(minPerm_/viscosity_), b(maxPerm_/viscosity_);
42 return b - a;
43 }
44 }
45
46 Real deriv2(const Real z) const {
47 if (type_==1) {
48 const Real a(minPerm_/viscosity_), b(std::log(maxPerm_/minPerm_));
49 return a * b * b * std::exp(b * z);
50 }
51 else {
52 return static_cast<Real>(0);
53 }
54 }
55
56 public:
57 Permeability(ROL::ParameterList &list) {
58 bool useDarcy = list.sublist("Problem").get("Use Darcy Flow",true);
59 dRadius_ = list.sublist("Problem").get("Diffuser Radius",5.0); // mm
60 viscosity_ = list.sublist("Problem").get("Dynamic Viscosity", 0.84e-8); // kg/mm-s
61 minPerm_ = list.sublist("Problem").get("Minimum Permeability", 3e-7); // mm^2
62 maxPerm_ = list.sublist("Problem").get("Maximum Permeability", 3e-6); // mm^2
63 if (useDarcy) dRadius_ += static_cast<Real>(10);
64 type_ = list.sublist("Problem").get("Parametrization Type", 0);
65 // type_ = 0 ... K = z kmin + (1-z) kmax
66 // type_ = 1 ... K = exp((1-z) log(kmin) + z log(kmax))
67 }
68
69 void compute(ROL::Ptr<Intrepid::FieldContainer<Real>> &alpha,
70 const ROL::Ptr<Intrepid::FieldContainer<Real>> &z,
71 const ROL::Ptr<const Intrepid::FieldContainer<Real>> &pts,
72 const int deriv=0) const {
73 const Real tol = std::sqrt(ROL::ROL_EPSILON<Real>());
74 const Real zero(0), one(1);
75 const int c = pts->dimension(0);
76 const int p = pts->dimension(1);
77 const int d = pts->dimension(2);
78 Real weight(0), norm(0);
79 for (int i = 0; i < c; ++i) {
80 for (int j = 0; j < p; ++j) {
81 norm = zero;
82 for (int k = 0; k < d; ++k) norm += (*pts)(i,j,k)*(*pts)(i,j,k);
83 weight = (std::sqrt(norm) <= dRadius_ + tol ? one : zero);
84 // Compute spatially dependent viscosity
85 if (deriv==1) (*alpha)(i,j) = weight * deriv1((*z)(i,j));
86 else if (deriv==2) (*alpha)(i,j) = weight * deriv2((*z)(i,j));
87 else (*alpha)(i,j) = weight * value((*z)(i,j));
88 }
89 }
90 }
91 };
92
93 #endif