GRINS-0.6.0
composite_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
27 #include "grins/composite_qoi.h"
28 
29 // GRINS
30 #include "grins/assembly_context.h"
31 
32 // libMesh
33 #include "libmesh/diff_context.h"
34 
35 namespace GRINS
36 {
38  : libMesh::DifferentiableQoI()
39  {
40  // We initialize these to false and then reset as needed by each QoI
41  assemble_qoi_sides = false;
42  assemble_qoi_elements = false;
43 
44  return;
45  }
46 
48  {
49  for( std::vector<QoIBase*>::iterator qoi = _qois.begin();
50  qoi != _qois.end(); ++qoi )
51  {
52  delete (*qoi);
53  }
54 
55  return;
56  }
57 
58  libMesh::AutoPtr<libMesh::DifferentiableQoI> CompositeQoI::clone()
59  {
61 
62  for( unsigned int q = 0; q < this->n_qois(); q++ )
63  {
64  clone->add_qoi( this->get_qoi(q) );
65  }
66 
67  return libMesh::AutoPtr<libMesh::DifferentiableQoI>(clone);
68  }
69 
70  void CompositeQoI::add_qoi( const QoIBase& qoi )
71  {
72  _qois.push_back( qoi.clone() );
73 
74  if( qoi.assemble_on_interior() )
75  {
76  this->assemble_qoi_elements = true;
77  }
78 
79  if( qoi.assemble_on_sides() )
80  {
81  this->assemble_qoi_sides = true;
82  }
83 
84  return;
85  }
86 
87  void CompositeQoI::init_qoi( std::vector<libMesh::Number>& sys_qoi )
88  {
89  sys_qoi.resize(_qois.size(), 0.0);
90 
91  return;
92  }
93 
94  void CompositeQoI::init( const GetPot& input, const MultiphysicsSystem& system )
95  {
96  for( std::vector<QoIBase*>::iterator qoi = _qois.begin();
97  qoi != _qois.end(); ++qoi )
98  {
99  (*qoi)->init(input,system);
100  }
101 
102  return;
103  }
104 
105  void CompositeQoI::init_context( libMesh::DiffContext& context )
106  {
107  AssemblyContext& c = libMesh::libmesh_cast_ref<AssemblyContext&>(context);
108 
109  for( std::vector<QoIBase*>::iterator qoi = _qois.begin();
110  qoi != _qois.end(); ++qoi )
111  {
112  (*qoi)->init_context(c);
113  }
114 
115  return;
116  }
117 
119  ( const std::string & param_name,
121  const
122  {
123  for( unsigned int q = 0; q < _qois.size(); q++ )
124  (*_qois[q]).register_parameter(param_name, param_pointer);
125  }
126 
127  void CompositeQoI::element_qoi( libMesh::DiffContext& context,
128  const libMesh::QoISet& /*qoi_indices*/ )
129  {
130  AssemblyContext& c = libMesh::libmesh_cast_ref<AssemblyContext&>(context);
131 
132  for( unsigned int q = 0; q < _qois.size(); q++ )
133  {
134  (*_qois[q]).element_qoi(c,q);
135  }
136 
137  return;
138  }
139 
140  void CompositeQoI::element_qoi_derivative( libMesh::DiffContext& context,
141  const libMesh::QoISet& /*qoi_indices*/ )
142  {
143  AssemblyContext& c = libMesh::libmesh_cast_ref<AssemblyContext&>(context);
144 
145  for( unsigned int q = 0; q < _qois.size(); q++ )
146  {
147  (*_qois[q]).element_qoi_derivative(c,q);
148  }
149 
150  return;
151  }
152 
153  void CompositeQoI::side_qoi( libMesh::DiffContext& context,
154  const libMesh::QoISet& /*qoi_indices*/ )
155  {
156  AssemblyContext& c = libMesh::libmesh_cast_ref<AssemblyContext&>(context);
157 
158  for( unsigned int q = 0; q < _qois.size(); q++ )
159  {
160  (*_qois[q]).side_qoi(c,q);
161  }
162 
163  return;
164  }
165 
166  void CompositeQoI::side_qoi_derivative( libMesh::DiffContext& context,
167  const libMesh::QoISet& /*qoi_indices*/ )
168  {
169  AssemblyContext& c = libMesh::libmesh_cast_ref<AssemblyContext&>(context);
170 
171  for( unsigned int q = 0; q < _qois.size(); q++ )
172  {
173  (*_qois[q]).side_qoi_derivative(c,q);
174  }
175 
176  return;
177  }
178 
179  void CompositeQoI::parallel_op( const libMesh::Parallel::Communicator& communicator,
180  std::vector<libMesh::Number>& sys_qoi,
181  std::vector<libMesh::Number>& local_qoi,
182  const libMesh::QoISet& /*qoi_indices*/ )
183  {
184  for( unsigned int q = 0; q < _qois.size(); q++ )
185  {
186  (*_qois[q]).parallel_op( communicator, sys_qoi[q], local_qoi[q] );
187  }
188 
189  return;
190  }
191 
192  void CompositeQoI::thread_join( std::vector<libMesh::Number>& qoi,
193  const std::vector<libMesh::Number>& other_qoi,
194  const libMesh::QoISet& /*qoi_indices*/ )
195  {
196  for( unsigned int q = 0; q < _qois.size(); q++ )
197  {
198  (*_qois[q]).thread_join( qoi[q], other_qoi[q] );
199  }
200 
201  return;
202  }
203 
204  void CompositeQoI::output_qoi( std::ostream& out ) const
205  {
206  for( std::vector<QoIBase*>::const_iterator qoi = _qois.begin();
207  qoi != _qois.end(); ++qoi )
208  {
209  (*qoi)->output_qoi(out);
210  }
211 
212  return;
213  }
214 
215  libMesh::Number CompositeQoI::get_qoi_value( unsigned int qoi_index ) const
216  {
217  return (*_qois[qoi_index]).value();
218  }
219 
220 } // end namespace GRINS
virtual bool assemble_on_interior() const =0
Does the QoI need an element interior assembly loop?
virtual void thread_join(std::vector< libMesh::Number > &qoi, const std::vector< libMesh::Number > &other_qoi, const libMesh::QoISet &qoi_indices)
Operation to accumulate the QoI from multiple MPI processes.
std::vector< QoIBase * > _qois
virtual void init_context(libMesh::DiffContext &context)
virtual void side_qoi_derivative(libMesh::DiffContext &context, const libMesh::QoISet &qois)
Compute the qoi derivative with respect to the solution on the domain boundary.
const QoIBase & get_qoi(unsigned int qoi_index) const
virtual bool assemble_on_sides() const =0
Does the QoI need a domain boundary assembly loop?
virtual ~CompositeQoI()
Definition: composite_qoi.C:47
GRINS namespace.
void register_parameter(const std::string &param_name, libMesh::ParameterMultiPointer< libMesh::Number > &param_pointer) const
Each QoI will register its copy(s) of an independent variable.
virtual void side_qoi(libMesh::DiffContext &context, const libMesh::QoISet &qoi_indices)
Compute the qoi value on the domain boundary.
virtual void element_qoi(libMesh::DiffContext &context, const libMesh::QoISet &qoi_indices)
Compute the qoi value for element interiors.
virtual void init_qoi(std::vector< libMesh::Number > &sys_qoi)
Method to allow QoI to resize libMesh::System storage of QoI computations.
Definition: composite_qoi.C:87
virtual void parallel_op(const libMesh::Parallel::Communicator &communicator, std::vector< libMesh::Number > &sys_qoi, std::vector< libMesh::Number > &local_qoi, const libMesh::QoISet &qoi_indices)
Operation to accumulate the QoI from multiple MPI processes.
Interface with libMesh for solving Multiphysics problems.
virtual void add_qoi(const QoIBase &qoi)
Definition: composite_qoi.C:70
void output_qoi(std::ostream &out) const
Basic output for computed QoI's.
virtual void init(const GetPot &input, const MultiphysicsSystem &system)
Method to allow QoI to cache any system information needed for QoI calculation, for example...
Definition: composite_qoi.C:94
virtual void element_qoi_derivative(libMesh::DiffContext &context, const libMesh::QoISet &qoi_indices)
Compute the qoi derivative with respect to the solution on element interiors.
virtual libMesh::AutoPtr< libMesh::DifferentiableQoI > clone()
Required to provide clone for adding QoI object to libMesh objects.
Definition: composite_qoi.C:58
virtual QoIBase * clone() const =0
Clone this QoI.
libMesh::Number get_qoi_value(unsigned int qoi_index) const
Accessor for value of QoI for given qoi_index.
unsigned int n_qois() const

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