GRINS-0.7.0
weighted_flux_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-2016 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/composite_function.h"
35 #include "libmesh/dirichlet_boundaries.h"
36 #include "libmesh/dof_map.h"
37 #include "libmesh/getpot.h"
38 #include "libmesh/fem_system.h"
39 #include "libmesh/parsed_function.h"
40 #include "libmesh/quadrature.h"
41 
42 namespace GRINS
43 {
44  WeightedFluxQoI::WeightedFluxQoI( const std::string& qoi_name )
45  : QoIBase(qoi_name)
46  {
47  return;
48  }
49 
51  {
52  return;
53  }
54 
56  {
57  return new WeightedFluxQoI( *this );
58  }
59 
61  (const GetPot& input,
62  const MultiphysicsSystem& system,
63  unsigned int qoi_num )
64  {
65  // Read variables for which we want to compute fluxes
66  int num_vars = input.vector_variable_size("QoI/WeightedFlux/variables");
67 
68  if( num_vars <= 0 )
69  {
70  std::cerr << "Error: Must specify at least one variable to compute"
71  << " weighted fluxes." << std::endl
72  << "Found: " << num_vars << std::endl;
73  libmesh_error();
74  }
75 
76  // Read boundary ids on which we want to compute fluxes
77  int num_bcs =
78  input.vector_variable_size("QoI/WeightedFlux/bc_ids");
79 
80  if( num_bcs != num_vars )
81  {
82  std::cerr << "Error: Must specify exactly one boundary id"
83  << " for each specified weighted flux variable."
84  << std::endl
85  << "Found: " << num_bcs << std::endl;
86  libmesh_error();
87  }
88 
89  std::vector<libMesh::boundary_id_type> bc_ids;
90 
91  for( int i = 0; i < num_bcs; i++ )
92  bc_ids.push_back( input("QoI/WeightedFlux/bc_ids", -1, i ) );
93 
94  // Read weight functions with which to compute fluxes
95  int num_weights =
96  input.vector_variable_size("QoI/WeightedFlux/weights");
97 
98  if( num_weights != num_vars )
99  {
100  std::cerr << "Error: Must specify exactly one weight function"
101  << " for each specified weighted flux variable."
102  << std::endl
103  << "Found: " << num_weights << std::endl;
104  libmesh_error();
105  }
106 
107  for( int i = 0; i < num_weights; i++ )
108  {
109  const libMesh::boundary_id_type bc_id =
110  input("QoI/WeightedFlux/bc_ids", -1, i );
111 
112  libmesh_assert_not_equal_to (bc_id, -1);
113 
114  const std::string var_name =
115  ( input("QoI/WeightedFlux/variables", std::string(""), i ) );
116 
117  libmesh_assert_not_equal_to (var_name, std::string(""));
118 
119  const std::string func_string =
120  input("QoI/WeightedFlux/weights", std::string(""), i);
121 
122  libmesh_assert_not_equal_to (func_string, std::string(""));
123 
124  std::set<libMesh::boundary_id_type> bc_id_set;
125  bc_id_set.insert(bc_id);
126 
127  libMesh::ParsedFunction<libMesh::Number> raw_func (func_string);
128 
129  std::vector<unsigned int> var_indices;
130  var_indices.push_back( system.variable_number( var_name ) );
131 
134 
135  remapped_func->attach_subfunction(raw_func, var_indices);
136 
137  libMesh::DirichletBoundary adjoint_bc
138  (bc_id_set, var_indices, remapped_func);
139 
140  // FIXME: this is an ugly hack
141  MultiphysicsSystem & hacked_system =
142  const_cast<MultiphysicsSystem&>(system);
143  hacked_system.get_dof_map().add_adjoint_dirichlet_boundary
144  (adjoint_bc, qoi_num);
145  }
146 
147  MultiphysicsSystem & hacked_system =
148  const_cast<MultiphysicsSystem&>(system);
149  hacked_system.reinit_constraints();
150  }
151 
152 } //namespace GRINS
virtual void init(const GetPot &input, const MultiphysicsSystem &system, unsigned int qoi_num)
Method to allow QoI to cache any system information needed for QoI calculation, for example...
GRINS namespace.
Interface with libMesh for solving Multiphysics problems.
virtual QoIBase * clone() const
Clone this QoI.

Generated on Thu Jun 2 2016 21:52:28 for GRINS-0.7.0 by  doxygen 1.8.10