GRINS-0.7.0
qoi_factory.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 // This class
26 #include "grins/qoi_factory.h"
27 
28 // GRINS
29 #include "grins/string_utils.h"
30 #include "grins/physics_naming.h"
31 #include "grins/qoi_names.h"
33 #include "grins/vorticity.h"
37 
38 namespace GRINS
39 {
41  {
42  return;
43  }
44 
46  {
47  return;
48  }
49 
50  SharedPtr<CompositeQoI> QoIFactory::build(const GetPot& input)
51  {
52  std::string qoi_list = input("QoI/enabled_qois", "none" );
53 
54  std::vector<std::string> qoi_names;
55 
56  if( qoi_list != std::string("none") )
57  {
58  StringUtilities::split_string( qoi_list, std::string(" "), qoi_names );
59  }
60 
61  SharedPtr<CompositeQoI> qois( new CompositeQoI );
62 
63  if( !qoi_names.empty() )
64  {
65  for( std::vector<std::string>::const_iterator name = qoi_names.begin();
66  name != qoi_names.end(); ++name )
67  {
68  this->add_qoi( input, *name, qois );
69 
70  this->check_qoi_physics_consistency( input, *name );
71  }
72 
73  if( input( "screen-options/echo_qoi", false ) )
74  {
75  this->echo_qoi_list( qois );
76  }
77  }
78 
79  return qois;
80  }
81 
82  void QoIFactory::add_qoi( const GetPot& /*input*/, const std::string& qoi_name, SharedPtr<CompositeQoI>& qois )
83  {
84  QoIBase* qoi = NULL;
85 
86  if( qoi_name == avg_nusselt )
87  {
88  qoi = new AverageNusseltNumber( avg_nusselt );
89  }
90 
91  else if( qoi_name == parsed_boundary )
92  {
94  }
95 
96  else if( qoi_name == parsed_interior )
97  {
99  }
100 
101  else if( qoi_name == vorticity )
102  {
103  qoi = new Vorticity( vorticity );
104  }
105 
106  else if( qoi_name == weighted_flux )
107  {
108  qoi = new WeightedFluxQoI( weighted_flux );
109  }
110 
111  else
112  {
113  libMesh::err << "Error: Invalid QoI name " << qoi_name << std::endl;
114  libmesh_error();
115  }
116 
117  libmesh_assert(qoi);
118 
119  qois->add_qoi( *qoi );
120 
121  return;
122  }
123 
124  void QoIFactory::check_qoi_physics_consistency( const GetPot& input,
125  const std::string& qoi_name )
126  {
127  int num_physics = input.vector_variable_size("Physics/enabled_physics");
128 
129  // This should be checked other places, but let's be double sure.
130  libmesh_assert(num_physics > 0);
131 
132  std::set<std::string> requested_physics;
133  std::set<std::string> required_physics;
134 
135  // Build Physics name set
136  for( int i = 0; i < num_physics; i++ )
137  {
138  requested_physics.insert( input("Physics/enabled_physics", "NULL", i ) );
139  }
140 
141  /* If it's Nusselt, we'd better have HeatTransfer or LowMachNavierStokes.
142  HeatTransfer implicitly requires fluids, so no need to check for those. `*/
143  if( qoi_name == avg_nusselt )
144  {
145  required_physics.insert(PhysicsNaming::heat_transfer());
146  required_physics.insert(PhysicsNaming::low_mach_navier_stokes());
147  this->consistency_helper( requested_physics, required_physics, qoi_name );
148  }
149 
150  return;
151  }
152 
153  void QoIFactory::echo_qoi_list( SharedPtr<CompositeQoI>& qois )
154  {
156  std::cout << "==========================================================" << std::endl
157  << "List of Enabled QoIs:" << std::endl;
158 
159  for( unsigned int q = 0; q < qois->n_qois(); q++ )
160  {
161  std::cout << qois->get_qoi(q).name() << std::endl;
162  }
163 
164  std::cout << "==========================================================" << std::endl;
165 
166  return;
167  }
168 
169  void QoIFactory::consistency_helper( const std::set<std::string>& requested_physics,
170  const std::set<std::string>& required_physics,
171  const std::string& qoi_name )
172  {
173  bool physics_found = false;
174  for( std::set<std::string>::const_iterator name = required_physics.begin();
175  name != required_physics.end();
176  name++ )
177  {
178  if( requested_physics.find( (*name) ) != requested_physics.end() )
179  physics_found = true;
180  }
181 
182  if( !physics_found )
183  this->consistency_error_msg( qoi_name, required_physics );
184 
185  return;
186  }
187 
188  void QoIFactory::consistency_error_msg( const std::string& qoi_name,
189  const std::set<std::string>& required_physics )
190  {
191  libMesh::err << "================================================================" << std::endl
192  << "QoI " << qoi_name << std::endl
193  << "requires one of the following physics which were not found:" <<std::endl;
194 
195  for( std::set<std::string>::const_iterator name = required_physics.begin();
196  name != required_physics.end();
197  name++ )
198  {
199  libMesh::err << *name << std::endl;
200  }
201 
202  libMesh::err << "================================================================" << std::endl;
203 
204  libmesh_error();
205  }
206 
207 } //namespace GRINS
virtual SharedPtr< CompositeQoI > build(const GetPot &input)
Definition: qoi_factory.C:50
static PhysicsName heat_transfer()
virtual void check_qoi_physics_consistency(const GetPot &input, const std::string &qoi_name)
Definition: qoi_factory.C:124
void consistency_error_msg(const std::string &qoi_name, const std::set< std::string > &required_physics)
Definition: qoi_factory.C:188
Vorticity QoI.
Definition: vorticity.h:42
static PhysicsName low_mach_navier_stokes()
const std::string avg_nusselt
Definition: qoi_names.h:30
const std::string vorticity
Definition: qoi_names.h:31
GRINS namespace.
Parsed Interior QoI.
Parsed Boundary QoI.
virtual ~QoIFactory()
Definition: qoi_factory.C:45
const std::string weighted_flux
Definition: qoi_names.h:34
const std::string parsed_boundary
Definition: qoi_names.h:32
void split_string(const std::string &input, const std::string &delimiter, std::vector< std::string > &results)
Definition: string_utils.C:31
const std::string parsed_interior
Definition: qoi_names.h:33
virtual void echo_qoi_list(SharedPtr< CompositeQoI > &qois)
Definition: qoi_factory.C:153
void consistency_helper(const std::set< std::string > &requested_physics, const std::set< std::string > &required_physics, const std::string &qoi_name)
Definition: qoi_factory.C:169
virtual void add_qoi(const GetPot &input, const std::string &qoi_name, SharedPtr< CompositeQoI > &qois)
Definition: qoi_factory.C:82

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