GRINS-0.6.0
parsed_interior_qoi.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 #include "libmesh/fe_base.h"
38 #include "libmesh/parsed_fem_function.h"
39 
40 namespace GRINS
41 {
42  ParsedInteriorQoI::ParsedInteriorQoI( const std::string& qoi_name )
43  : QoIBase(qoi_name) {}
44 
46  : QoIBase(original.name())
47  {
48  if (original.qoi_functional.get())
49  this->qoi_functional = original.qoi_functional->clone();
50  }
51 
53 
55  {
56  return new ParsedInteriorQoI( *this );
57  }
58 
59  void ParsedInteriorQoI::init( const GetPot& input, const MultiphysicsSystem& system )
60  {
61  std::string qoi_functional_string =
62  input("QoI/ParsedInterior/qoi_functional", std::string("0"));
63 
64  if (qoi_functional_string == "0")
65  libmesh_error_msg("Error! Zero ParsedInteriorQoI specified!" <<
66  std::endl);
67 
68  this->qoi_functional.reset
69  (new libMesh::ParsedFEMFunction<libMesh::Number>
70  (system, qoi_functional_string));
71  }
72 
74  {
75  libMesh::FEBase* element_fe;
76  context.get_element_fe<libMesh::Real>(0, element_fe);
77  element_fe->get_JxW();
78  element_fe->get_xyz();
79 
80  qoi_functional->init_context(context);
81  }
82 
84  const unsigned int qoi_index )
85  {
86  libMesh::FEBase* element_fe;
87  context.get_element_fe<libMesh::Real>(0, element_fe);
88  const std::vector<libMesh::Real> &JxW = element_fe->get_JxW();
89 
90  const std::vector<libMesh::Point>& x_qp = element_fe->get_xyz();
91 
92  unsigned int n_qpoints = context.get_element_qrule().n_points();
93 
95  libMesh::Number& qoi = context.get_qois()[qoi_index];
96 
97  for( unsigned int qp = 0; qp != n_qpoints; qp++ )
98  {
99  const libMesh::Number func_val =
100  (*qoi_functional)(context, x_qp[qp], context.get_time());
101 
102  qoi += func_val * JxW[qp];
103  }
104  }
105 
107  const unsigned int qoi_index )
108  {
109  libMesh::FEBase* element_fe;
110  context.get_element_fe<libMesh::Real>(0, element_fe);
111  const std::vector<libMesh::Real> &JxW = element_fe->get_JxW();
112 
113  const std::vector<libMesh::Point>& x_qp = element_fe->get_xyz();
114 
115  // Local DOF count and quadrature point count
116  const unsigned int n_u_dofs = context.get_dof_indices().size();
117 
118  unsigned int n_qpoints = context.get_element_qrule().n_points();
119 
120  // Local solution vector - non-const version for finite
121  // differenting purposes
122  libMesh::DenseVector<libMesh::Number>& elem_solution =
123  const_cast<libMesh::DenseVector<libMesh::Number>&>
124  (context.get_elem_solution());
125 
127  libMesh::DenseVector<libMesh::Number> &Qu =
128  context.get_qoi_derivatives()[qoi_index];
129 
130  for( unsigned int qp = 0; qp != n_qpoints; qp++ )
131  {
132  // Central finite differencing to approximate derivatives.
133  // FIXME - we should hook the FParserAD stuff into
134  // ParsedFEMFunction
135 
136  for( unsigned int i = 0; i != n_u_dofs; ++i )
137  {
138  libMesh::Number &current_solution = elem_solution(i);
139  const libMesh::Number original_solution = current_solution;
140 
141  current_solution = original_solution + libMesh::TOLERANCE;
142 
143  const libMesh::Number plus_val =
144  (*qoi_functional)(context, x_qp[qp], context.get_time());
145 
146  current_solution = original_solution - libMesh::TOLERANCE;
147 
148  const libMesh::Number minus_val =
149  (*qoi_functional)(context, x_qp[qp], context.get_time());
150 
151  Qu(i) += (plus_val - minus_val) *
152  (0.5 / libMesh::TOLERANCE) * JxW[qp];
153 
154  // Don't forget to restore the correct solution...
155  current_solution = original_solution;
156  }
157  }
158  }
159 
160 } //namespace GRINS
ParsedInteriorQoI()
User never call default constructor.
GRINS namespace.
Parsed Interior QoI.
Interface with libMesh for solving Multiphysics problems.
virtual void element_qoi(AssemblyContext &context, const unsigned int qoi_index)
Compute the qoi value.
virtual void init(const GetPot &input, const MultiphysicsSystem &system)
Initialize local variables.
virtual void element_qoi_derivative(AssemblyContext &context, const unsigned int qoi_index)
Compute the qoi derivative with respect to the solution.
virtual void init_context(AssemblyContext &context)
libMesh::AutoPtr< libMesh::FEMFunctionBase< libMesh::Number > > qoi_functional
virtual QoIBase * clone() const
Required to provide clone (deep-copy) for adding QoI object to libMesh objects.

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