GRINS-0.7.0
single_fe_type_variable.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
27 
28 // GRINS
29 #include "grins/common.h"
30 
31 // libMesh
32 #include "libmesh/getpot.h"
33 #include "libmesh/string_to_enum.h"
34 #include "libmesh/fem_system.h"
35 
36 namespace GRINS
37 {
38 
40  const std::string& physics_name,
41  const std::string& old_var_prefix,
42  const std::string& subsection,
43  const std::string& default_family,
44  const std::string& default_order,
45  bool _is_constraint_var )
46  : FEVariablesBase(_is_constraint_var)
47  {
48  _family.resize(1,libMesh::INVALID_FE);
49  _order.resize(1,libMesh::INVALID_ORDER);
50 
51  this->parse_family_and_order(input,
52  physics_name,
53  old_var_prefix,
54  subsection,
55  _family,
56  _order,
57  default_family,
58  default_order);
59 
60  libmesh_assert_not_equal_to( _family[0], libMesh::INVALID_FE);
61  libmesh_assert_not_equal_to( _order[0], libMesh::INVALID_ORDER);
62  }
63 
65  const std::string& subsection,
66  bool _is_constraint_var)
67  : FEVariablesBase(_is_constraint_var)
68  {
69  _family.resize(1,libMesh::INVALID_FE);
70  _order.resize(1,libMesh::INVALID_ORDER);
71 
72  this->parse_new_style(input, subsection, _family[0], _order[0]);
73 
74  libmesh_assert_not_equal_to( _family[0], libMesh::INVALID_FE);
75  libmesh_assert_not_equal_to( _order[0], libMesh::INVALID_ORDER);
76  }
77 
78  void SingleFETypeVariable::init( libMesh::FEMSystem* system )
79  {
80  // Make sure there's only one order and family
81  libmesh_assert_equal_to(_order.size(), 1);
82  libmesh_assert_equal_to(_family.size(), 1);
83 
84  const unsigned int n_vars = _var_names.size();
85  _vars.resize(n_vars);
86 
87  for( unsigned int v = 0; v < n_vars; v++ )
88  _vars[v] = system->add_variable( _var_names[v], _order[0], _family[0]);
89  }
90 
92  const std::string& physics_name,
93  const std::string& old_var_prefix,
94  const std::string& subsection,
95  std::vector<GRINSEnums::FEFamily>& family,
96  std::vector<GRINSEnums::Order>& order,
97  const std::string& default_family,
98  const std::string& default_order )
99  {
100  libmesh_assert_equal_to( family.size(), 1 );
101  libmesh_assert_equal_to( family.size(), order.size() );
102 
103  // Check if FEfamily/order set in both old style and new style.
104  // Errors out if both are present.
105  this->dup_family_order_check(input,physics_name,old_var_prefix);
106 
107  // If there's nothing about family or order, then we'll use the defaults.
108  // This is deprecated.
109  if( !this->have_family_or_order(input,physics_name,old_var_prefix,subsection) )
110  {
111  std::string warning = "WARNING: Could not find input for FE family and order for Variable "+subsection+".\n";
112  warning += " Using default values: FEFamily = "+default_family+", Order = "+default_order+"\n";
113  warning += " THIS IS DEPRECATED. In the future, you explicitly specify these in your input file\n";
114  warning += " using: [Variables/"+subsection+"/fe_family] and [Variables/"+subsection+"/order].\n";
115  grins_warning(warning);
116 
117  family[0] = libMesh::Utility::string_to_enum<GRINSEnums::FEFamily>(default_family);
118  order[0] = libMesh::Utility::string_to_enum<GRINSEnums::Order>(default_order);
119  }
120  // So here we know we have one or the other
121  else
122  {
123  // If we got here, there was one or the other, but it's possible they only specified one of them
124  // so we default to the default value in this case.
125  // Using this style of input is deprecated.
126  if( input.have_variable("Physics/"+physics_name+"/"+old_var_prefix+"FE_family") ||
127  input.have_variable("Physics/"+physics_name+"/"+old_var_prefix+"order"))
128  {
129  this->parse_old_style_with_warning(input,physics_name,"",default_family,default_order,
130  subsection,family[0],order[0]);
131  }
132  // Some of the old style didn't have the "prefix"
133  else if( input.have_variable("Physics/"+physics_name+"/FE_family") ||
134  input.have_variable("Physics/"+physics_name+"/order"))
135  {
136  this->parse_old_style_with_warning(input,physics_name,"",default_family,default_order,
137  subsection,family[0],order[0]);
138  }
139  // We must be using the new style
140  else
141  {
142  this->parse_new_style(input,subsection,family[0],order[0]);
143  }
144  }
145  }
146 
148  const std::string& physics_name,
149  const std::string& old_var_prefix,
150  const std::string& default_family,
151  const std::string& default_order,
152  const std::string& subsection,
153  GRINSEnums::FEFamily& family,
154  GRINSEnums::Order& order )
155  {
156  std::string warning = "WARNING: Specifying Physics/"+physics_name+"/"+old_var_prefix+"FE_family and\n";
157  warning += " Physics/"+physics_name+"/"+old_var_prefix+"order is DEPRECATED! Please update and use\n";
158  warning += " [Variables/"+subsection+"/fe_family] and [Variables/"+subsection+"/order].\n";
159  grins_warning(warning);
160 
161  std::string family_in = input("Variables/"+subsection+"/fe_family", default_family );
162  std::string order_in = input("Variables/"+subsection+"/order", default_order );
163 
164  family = libMesh::Utility::string_to_enum<GRINSEnums::FEFamily>(family_in);
165  order = libMesh::Utility::string_to_enum<GRINSEnums::Order>(order_in);
166  }
167 
169  const std::string& physics_name,
170  const std::string& old_var_prefix ) const
171  {
172  // We'll error out if there's even a [Variables] section and the old style
173  // in order to be conservative.
174  if( ( input.have_variable("Physics/"+physics_name+"/FE_family") ||
175  input.have_variable("Physics/"+physics_name+"/order") ||
176  input.have_variable("Physics/"+physics_name+"/"+old_var_prefix+"FE_family") ||
177  input.have_variable("Physics/"+physics_name+"/"+old_var_prefix+"order")) &&
178  input.have_section("Variables") )
179  libmesh_error_msg("ERROR: Cannot have a [Variables] section and deprecated FE_family/order input style!");
180  }
181 
182  void SingleFETypeVariable::parse_new_style( const GetPot& input,
183  const std::string& subsection,
184  GRINSEnums::FEFamily& family,
185  GRINSEnums::Order& order )
186  {
187  // Both options must've been specified
188  if( !input.have_variable("Variables/"+subsection+"/fe_family") )
189  libmesh_error_msg("ERROR: Could not find Variables/"+subsection+"/fe_family in input!");
190 
191  if( !input.have_variable("Variables/"+subsection+"/order") )
192  libmesh_error_msg("ERROR: Could not find Variables/"+subsection+"/order in input!");
193 
194  std::string family_in = input("Variables/"+subsection+"/fe_family", "DIE!");
195  std::string order_in = input("Variables/"+subsection+"/order", "DIE!");
196 
197  family = libMesh::Utility::string_to_enum<GRINSEnums::FEFamily>(family_in);
198  order = libMesh::Utility::string_to_enum<GRINSEnums::Order>(order_in);
199  }
200 
202  const std::string& physics_name,
203  const std::string& old_var_prefix,
204  const std::string& subsection ) const
205  {
206  bool have_family_or_order = false;
207 
208  if( input.have_variable("Physics/"+physics_name+"/FE_family") ||
209  input.have_variable("Physics/"+physics_name+"/order") ||
210  input.have_variable("Physics/"+physics_name+"/"+old_var_prefix+"FE_family") ||
211  input.have_variable("Physics/"+physics_name+"/"+old_var_prefix+"order") ||
212  input.have_variable("Variables/"+subsection+"/fe_family") ||
213  input.have_variable("Variables/"+subsection+"/order") )
214  have_family_or_order = true;
215 
216  return have_family_or_order;
217  }
218 
219 } // end namespace GRINS
void dup_family_order_check(const GetPot &input, const std::string &physics_name, const std::string &old_var_prefix) const
Check (and error if true) for old and new style FEFamily/Order input.
std::vector< GRINSEnums::FEFamily > _family
std::vector< GRINSEnums::Order > _order
bool have_family_or_order(const GetPot &input, const std::string &physics_name, const std::string &old_var_prefix, const std::string &subsection) const
Check for no presence of FEFamily/Order input.
void parse_new_style(const GetPot &input, const std::string &subsection, GRINSEnums::FEFamily &family, GRINSEnums::Order &order)
#define grins_warning(message)
Definition: common.h:34
virtual void init(libMesh::FEMSystem *system)
Add variables to the system.
void parse_old_style_with_warning(const GetPot &input, const std::string &physics_name, const std::string &old_var_prefix, const std::string &default_family, const std::string &default_order, const std::string &subsection, GRINSEnums::FEFamily &family, GRINSEnums::Order &order)
SingleFETypeVariable(const GetPot &input, const std::string &physics_name, const std::string &old_var_prefix, const std::string &subsection, const std::string &default_family, const std::string &default_order, bool is_constraint_var)
Deprecated, old style constructor.
GRINS namespace.
void parse_family_and_order(const GetPot &input, const std::string &physics_name, const std::string &old_var_prefix, const std::string &subsection, std::vector< GRINSEnums::FEFamily > &family, std::vector< GRINSEnums::Order > &order, const std::string &default_family, const std::string &default_order)
Helper function to parse FEFamily and Order.
std::vector< std::string > _var_names
std::vector< VariableIndex > _vars

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