GRINS-0.6.0
velocity_penalty_base.C
Go to the documentation of this file.
1 //-----------------------------------------------------------------------bl-
2 //--------------------------------------------------------------------------
3 //
4 // GRINS - General Reacting Incompressible Navier-Stokes
5 //
6 // Copyright (C) 2014-2015 Paul T. Bauman, Roy H. Stogner
7 // Copyright (C) 2010-2013 The PECOS Development Team
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the Version 2.1 GNU Lesser General
11 // Public License as published by the Free Software Foundation.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc. 51 Franklin Street, Fifth Floor,
21 // Boston, MA 02110-1301 USA
22 //
23 //-----------------------------------------------------------------------el-
24 
25 
26 // This class
28 
29 // GRINS
31 
32 // libMesh
33 #include "libmesh/parsed_function.h"
34 #include "libmesh/zero_function.h"
35 
36 namespace GRINS
37 {
38 
39  template<class Mu>
40  VelocityPenaltyBase<Mu>::VelocityPenaltyBase( const std::string& physics_name, const GetPot& input )
41  : IncompressibleNavierStokesBase<Mu>(physics_name,
42  incompressible_navier_stokes, /* "core" Physics name */
43  input),
44  _quadratic_scaling(false)
45  {
46  this->read_input_options(input);
47 
48  return;
49  }
50 
51  template<class Mu>
53  {
54  return;
55  }
56 
57  template<class Mu>
58  void VelocityPenaltyBase<Mu>::read_input_options( const GetPot& input )
59  {
60  std::string base_physics_name = "VelocityPenalty";
61  if (this->_physics_name == velocity_penalty2 ||
62  this->_physics_name == velocity_penalty2_adjoint_stab)
63  base_physics_name.push_back('2');
64 
65  if (this->_physics_name == velocity_penalty3 ||
66  this->_physics_name == velocity_penalty3_adjoint_stab)
67  base_physics_name.push_back('3');
68 
69  std::string penalty_function =
70  input("Physics/"+base_physics_name+"/penalty_function",
71  std::string("0"));
72 
73  if (penalty_function == "0")
74  this->normal_vector_function.reset
75  (new libMesh::ZeroFunction<libMesh::Number>());
76  else
77  this->normal_vector_function.reset
78  (new libMesh::ParsedFunction<libMesh::Number>(penalty_function));
79 
80  std::string base_function =
81  input("Physics/"+base_physics_name+"/base_velocity",
82  std::string("0"));
83 
84  if (penalty_function == "0" && base_function == "0")
85  std::cout << "Warning! Zero VelocityPenalty specified!" << std::endl;
86 
87  if (base_function == "0")
88  this->base_velocity_function.reset
89  (new libMesh::ZeroFunction<libMesh::Number>());
90  else
91  this->base_velocity_function.reset
92  (new libMesh::ParsedFunction<libMesh::Number>(base_function));
93 
94  _quadratic_scaling =
95  input("Physics/"+base_physics_name+"/quadratic_scaling", false);
96  }
97 
98  template<class Mu>
100  ( const libMesh::Point& point,
101  const libMesh::Real time,
102  const libMesh::NumberVectorValue& U,
103  libMesh::NumberVectorValue& F,
104  libMesh::NumberTensorValue *dFdU)
105  {
106  // Velocity discrepancy (current velocity minus base velocity)
107  // normal to constraint plane, scaled by constraint penalty
108  // value
109  libmesh_assert(normal_vector_function.get());
110  libmesh_assert(base_velocity_function.get());
111 
112  libMesh::DenseVector<libMesh::Number> output_vec(3);
113 
114  (*normal_vector_function)(point, time,
115  output_vec);
116 
117  libMesh::NumberVectorValue U_N(output_vec(0),
118  output_vec(1),
119  output_vec(2));
120 
121  (*base_velocity_function)(point, time,
122  output_vec);
123 
124  const libMesh::NumberVectorValue U_B(output_vec(0),
125  output_vec(1),
126  output_vec(2));
127 
128  const libMesh::NumberVectorValue U_Rel = U-U_B;
129 
130  // Old code
131  // const libMesh::NumberVectorValue F1 = (U_Rel*U_N)*U_N; //
132 
133  // With correct sign and more natural normalization
134  const libMesh::Number U_N_mag = std::sqrt(U_N*U_N);
135 
136  if (!U_N_mag)
137  return false;
138 
139  const libMesh::NumberVectorValue U_N_unit = U_N/U_N_mag;
140 
141  F = -(U_Rel*U_N)*U_N_unit;
142 
143  if (dFdU)
144  for (unsigned int i=0; i != 3; ++i)
145  for (unsigned int j=0; j != 3; ++j)
146  (*dFdU)(i,j) = -(U_N(j))*U_N_unit(i);
147 
148  // With quadratic scaling
149  if (_quadratic_scaling)
150  {
151  const libMesh::Number U_Rel_mag = std::sqrt(U_Rel * U_Rel);
152 
153  // Modify dFdU first so as to reuse the old value of F
154  if (dFdU)
155  {
156  // dU_Rel/dU = I
157  // d(U_Rel*U_Rel)/dU = 2*U_Rel
158  // d|U_Rel|/dU = U_Rel/|U_Rel|
159 
160  const libMesh::NumberVectorValue U_Rel_unit = U_Rel/U_Rel_mag;
161 
162  (*dFdU) *= U_Rel_mag;
163 
164  if (U_Rel_mag)
165  for (unsigned int i=0; i != 3; ++i)
166  for (unsigned int j=0; j != 3; ++j)
167  (*dFdU)(i,j) += F(i)*U_Rel_unit(j);
168  }
169 
170  F *= U_Rel_mag;
171  }
172 
173  // With correction term to avoid doing work on flow
174  bool do_correction = false;
175  if (do_correction)
176  {
177  if (dFdU)
178  libmesh_not_implemented();
179 
180  const libMesh::Number U_Rel_mag_sq = U_Rel * U_Rel;
181  if (U_Rel_mag_sq)
182  {
183  F -= (U_Rel*F)*U_Rel/U_Rel_mag_sq;
184  }
185  }
186  return true;
187  }
188 
189 } // namespace GRINS
190 
191 // Instantiate
192 INSTANTIATE_INC_NS_SUBCLASS(VelocityPenaltyBase);
const PhysicsName incompressible_navier_stokes
Physics class for Incompressible Navier-Stokes.
GRINS namespace.
const PhysicsName velocity_penalty2_adjoint_stab
INSTANTIATE_INC_NS_SUBCLASS(VelocityPenaltyBase)
const PhysicsName velocity_penalty3
const PhysicsName velocity_penalty2
virtual void read_input_options(const GetPot &input)
Read options from GetPot input file.
const PhysicsName velocity_penalty3_adjoint_stab
bool compute_force(const libMesh::Point &point, const libMesh::Real time, const libMesh::NumberVectorValue &U, libMesh::NumberVectorValue &F, libMesh::NumberTensorValue *dFdU=NULL)

Generated on Mon Jun 22 2015 21:32:20 for GRINS-0.6.0 by  doxygen 1.8.9.1