GRINS-0.8.0
physics_builder.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 // This class
26 #include "grins/physics_builder.h"
27 
28 // GRINS
29 #include "grins/shared_ptr.h"
30 #include "grins/physics_naming.h"
32 
33 // libMesh
34 #include "libmesh/getpot.h"
35 
36 namespace GRINS
37 {
39  {
40  // First parse what Physics the user requested
41  std::set<std::string> requested_physics;
42  PhysicsBuilder::parse_requested_physics(input,requested_physics);
43 
44  // Give the PhysicsFactories access to the GetPot object
46 
47  PhysicsList physics_map;
48 
49  // Now populate the PhysicsList with with of the corresponding Physics objects
50  for( std::set<std::string>::const_iterator physics_name_it = requested_physics.begin();
51  physics_name_it != requested_physics.end();
52  physics_name_it++ )
53  {
54  // Convenience
55  std::string physics_name = *physics_name_it;
56 
57  // Set the physics_name in the PhysicsFactory as it will be used internally
58  // to feed to the Physics constructors
60 
61  // Set the suffix in PhysicsNaming so it propagates to the Physics classes
62  std::string physics_suffix = PhysicsNaming::extract_suffix(physics_name);
63  PhysicsNaming::set_suffix(physics_suffix);
64 
65  // Strip any suffix out when querying the PhysicsFactories
66  std::string physics_name_prefix = PhysicsNaming::extract_physics(physics_name);
67 
68  // Now build the actual Physics object
69  libMesh::UniquePtr<Physics> physics_ptr = PhysicsFactoryBase::build(physics_name_prefix);
70 
71  // Clear out the suffix now that we're done
73 
74  // Now give it to the PhysicsList
75  physics_map[physics_name] = SharedPtr<Physics>( physics_ptr.release() );
76  }
77 
78  // Echo Physics to display, if requested
79  if( input( "screen-options/echo_physics", true ) )
80  {
81  libMesh::out << "==========================================================" << std::endl
82  << "List of Enabled Physics:" << std::endl;
83 
84  for( PhysicsListIter it = physics_map.begin();
85  it != physics_map.end();
86  it++ )
87  {
88  libMesh::out << it->first << std::endl;
89  }
90  libMesh::out << "==========================================================" << std::endl;
91  }
92 
93  return physics_map;
94  }
95 
96  void PhysicsBuilder::parse_requested_physics( const GetPot& input, std::set<std::string>& requested_physics )
97  {
98  int num_physics = input.vector_variable_size("Physics/enabled_physics");
99 
100  if( num_physics < 1 )
101  libmesh_error_msg("Error: Must enable at least one physics model!");
102 
103  for( int i = 0; i < num_physics; i++ )
104  requested_physics.insert( input("Physics/enabled_physics", "NULL", i ) );
105  }
106 
107 } // end namespace GRINS
static PhysicsList build_physics_map(const GetPot &input)
Returns container of constructed Physics objects.
static void set_getpot(const GetPot &input)
static libMesh::UniquePtr< Physics > build(const std::string &name)
Use this method to build objects of type Base.
static void parse_requested_physics(const GetPot &input, std::set< std::string > &requested_physics)
Parses the requested Physics from input and populates the set passed to this function.
GRINS namespace.
static std::string extract_physics(const std::string &full_name)
Extract the physics name from the full_name.
static void set_physics_name(const std::string &physics_name)
Setter for physics name.
std::map< std::string, SharedPtr< GRINS::Physics > > PhysicsList
Container for GRINS::Physics object pointers.
Definition: var_typedefs.h:59
static std::string extract_suffix(const std::string &full_name)
Extract the suffix from the full_name.
std::map< std::string, SharedPtr< GRINS::Physics > >::const_iterator PhysicsListIter
Iterator for PhysicsList.
Definition: var_typedefs.h:62
static void clear_suffix()
static void set_suffix(const std::string &suff)

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