GRINS-0.6.0
vorticity.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
27 #include "grins/vorticity.h"
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 #include "libmesh/fe_base.h"
38 
39 namespace GRINS
40 {
41  Vorticity::Vorticity( const std::string& qoi_name )
42  : QoIBase(qoi_name)
43  {
44  return;
45  }
46 
48  {
49  return;
50  }
51 
53  {
54  return new Vorticity( *this );
55  }
56 
57  void Vorticity::init( const GetPot& input, const MultiphysicsSystem& system )
58  {
59  // Extract subdomain on which to compute to qoi
60  int num_ids = input.vector_variable_size( "QoI/Vorticity/enabled_subdomains" );
61 
62  if( num_ids == 0 )
63  {
64  std::cerr << "Error: Must specify at least one subdomain id on which to compute vorticity." << std::endl;
65  libmesh_error();
66  }
67 
68  for( int i = 0; i < num_ids; i++ )
69  {
70  libMesh::subdomain_id_type s_id = input( "QoI/Vorticity/enabled_subdomains", -1, i );
71  _subdomain_ids.insert( s_id );
72  }
73 
74  // Grab velocity variable indices
75  std::string u_var_name = input("Physics/VariableNames/u_velocity", u_var_name_default);
76  std::string v_var_name = input("Physics/VariableNames/v_velocity", v_var_name_default);
77  this->_u_var = system.variable_number(u_var_name);
78  this->_v_var = system.variable_number(v_var_name);
79 
80  return;
81  }
82 
84  {
85  libMesh::FEBase* u_fe = NULL;
86  libMesh::FEBase* v_fe = NULL;
87 
88  context.get_element_fe<libMesh::Real>(this->_u_var, u_fe);
89  context.get_element_fe<libMesh::Real>(this->_v_var, v_fe);
90 
91  u_fe->get_dphi();
92  u_fe->get_JxW();
93 
94  v_fe->get_dphi();
95 
96  return;
97  }
98 
100  const unsigned int qoi_index )
101  {
102 
103  if( _subdomain_ids.find( (&context.get_elem())->subdomain_id() ) != _subdomain_ids.end() )
104  {
105  libMesh::FEBase* element_fe;
106  context.get_element_fe<libMesh::Real>(this->_u_var, element_fe);
107  const std::vector<libMesh::Real> &JxW = element_fe->get_JxW();
108 
109  unsigned int n_qpoints = context.get_element_qrule().n_points();
110 
112  libMesh::Number& qoi = context.get_qois()[qoi_index];
113 
114  for( unsigned int qp = 0; qp != n_qpoints; qp++ )
115  {
116  libMesh::Gradient grad_u = 0.;
117  libMesh::Gradient grad_v = 0.;
118  context.interior_gradient( this->_u_var, qp, grad_u );
119  context.interior_gradient( this->_v_var, qp, grad_v );
120  qoi += (grad_v(0) - grad_u(1)) * JxW[qp];
121  }
122  }
123 
124  return;
125  }
126 
128  const unsigned int qoi_index )
129  {
130 
131  if( _subdomain_ids.find( (&context.get_elem())->subdomain_id() ) != _subdomain_ids.end() )
132  {
133  // Element
134  libMesh::FEBase* element_fe;
135  context.get_element_fe<libMesh::Real>(this->_u_var, element_fe);
136 
137  // Jacobian times integration weights
138  const std::vector<libMesh::Real> &JxW = element_fe->get_JxW();
139 
140  // Grad of basis functions
141  const std::vector<std::vector<libMesh::RealGradient> >& du_phi =
142  context.get_element_fe(_u_var)->get_dphi();
143  const std::vector<std::vector<libMesh::RealGradient> >& dv_phi =
144  context.get_element_fe(_v_var)->get_dphi();
145 
146  // Local DOF count and quadrature point count
147  const unsigned int n_T_dofs = context.get_dof_indices(0).size();
148  unsigned int n_qpoints = context.get_element_qrule().n_points();
149 
150  // Warning: we assume here that vorticity is the only QoI!
151  // This should be consistent with the assertion in grins_mesh_adaptive_solver.C
153  libMesh::DenseSubVector<libMesh::Number> &Qu = context.get_qoi_derivatives(qoi_index, _u_var);
154  libMesh::DenseSubVector<libMesh::Number> &Qv = context.get_qoi_derivatives(qoi_index, _v_var);
155 
156  // Integration loop
157  for( unsigned int qp = 0; qp != n_qpoints; qp++ )
158  {
159  for( unsigned int i = 0; i != n_T_dofs; i++ )
160  {
161  Qu(i) += - dv_phi[i][qp](1) * JxW[qp];
162  Qv(i) += du_phi[i][qp](0) * JxW[qp];
163  }
164  }
165  }
166 
167  return;
168  }
169 
170 } //namespace GRINS
Vorticity()
User never call default constructor.
virtual ~Vorticity()
Definition: vorticity.C:47
virtual QoIBase * clone() const
Required to provide clone (deep-copy) for adding QoI object to libMesh objects.
Definition: vorticity.C:52
virtual void init_context(AssemblyContext &context)
Definition: vorticity.C:83
std::set< libMesh::subdomain_id_type > _subdomain_ids
List of sumdomain ids for which we want to compute this QoI.
Definition: vorticity.h:89
const std::string v_var_name_default
y-velocity
GRINS namespace.
const std::string u_var_name_default
Default physics variable names.
virtual void element_qoi(AssemblyContext &context, const unsigned int qoi_index)
Compute the qoi value.
Definition: vorticity.C:99
Interface with libMesh for solving Multiphysics problems.
virtual void init(const GetPot &input, const MultiphysicsSystem &system)
Initialize local variables.
Definition: vorticity.C:57
virtual void element_qoi_derivative(AssemblyContext &context, const unsigned int qoi_index)
Compute the qoi derivative with respect to the solution.
Definition: vorticity.C:127
VariableIndex _v_var
v-velocity component variable index
Definition: vorticity.h:86
VariableIndex _u_var
u-velocity component variable index
Definition: vorticity.h:83

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