GRINS-0.8.0
List of all members | Public Member Functions | Protected Member Functions
GRINS::DefaultVariableBuilder Class Reference

#include <default_variable_builder.h>

Inheritance diagram for GRINS::DefaultVariableBuilder:
Inheritance graph
[legend]
Collaboration diagram for GRINS::DefaultVariableBuilder:
Collaboration graph
[legend]

Public Member Functions

 DefaultVariableBuilder ()
 
 ~DefaultVariableBuilder ()
 
virtual void build_variables_impl (const GetPot &input, MultiphysicsSystem &system)
 Implementation of Variable construction done in subclasses. More...
 
- Public Member Functions inherited from GRINS::VariableBuilder
 VariableBuilder ()
 
 ~VariableBuilder ()
 
- Public Member Functions inherited from GRINS::BuilderHelper
 BuilderHelper ()
 
 ~BuilderHelper ()
 

Protected Member Functions

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/<var_section>/names]. More...
 
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. More...
 
std::string parse_fe_order (const GetPot &input, const std::string &var_section, const std::string &var_type) const
 Helper function to extract [Varaiable/<var_section>/order] from input. More...
 
std::string parse_var_type (const GetPot &input, const std::string &var_section) const
 Parses the [Variable/<var_section>/var_type] option. More...
 
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)
 
- Protected Member Functions inherited from GRINS::VariableBuilder
void add_variable_to_warehouse (SharedPtr< FEVariablesBase > &fe_var, const std::string &var_name)
 Adds/registers the fe_var to VariableWarehouse. More...
 
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. More...
 
SharedPtr< FEVariablesBasebuild_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() More...
 

Additional Inherited Members

- Static Public Member Functions inherited from GRINS::VariableBuilder
static void build_variables (const GetPot &input, MultiphysicsSystem &system)
 
- Static Public Member Functions inherited from GRINS::BuilderHelper
static void parse_var_sections (const GetPot &input, std::set< std::string > &sections)
 Parses the input file for [Variables] first-level subsections. More...
 
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. More...
 

Detailed Description

Definition at line 37 of file default_variable_builder.h.

Constructor & Destructor Documentation

GRINS::DefaultVariableBuilder::DefaultVariableBuilder ( )
inline

Definition at line 41 of file default_variable_builder.h.

41 {}
GRINS::DefaultVariableBuilder::~DefaultVariableBuilder ( )
inline

Definition at line 42 of file default_variable_builder.h.

42 {}

Member Function Documentation

void GRINS::DefaultVariableBuilder::build_variables_impl ( const GetPot &  input,
MultiphysicsSystem system 
)
virtual

Implementation of Variable construction done in subclasses.

Implements GRINS::VariableBuilder.

Definition at line 38 of file default_variable_builder.C.

References GRINS::VariableBuilder::add_variable_to_warehouse(), GRINS::VariableBuilder::add_vars_to_system(), GRINS::VariableBuilder::build_fe_var(), parse_fe_family(), parse_fe_order(), parse_subdomain_ids(), parse_var_names(), GRINS::BuilderHelper::parse_var_sections_vector(), and parse_var_type().

Referenced by GRINS::VariableBuilder::build_variables().

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  }
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.
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.
void add_variable_to_warehouse(SharedPtr< FEVariablesBase > &fe_var, const std::string &var_name)
Adds/registers the fe_var to VariableWarehouse.
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].
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.
std::string GRINS::DefaultVariableBuilder::parse_fe_family ( const GetPot &  input,
const std::string &  var_section,
const std::string &  var_type 
) const
protected

Helper function to extract from input.

This will dispatch to the VariableFactory.

Definition at line 103 of file default_variable_builder.C.

References GRINS::VariableFactoryAbstract::parse_fe_family(), GRINS::FactoryWithGetPot< FEVariablesBase >::set_getpot(), GRINS::VariableFactoryAbstract::set_var_section(), and GRINS::VariablesParsing::variables_section().

Referenced by build_variables_impl().

106  {
109 
111  }
static std::string variables_section()
Helper function to encapsualte the overall [Variables] section name.
static void set_getpot(const GetPot &input)
static void set_var_section(const std::string &var_section)
Set the section for the input file before calling build_var_names()
static std::string parse_fe_family(const std::string &name)
std::string GRINS::DefaultVariableBuilder::parse_fe_order ( const GetPot &  input,
const std::string &  var_section,
const std::string &  var_type 
) const
protected

Helper function to extract [Varaiable/<var_section>/order] from input.

This will dispatch to the VariableFactory.

Definition at line 113 of file default_variable_builder.C.

References GRINS::VariableFactoryAbstract::parse_fe_order(), GRINS::FactoryWithGetPot< FEVariablesBase >::set_getpot(), GRINS::VariableFactoryAbstract::set_var_section(), and GRINS::VariablesParsing::variables_section().

Referenced by build_variables_impl().

116  {
119 
121  }
static std::string variables_section()
Helper function to encapsualte the overall [Variables] section name.
static void set_getpot(const GetPot &input)
static void set_var_section(const std::string &var_section)
Set the section for the input file before calling build_var_names()
static std::string parse_fe_order(const std::string &name)
void GRINS::DefaultVariableBuilder::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 
)
protected

Definition at line 123 of file default_variable_builder.C.

References GRINS::VariablesParsing::variables_section().

Referenced by build_variables_impl().

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  }
static std::string variables_section()
Helper function to encapsualte the overall [Variables] section name.
void GRINS::DefaultVariableBuilder::parse_var_names ( const GetPot &  input,
const std::string &  var_type,
const std::string &  var_section,
std::vector< std::string > &  var_names 
) const
protected

Parse [Variable/<var_section>/names].

Definition at line 89 of file default_variable_builder.C.

References GRINS::VariableFactoryAbstract::build_var_names(), GRINS::FactoryWithGetPot< FEVariablesBase >::set_getpot(), GRINS::VariableFactoryAbstract::set_var_section(), and GRINS::VariablesParsing::variables_section().

Referenced by build_variables_impl().

93  {
94  // Just in case
95  var_names.clear();
96 
99 
100  var_names = VariableFactoryAbstract::build_var_names(var_type);
101  }
static std::string variables_section()
Helper function to encapsualte the overall [Variables] section name.
static void set_getpot(const GetPot &input)
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.
static void set_var_section(const std::string &var_section)
Set the section for the input file before calling build_var_names()
std::string GRINS::DefaultVariableBuilder::parse_var_type ( const GetPot &  input,
const std::string &  var_section 
) const
inlineprotected

Parses the [Variable/<var_section>/var_type] option.

The var_type is how we distinguish between the Variables so that the user can name the section whatever they want. If var_type is not present, then we assume that the var_type is actually the the section name, var_section.

Definition at line 72 of file default_variable_builder.h.

References GRINS::VariablesParsing::variables_section().

Referenced by build_variables_impl().

74  { std::string input_sec = VariablesParsing::variables_section()+"/"+var_section+"/type";
75  return input(input_sec,var_section); }
static std::string variables_section()
Helper function to encapsualte the overall [Variables] section name.

The documentation for this class was generated from the following files:

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