GRINS-0.8.0
default_variable_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
27 
28 // GRINS
29 #include "grins/multiphysics_sys.h"
30 #include "grins/variable_factory.h"
31 
32 // libMesh
33 #include "libmesh/getpot.h"
34 #include "libmesh/mesh_base.h"
35 
36 namespace GRINS
37 {
39  MultiphysicsSystem& system )
40  {
41  std::set<libMesh::subdomain_id_type> mesh_subdomain_ids;
42  const libMesh::MeshBase& mesh = system.get_mesh();
43 
44  // Note this does a full loop of the mesh, these are not cached
45  // So we compute them once
46  mesh.subdomain_ids(mesh_subdomain_ids);
47 
48  std::vector<std::string> var_sections;
49  this->parse_var_sections_vector( input, var_sections );
50 
51  for( std::vector<std::string>::const_iterator var_sect = var_sections.begin();
52  var_sect != var_sections.end(); ++var_sect )
53  {
54  // Convenience
55  std::string var_section( *var_sect );
56 
57  // We construct based on the Variable type so we can name the Variables whatever we want
58  // If var_type is invalid, that will be detected in the build_fe_var call, since
59  // we feed the var_type to VariableFactoryAbstract::build.
60  std::string var_type = this->parse_var_type( input, var_section );
61 
62  // Parse names
63  std::vector<std::string> var_names;
64  this->parse_var_names( input, var_type, var_section, var_names );
65 
66  // Parse FE family
67  std::string fe_family = this->parse_fe_family( input, var_section, var_type );
68 
69  // Parse FE order
70  std::string order = this->parse_fe_order( input, var_section, var_type );
71 
72  // Parse the subdomain_ids
73  std::set<libMesh::subdomain_id_type> subdomain_ids;
74  this->parse_subdomain_ids( mesh_subdomain_ids, input, var_section, subdomain_ids );
75 
76  // Add variables to system
77  std::vector<VariableIndex> var_indices;
78  this->add_vars_to_system( system, var_names, fe_family, order, var_indices, subdomain_ids );
79 
80 
81  // Build FEVariablesBase object
82  SharedPtr<FEVariablesBase> fe_var = this->build_fe_var( var_type, var_names, var_indices, subdomain_ids );
83 
84  // Add to VariableWarehouse
85  this->add_variable_to_warehouse( fe_var, var_section );
86  }
87  }
88 
89  void DefaultVariableBuilder::parse_var_names( const GetPot& input,
90  const std::string& var_type,
91  const std::string& var_section,
92  std::vector<std::string>& var_names ) const
93  {
94  // Just in case
95  var_names.clear();
96 
99 
100  var_names = VariableFactoryAbstract::build_var_names(var_type);
101  }
102 
103  std::string DefaultVariableBuilder::parse_fe_family( const GetPot& input,
104  const std::string& var_section,
105  const std::string& var_type ) const
106  {
109 
111  }
112 
113  std::string DefaultVariableBuilder::parse_fe_order( const GetPot& input,
114  const std::string& var_section,
115  const std::string& var_type ) const
116  {
119 
121  }
122 
123  void DefaultVariableBuilder::parse_subdomain_ids( const std::set<libMesh::subdomain_id_type>& mesh_subdomain_ids,
124  const GetPot& input,
125  const std::string& var_section,
126  std::set<libMesh::subdomain_id_type>& subdomain_ids )
127  {
128  std::string input_sec(VariablesParsing::variables_section()+"/"+var_section+"/enabled_subdomains");
129  if( input.have_variable(input_sec) )
130  {
131  unsigned int invalid_id = std::numeric_limits<unsigned int>::max();
132 
133  unsigned int n_ids = input.vector_variable_size(input_sec);
134  for( unsigned int i = 0; i < n_ids; i++ )
135  {
136  unsigned int id = input(input_sec,invalid_id,i);
137  subdomain_ids.insert(id);
138  }
139 
140  for( std::set<libMesh::subdomain_id_type>::const_iterator it = subdomain_ids.begin(); it != subdomain_ids.end(); ++it )
141  if( mesh_subdomain_ids.find(*it) == mesh_subdomain_ids.end() )
142  libmesh_error_msg("ERROR: Could not find subdomain " << *it << " in the mesh!");
143  }
144  }
145 
146 } // end namespace GRINS
std::string parse_fe_order(const GetPot &input, const std::string &var_section, const std::string &var_type) const
Helper function to extract [Varaiable//order] from input.
static std::string variables_section()
Helper function to encapsualte the overall [Variables] section name.
static void set_getpot(const GetPot &input)
std::string parse_var_type(const GetPot &input, const std::string &var_section) const
Parses the [Variable//var_type] option.
void parse_subdomain_ids(const std::set< libMesh::subdomain_id_type > &mesh_subdomain_ids, const GetPot &input, const std::string &var_section, std::set< libMesh::subdomain_id_type > &subdomain_ids)
static void parse_var_sections_vector(const GetPot &input, std::vector< std::string > &sections)
The same as parse_var_sections, except the result is returned in an std::vector.
static std::vector< std::string > build_var_names(const std::string &name)
Build the variable names for the FEVariablesBase type (name), returned in the std::vector.
void add_variable_to_warehouse(SharedPtr< FEVariablesBase > &fe_var, const std::string &var_name)
Adds/registers the fe_var to VariableWarehouse.
GRINS namespace.
void add_vars_to_system(MultiphysicsSystem &system, const std::vector< std::string > &var_names, const std::string &fe_family, const std::string &order, std::vector< VariableIndex > &var_indices, const std::set< libMesh::subdomain_id_type > &subdomain_ids)
Given the names, family, and order, this adds the variables to the system and populates var_indices...
void parse_var_names(const GetPot &input, const std::string &var_type, const std::string &var_section, std::vector< std::string > &var_names) const
Parse [Variable//names].
static void set_var_section(const std::string &var_section)
Set the section for the input file before calling build_var_names()
virtual void build_variables_impl(const GetPot &input, MultiphysicsSystem &system)
Implementation of Variable construction done in subclasses.
static std::string parse_fe_family(const std::string &name)
Interface with libMesh for solving Multiphysics problems.
SharedPtr< FEVariablesBase > build_fe_var(const std::string &var_type, const std::vector< std::string > &var_names, const std::vector< VariableIndex > &var_indices, const std::set< libMesh::subdomain_id_type > &subdomain_ids)
Sets appropriate data in the VariableFactoryAbstract and calls VariableFactoryAbstract::build() ...
std::string parse_fe_family(const GetPot &input, const std::string &var_section, const std::string &var_type) const
Helper function to extract from input.
static std::string parse_fe_order(const std::string &name)

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