GRINS-0.6.0
ic_handling_base.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 // $Id$
26 //
27 //--------------------------------------------------------------------------
28 //--------------------------------------------------------------------------
29 
30 // This class
31 #include "grins/ic_handling_base.h"
32 
33 // GRINS
34 #include "grins/string_utils.h"
35 
36 // libMesh
37 #include "libmesh/composite_function.h"
38 #include "libmesh/fem_context.h"
39 #include "libmesh/fem_system.h"
40 #include "libmesh/dof_map.h"
41 #include "libmesh/dirichlet_boundaries.h"
42 #include "libmesh/periodic_boundary.h"
43 #include "libmesh/dof_map.h"
44 #include "libmesh/parsed_function.h"
45 #include "libmesh/const_function.h"
46 
47 // C++
48 #include "sstream"
49 
50 namespace GRINS
51 {
52  ICHandlingBase::ICHandlingBase(const std::string& physics_name)
53  : _ic_func(NULL),
54  _physics_name( physics_name )
55  {
56  return;
57  }
58 
60  {
61  return;
62  }
63 
65  ( const libMesh::FunctionBase<libMesh::Number>& initial_val)
66  {
67  _ic_func = initial_val.clone();
68  }
69 
70  void ICHandlingBase::read_ic_data( const GetPot& input, const std::string& id_str,
71  const std::string& ic_str,
72  const std::string& var_str,
73  const std::string& value_str)
74  {
75  int num_ids = input.vector_variable_size(id_str);
76  int num_ics = input.vector_variable_size(ic_str);
77  int num_vars = input.vector_variable_size(var_str);
78  int num_values = input.vector_variable_size(value_str);
79 
80  if( num_ids != num_ics )
81  {
82  std::cerr << "Error: number of subdomain ids " << num_ids
83  << "must equal number of initial condition types " << num_ics
84  << std::endl;
85  libmesh_error();
86  }
87 
88  if( num_ids != num_vars )
89  {
90  std::cerr << "Error: number of subdomain ids " << num_ids
91  << "must equal number of variable name lists " << num_vars
92  << std::endl;
93  libmesh_error();
94  }
95 
96  if( num_ids != num_values )
97  {
98  std::cerr << "Error: number of subdomain ids " << num_ids
99  << "must equal number of initial condition values " << num_values
100  << std::endl;
101  libmesh_error();
102  }
103 
104  if( num_ids > 1 )
105  {
106  std::cerr << "Error: GRINS does not yet support per-subdomain initial conditions" << std::endl;
107  libmesh_not_implemented();
108  }
109 
110  for( int i = 0; i < num_ids; i++ )
111  {
112  int ic_id = input(id_str, -1, i );
113  std::string ic_type_in = input(ic_str, "NULL", i );
114  std::string ic_value_in = input(value_str, "NULL", i );
115  std::string ic_vars_in = input(var_str, "NULL", i );
116 
117  int ic_type = this->string_to_int( ic_type_in );
118 
119  std::stringstream ss;
120  ss << ic_id;
121  std::string ic_id_string = ss.str();
122 
123  this->init_ic_types( ic_id, ic_id_string, ic_type, ic_vars_in, ic_value_in, input );
124  }
125 
126  return;
127  }
128 
129  void ICHandlingBase::init_ic_data( const libMesh::FEMSystem& system,
131  {
132  if (this->get_ic_func())
133  {
134  std::vector<unsigned int> index_map;
135 
136  libmesh_assert(_subfunction_variables.size());
137 
138  for (unsigned int i=0; i != _subfunction_variables.size();
139  ++i)
140  index_map.push_back
141  (system.variable_number(_subfunction_variables[i]));
142 
143  all_ics.attach_subfunction(*this->get_ic_func(), index_map);
144  }
145  }
146 
147  int ICHandlingBase::string_to_int( const std::string& ic_type_in ) const
148  {
149  int ic_type_out;
150  if( ic_type_in == "parsed" )
151  {
152  ic_type_out = PARSED;
153  }
154  else if( ic_type_in == "constant" )
155  {
156  ic_type_out = CONSTANT;
157  }
158  else
159  {
160  std::cerr << "==========================================================" << std::endl
161  << "Error: Invalid ic_type " << ic_type_in << std::endl
162  << " Physics class is " << _physics_name << std::endl
163  << "==========================================================" << std::endl;
164  libmesh_error();
165  }
166  return ic_type_out;
167  }
168 
169  void ICHandlingBase::init_ic_types( const libMesh::subdomain_id_type /*ic_id*/,
170  const std::string& /*ic_id_string*/,
171  const int ic_type,
172  const std::string& ic_vars_string,
173  const std::string& ic_value_string,
174  const GetPot& /*input*/ )
175  {
177 
178  libmesh_assert(_subfunction_variables.size());
179 
180  switch(ic_type)
181  {
182  case(PARSED):
183  {
184  _ic_func = libMesh::AutoPtr<libMesh::FunctionBase<libMesh::Number> >
185  (new libMesh::ParsedFunction<libMesh::Number>(ic_value_string));
186  }
187  break;
188 
189  case(CONSTANT):
190  {
191  _ic_func = libMesh::AutoPtr<libMesh::FunctionBase<libMesh::Number> >
192  (new libMesh::ConstFunction<libMesh::Number>
193  (StringUtilities::string_to_T<libMesh::Number>(ic_value_string)));
194  }
195  break;
196 
197  default:
198  {
199  std::cerr << "=========================================================="
200  << "Error: Invalid IC type for " << _physics_name << std::endl
201  << " Detected IC type was " << ic_type << std::endl
202  << "==========================================================" << std::endl;
203  libmesh_error();
204  }
205  }
206  return;
207  }
208 
209 } // namespace GRINS
void attach_initial_func(const libMesh::FunctionBase< libMesh::Number > &initial_val)
libMesh::FunctionBase< libMesh::Number > * get_ic_func() const
GRINS namespace.
virtual void init_ic_types(const libMesh::subdomain_id_type ic_id, const std::string &ic_id_string, const int ic_type, const std::string &ic_vars_string, const std::string &ic_value_string, const GetPot &input)
ICHandlingBase(const std::string &physics_name)
virtual void read_ic_data(const GetPot &input, const std::string &id_str, const std::string &ic_str, const std::string &var_str, const std::string &value_str)
virtual int string_to_int(const std::string &bc_type_in) const
libMesh::AutoPtr< libMesh::FunctionBase< libMesh::Number > > _ic_func
std::vector< std::string > _subfunction_variables
virtual void init_ic_data(const libMesh::FEMSystem &system, libMesh::CompositeFunction< libMesh::Number > &all_ics)
Override this method to initialize any system-dependent data.
void split_string(const std::string &input, const std::string &delimiter, std::vector< std::string > &results)
Definition: string_utils.C:31

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