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

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