GRINS-0.6.0
average_nusselt_number.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
30 #include "grins/multiphysics_sys.h"
31 #include "grins/assembly_context.h"
32 
33 // libMesh
34 #include "libmesh/getpot.h"
35 #include "libmesh/fem_system.h"
36 #include "libmesh/quadrature.h"
37 
38 namespace GRINS
39 {
40  AverageNusseltNumber::AverageNusseltNumber( const std::string& qoi_name )
41  : QoIBase(qoi_name)
42  {
43  return;
44  }
45 
47  {
48  return;
49  }
50 
52  {
53  return new AverageNusseltNumber( *this );
54  }
55 
56  void AverageNusseltNumber::init( const GetPot& input, const MultiphysicsSystem& system )
57  {
58  this->set_parameter
59  ( _k, input, "QoI/NusseltNumber/thermal_conductivity", -1.0 );
60 
61  this->set_parameter
62  ( _scaling, input, "QoI/NusseltNumber/scaling", 1.0 );
63 
64  if( this->_k < 0.0 )
65  {
66  std::cerr << "Error: thermal conductivity for AverageNusseltNumber must be positive." << std::endl
67  << "Found k = " << _k << std::endl;
68  libmesh_error();
69  }
70 
71  // Read boundary ids for which we want to compute
72  int num_bcs = input.vector_variable_size("QoI/NusseltNumber/bc_ids");
73 
74  if( num_bcs <= 0 )
75  {
76  std::cerr << "Error: Must specify at least one boundary id to compute"
77  << " average Nusselt number." << std::endl
78  << "Found: " << num_bcs << std::endl;
79  libmesh_error();
80  }
81 
82  for( int i = 0; i < num_bcs; i++ )
83  {
84  _bc_ids.insert( input("QoI/NusseltNumber/bc_ids", -1, i ) );
85  }
86 
87  // Grab temperature variable index
88  std::string T_var_name = input( "Physics/VariableNames/Temperature",
90 
91  this->_T_var = system.variable_number(T_var_name);
92 
93  return;
94  }
95 
97  {
98  libMesh::FEBase* T_fe;
99 
100  context.get_side_fe<libMesh::Real>(this->_T_var, T_fe);
101 
102  T_fe->get_dphi();
103  T_fe->get_JxW();
104 
105  return;
106  }
107 
109  const unsigned int qoi_index )
110  {
111  bool on_correct_side = false;
112 
113  for (std::set<libMesh::boundary_id_type>::const_iterator id =
114  _bc_ids.begin(); id != _bc_ids.end(); id++ )
115  if( context.has_side_boundary_id( (*id) ) )
116  {
117  on_correct_side = true;
118  break;
119  }
120 
121  if (!on_correct_side)
122  return;
123 
124  libMesh::FEBase* side_fe;
125  context.get_side_fe<libMesh::Real>(this->_T_var, side_fe);
126 
127  const std::vector<libMesh::Real> &JxW = side_fe->get_JxW();
128 
129  const std::vector<libMesh::Point>& normals = side_fe->get_normals();
130 
131  unsigned int n_qpoints = context.get_side_qrule().n_points();
132 
133  libMesh::Number& qoi = context.get_qois()[qoi_index];
134 
135  // Loop over quadrature points
136 
137  for (unsigned int qp = 0; qp != n_qpoints; qp++)
138  {
139  // Get the solution value at the quadrature point
140  libMesh::Gradient grad_T = 0.0;
141  context.side_gradient(this->_T_var, qp, grad_T);
142 
143  // Update the elemental increment dR for each qp
144  qoi += (this->_scaling)*(this->_k)*(grad_T*normals[qp])*JxW[qp];
145 
146  } // quadrature loop
147  }
148 
150  const unsigned int qoi_index )
151  {
152 
153  for( std::set<libMesh::boundary_id_type>::const_iterator id = _bc_ids.begin();
154  id != _bc_ids.end(); id++ )
155  {
156  if( context.has_side_boundary_id( (*id) ) )
157  {
158  libMesh::FEBase* T_side_fe;
159  context.get_side_fe<libMesh::Real>(this->_T_var, T_side_fe);
160 
161  const std::vector<libMesh::Real> &JxW = T_side_fe->get_JxW();
162 
163  const std::vector<libMesh::Point>& normals = T_side_fe->get_normals();
164 
165  unsigned int n_qpoints = context.get_side_qrule().n_points();
166 
167  const unsigned int n_T_dofs = context.get_dof_indices(_T_var).size();
168 
169  const std::vector<std::vector<libMesh::Gradient> >& T_gradphi = T_side_fe->get_dphi();
170 
171  libMesh::DenseSubVector<libMesh::Number>& dQ_dT =
172  context.get_qoi_derivatives(qoi_index, _T_var);
173 
174  // Loop over quadrature points
175  for (unsigned int qp = 0; qp != n_qpoints; qp++)
176  {
177  // Get the solution value at the quadrature point
178  libMesh::Gradient grad_T = 0.0;
179  context.side_gradient(this->_T_var, qp, grad_T);
180 
181  // Update the elemental increment dR for each qp
182  //qoi += (this->_scaling)*(this->_k)*(grad_T*normals[qp])*JxW[qp];
183 
184  for( unsigned int i = 0; i != n_T_dofs; i++ )
185  {
186  dQ_dT(i) += _scaling*_k*T_gradphi[i][qp]*normals[qp]*JxW[qp];
187  }
188 
189  } // quadrature loop
190 
191  } // end check on boundary id
192 
193  }
194 
195  return;
196  }
197 
198 } //namespace GRINS
virtual void set_parameter(libMesh::Number &param_variable, const GetPot &input, const std::string &param_name, libMesh::Number param_default)
Each subclass can simultaneously read a parameter value from.
std::set< libMesh::boundary_id_type > _bc_ids
List of boundary ids for which we want to compute this QoI.
virtual void init_context(AssemblyContext &context)
libMesh::Real _scaling
Scaling constant.
GRINS namespace.
const std::string T_var_name_default
temperature
virtual QoIBase * clone() const
Clone this QoI.
virtual void side_qoi_derivative(AssemblyContext &context, const unsigned int qoi_index)
Compute the qoi derivative with respect to the solution on the domain boundary.
libMesh::Real _k
Thermal conductivity.
virtual void init(const GetPot &input, const MultiphysicsSystem &system)
Method to allow QoI to cache any system information needed for QoI calculation, for example...
virtual void side_qoi(AssemblyContext &context, const unsigned int qoi_index)
Compute the qoi value on the domain boundary.
VariableIndex _T_var
Temperature variable index.
Interface with libMesh for solving Multiphysics problems.

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