GRINS-0.8.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-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
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::UniquePtr<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::UniquePtr<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( unsigned int q = 0; q < _qois.size(); q++ )
97  _qois[q]->init(input,system,q);
98  }
99 
100  void CompositeQoI::init_context( libMesh::DiffContext& context )
101  {
102  AssemblyContext& c = libMesh::cast_ref<AssemblyContext&>(context);
103 
104  for( std::vector<QoIBase*>::iterator qoi = _qois.begin();
105  qoi != _qois.end(); ++qoi )
106  {
107  (*qoi)->init_context(c);
108  }
109 
110  return;
111  }
112 
114  ( const std::string & param_name,
116  const
117  {
118  for( unsigned int q = 0; q < _qois.size(); q++ )
119  (*_qois[q]).register_parameter(param_name, param_pointer);
120  }
121 
123  {
124  // call reinit() on each qoi
125  for (unsigned int i=0; i<this->n_qois(); i++)
126  (this->get_qoi(i)).reinit(system);
127  }
128 
129  void CompositeQoI::element_qoi( libMesh::DiffContext& context,
130  const libMesh::QoISet& /*qoi_indices*/ )
131  {
132  AssemblyContext& c = libMesh::cast_ref<AssemblyContext&>(context);
133 
134  for( unsigned int q = 0; q < _qois.size(); q++ )
135  {
136  (*_qois[q]).element_qoi(c,q);
137  }
138 
139  return;
140  }
141 
142  void CompositeQoI::element_qoi_derivative( libMesh::DiffContext& context,
143  const libMesh::QoISet& /*qoi_indices*/ )
144  {
145  AssemblyContext& c = libMesh::cast_ref<AssemblyContext&>(context);
146 
147  for( unsigned int q = 0; q < _qois.size(); q++ )
148  {
149  (*_qois[q]).element_qoi_derivative(c,q);
150  }
151 
152  return;
153  }
154 
155  void CompositeQoI::side_qoi( libMesh::DiffContext& context,
156  const libMesh::QoISet& /*qoi_indices*/ )
157  {
158  AssemblyContext& c = libMesh::cast_ref<AssemblyContext&>(context);
159 
160  for( unsigned int q = 0; q < _qois.size(); q++ )
161  {
162  (*_qois[q]).side_qoi(c,q);
163  }
164 
165  return;
166  }
167 
168  void CompositeQoI::side_qoi_derivative( libMesh::DiffContext& context,
169  const libMesh::QoISet& /*qoi_indices*/ )
170  {
171  AssemblyContext& c = libMesh::cast_ref<AssemblyContext&>(context);
172 
173  for( unsigned int q = 0; q < _qois.size(); q++ )
174  {
175  (*_qois[q]).side_qoi_derivative(c,q);
176  }
177 
178  return;
179  }
180 
181  void CompositeQoI::parallel_op( const libMesh::Parallel::Communicator& communicator,
182  std::vector<libMesh::Number>& sys_qoi,
183  std::vector<libMesh::Number>& local_qoi,
184  const libMesh::QoISet& /*qoi_indices*/ )
185  {
186  for( unsigned int q = 0; q < _qois.size(); q++ )
187  {
188  (*_qois[q]).parallel_op( communicator, sys_qoi[q], local_qoi[q] );
189  }
190 
191  return;
192  }
193 
194  void CompositeQoI::thread_join( std::vector<libMesh::Number>& qoi,
195  const std::vector<libMesh::Number>& other_qoi,
196  const libMesh::QoISet& /*qoi_indices*/ )
197  {
198  for( unsigned int q = 0; q < _qois.size(); q++ )
199  {
200  (*_qois[q]).thread_join( qoi[q], other_qoi[q] );
201  }
202 
203  return;
204  }
205 
206  void CompositeQoI::output_qoi( std::ostream& out ) const
207  {
208  for( std::vector<QoIBase*>::const_iterator qoi = _qois.begin();
209  qoi != _qois.end(); ++qoi )
210  {
211  (*qoi)->output_qoi(out);
212  }
213 
214  return;
215  }
216 
217  libMesh::Number CompositeQoI::get_qoi_value( unsigned int qoi_index ) const
218  {
219  return (*_qois[qoi_index]).value();
220  }
221 
222 } // 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
void register_parameter(const std::string &param_name, libMesh::ParameterMultiAccessor< libMesh::Number > &param_pointer) const
Each QoI will register its copy(s) of an independent variable.
virtual libMesh::UniquePtr< libMesh::DifferentiableQoI > clone()
Required to provide clone for adding QoI object to libMesh objects.
Definition: composite_qoi.C:58
GRINS namespace.
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 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.
virtual void reinit(MultiphysicsSystem &system)
Reinitialize qoi.
unsigned int n_qois() const

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