GRINS-0.8.0
integrated_function.C
Go to the documentation of this file.
1 //-----------------------------------------------------------------------bl-
2 //--------------------------------------------------------------------------
3 //
4 // GRINS - General Reacting Incompressible Navier-Stokes
5 //
6 // Copyright (C) 2014-2017 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"
33 #include "grins/rayfire_mesh.h"
35 
36 // libMesh
37 #include "libmesh/getpot.h"
38 #include "libmesh/fem_system.h"
39 #include "libmesh/quadrature_gauss.h"
40 #include "libmesh/elem.h"
41 #include "libmesh/fe.h"
42 #include "libmesh/fe_type.h"
43 #include "libmesh/function_base.h"
44 
45 namespace GRINS
46 {
47  template<typename Function>
48  IntegratedFunction<Function>::IntegratedFunction(unsigned int p_level, SharedPtr<Function> f, RayfireMesh * rayfire, const std::string & qoi_name) :
49  QoIBase(qoi_name),
50  _p_level(p_level),
51  _f(f),
52  _rayfire(rayfire)
53  {}
54 
55  template<typename Function>
56  IntegratedFunction<Function>::IntegratedFunction(const GetPot & input, unsigned int p_level, SharedPtr<Function> f, const std::string & input_qoi_string, const std::string & qoi_name) :
57  QoIBase(qoi_name),
58  _p_level(p_level),
59  _f(f)
60  {
61  _rayfire.reset(new RayfireMesh(input,input_qoi_string));
62  }
63 
64  template<typename Function>
66  QoIBase(original),
67  _p_level(original._p_level),
68  _f(original._f)
69  {
70  // call RayfireMesh copy constructor
71  this->_rayfire.reset(new RayfireMesh( *((original._rayfire).get())) );
72  }
73 
74  template<typename Function>
76  {
77  return new IntegratedFunction<Function>( *this );
78  }
79 
80  template<typename Function>
82  (const GetPot & /*input*/,
83  const MultiphysicsSystem & system,
84  unsigned int /*qoi_num*/ )
85  {
86  _rayfire->init(system.get_mesh());
87  }
88 
89  template<typename Function>
91  {
92  _rayfire->reinit(system.get_mesh());
93  }
94 
95  template<typename Function>
97  const unsigned int qoi_index )
98  {
99  const libMesh::Elem & original_elem = context.get_elem();
100  const libMesh::Elem * rayfire_elem = _rayfire->map_to_rayfire_elem(original_elem.id());
101 
102  // rayfire_elem will be NULL if the main_elem
103  // is not in the rayfire
104  if (rayfire_elem)
105  {
106  // create and init the quadrature base on the rayfire elem
107  libMesh::QGauss qbase(rayfire_elem->dim(),libMesh::Order(_p_level));
108  qbase.init(rayfire_elem->type(),libMesh::Order(_p_level));
109 
110  // need the QP coordinates and JxW
111  libMesh::UniquePtr< libMesh::FEGenericBase<libMesh::Real> > fe = libMesh::FEGenericBase<libMesh::Real>::build(rayfire_elem->dim(), libMesh::FEType(libMesh::FIRST, libMesh::LAGRANGE) );
112 
113  fe->attach_quadrature_rule( &qbase );
114  const std::vector<libMesh::Real> & JxW = fe->get_JxW();
115  const std::vector<libMesh::Point> & xyz = fe->get_xyz();
116 
117  fe->reinit(rayfire_elem);
118 
119  const unsigned int n_qpoints = fe->n_quadrature_points();
120 
121  libMesh::Number & qoi = context.get_qois()[qoi_index];
122 
123  for (unsigned int qp = 0; qp != n_qpoints; ++qp)
124  qoi += this->qoi_value((*_f),context,xyz[qp])*JxW[qp];
125 
126  }
127  }
128 
129  template<typename Function>
131  const unsigned int qoi_index )
132  {
133  const libMesh::Elem& original_elem = context.get_elem();
134  const libMesh::Elem* rayfire_elem = _rayfire->map_to_rayfire_elem(original_elem.id());
135 
136  // rayfire_elem will be NULL if the main_elem
137  // is not in the rayfire
138  if (rayfire_elem)
139  {
140  // create and init the quadrature base on the rayfire elem
141  libMesh::QGauss qbase(rayfire_elem->dim(),libMesh::Order(_p_level));
142  qbase.init(rayfire_elem->type(),libMesh::Order(_p_level));
143 
144  // need the QP coordinates and JxW
145  libMesh::UniquePtr< libMesh::FEGenericBase<libMesh::Real> > fe = libMesh::FEGenericBase<libMesh::Real>::build(rayfire_elem->dim(), libMesh::FEType(libMesh::FIRST, libMesh::LAGRANGE) );
146 
147  fe->attach_quadrature_rule( &qbase );
148  const std::vector<libMesh::Real> & JxW = fe->get_JxW();
149  const std::vector<libMesh::Point> & xyz = fe->get_xyz();
150 
151  fe->reinit(rayfire_elem);
152 
153  const unsigned int n_qpoints = fe->n_quadrature_points();
154 
155  // FIXME the inverse_map() is ugly AF
156  for (unsigned int qp = 0; qp != n_qpoints; qp++)
157  this->qoi_derivative((*_f),context,xyz[qp],JxW[qp],qoi_index);
158 
159  }
160  }
161 
162  // speciaizations of the qoi_value() function
163  template<>
165  {
166  return f(context,xyz);
167  }
168 
169  template<>
170  libMesh::Real IntegratedFunction<libMesh::FunctionBase<libMesh::Real> >::qoi_value(libMesh::FunctionBase<libMesh::Real> & f, AssemblyContext & /*context*/, const libMesh::Point & xyz)
171  {
172  return f(xyz);
173  }
174 
175  // speciaizations of the qoi_derivative() function
176  template<>
178  const libMesh::Point & qp_xyz, const libMesh::Real JxW, const unsigned int qoi_index)
179  {
180  f.derivatives(context,qp_xyz,JxW,qoi_index);
181  }
182 
183  template<>
184  void IntegratedFunction<libMesh::FunctionBase<libMesh::Real> >::qoi_derivative( libMesh::FunctionBase<libMesh::Real> & /*f*/, AssemblyContext & /*context*/,
185  const libMesh::Point & /*qp_xyz*/, const libMesh::Real /*JxW*/, const unsigned int /*qoi_index*/)
186  {
187  // derivatives are always zero for FunctionBase
188  }
189 
192 
193 } //namespace GRINS
virtual void reinit(MultiphysicsSystem &system)
Reinitialize the rayfire.
virtual QoIBase * clone() const
Required to provide clone (deep-copy) for adding QoI object to libMesh objects.
libMesh::UniquePtr< RayfireMesh > _rayfire
Pointer to RayfireMesh object.
RayfireMesh.
Definition: rayfire_mesh.h:65
virtual void derivatives(libMesh::FEMContext &context, const libMesh::Point &qp_xyz, const libMesh::Real &JxW, const unsigned int qoi_index, const libMesh::Real time=0.)=0
Function Derivative Evaluation.
virtual void element_qoi(AssemblyContext &context, const unsigned int qoi_index)
Compute the qoi value.
GRINS namespace.
virtual void init(const GetPot &input, const MultiphysicsSystem &system, unsigned int qoi_num)
Initializes the rayfire with the mesh from system.
Interface with libMesh for solving Multiphysics problems.
virtual void element_qoi_derivative(AssemblyContext &context, const unsigned int qoi_index)
Compute the qoi derivative with respect to the solution.
IntegratedFunction()
User cannot call empty constructor.

Generated on Tue Dec 19 2017 12:47:28 for GRINS-0.8.0 by  doxygen 1.8.9.1