GRINS-0.8.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-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 // $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  : _physics_name( physics_name )
54  {
55  return;
56  }
57 
59  {
60  return;
61  }
62 
64  ( const libMesh::FunctionBase<libMesh::Number>& initial_val)
65  {
66  _ic_func = initial_val.clone();
67  }
68 
69  void ICHandlingBase::read_ic_data( const GetPot& input, const std::string& id_str,
70  const std::string& ic_str,
71  const std::string& var_str,
72  const std::string& value_str)
73  {
74  int num_ids = input.vector_variable_size(id_str);
75  int num_ics = input.vector_variable_size(ic_str);
76  int num_vars = input.vector_variable_size(var_str);
77  int num_values = input.vector_variable_size(value_str);
78 
79  if( num_ids != num_ics )
80  {
81  std::cerr << "Error: number of subdomain ids " << num_ids
82  << "must equal number of initial condition types " << num_ics
83  << std::endl;
84  libmesh_error();
85  }
86 
87  if( num_ids != num_vars )
88  {
89  std::cerr << "Error: number of subdomain ids " << num_ids
90  << "must equal number of variable name lists " << num_vars
91  << std::endl;
92  libmesh_error();
93  }
94 
95  if( num_ids != num_values )
96  {
97  std::cerr << "Error: number of subdomain ids " << num_ids
98  << "must equal number of initial condition values " << num_values
99  << std::endl;
100  libmesh_error();
101  }
102 
103  if( num_ids > 1 )
104  {
105  std::cerr << "Error: GRINS does not yet support per-subdomain initial conditions" << std::endl;
106  libmesh_not_implemented();
107  }
108 
109  for( int i = 0; i < num_ids; i++ )
110  {
111  int ic_id = input(id_str, -1, i );
112  std::string ic_type_in = input(ic_str, "NULL", i );
113  std::string ic_value_in = input(value_str, "NULL", i );
114  std::string ic_vars_in = input(var_str, "NULL", i );
115 
116  int ic_type = this->string_to_int( ic_type_in );
117 
118  std::stringstream ss;
119  ss << ic_id;
120  std::string ic_id_string = ss.str();
121 
122  this->init_ic_types( ic_id, ic_id_string, ic_type, ic_vars_in, ic_value_in, input );
123  }
124 
125  return;
126  }
127 
128  void ICHandlingBase::init_ic_data( const libMesh::FEMSystem& system,
130  {
131  if (this->get_ic_func())
132  {
133  std::vector<unsigned int> index_map;
134 
135  libmesh_assert(_subfunction_variables.size());
136 
137  for (unsigned int i=0; i != _subfunction_variables.size();
138  ++i)
139  index_map.push_back
140  (system.variable_number(_subfunction_variables[i]));
141 
142  all_ics.attach_subfunction(*this->get_ic_func(), index_map);
143  }
144  }
145 
146  int ICHandlingBase::string_to_int( const std::string& ic_type_in ) const
147  {
148  int ic_type_out;
149  if( ic_type_in == "parsed" )
150  {
151  ic_type_out = PARSED;
152  }
153  else if( ic_type_in == "constant" )
154  {
155  ic_type_out = CONSTANT;
156  }
157  else
158  {
159  std::cerr << "==========================================================" << std::endl
160  << "Error: Invalid ic_type " << ic_type_in << std::endl
161  << " Physics class is " << _physics_name << std::endl
162  << "==========================================================" << std::endl;
163  libmesh_error();
164  }
165  return ic_type_out;
166  }
167 
168  void ICHandlingBase::init_ic_types( const libMesh::subdomain_id_type /*ic_id*/,
169  const std::string& /*ic_id_string*/,
170  const int ic_type,
171  const std::string& ic_vars_string,
172  const std::string& ic_value_string,
173  const GetPot& /*input*/ )
174  {
176 
177  libmesh_assert(_subfunction_variables.size());
178 
179  switch(ic_type)
180  {
181  case(PARSED):
182  {
183  _ic_func = libMesh::UniquePtr<libMesh::FunctionBase<libMesh::Number> >
184  (new libMesh::ParsedFunction<libMesh::Number>(ic_value_string));
185  }
186  break;
187 
188  case(CONSTANT):
189  {
190  _ic_func = libMesh::UniquePtr<libMesh::FunctionBase<libMesh::Number> >
191  (new libMesh::ConstFunction<libMesh::Number>
192  (StringUtilities::string_to_T<libMesh::Number>(ic_value_string)));
193  }
194  break;
195 
196  default:
197  {
198  std::cerr << "=========================================================="
199  << "Error: Invalid IC type for " << _physics_name << std::endl
200  << " Detected IC type was " << ic_type << std::endl
201  << "==========================================================" << std::endl;
202  libmesh_error();
203  }
204  }
205  return;
206  }
207 
208 } // 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
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
libMesh::UniquePtr< libMesh::FunctionBase< libMesh::Number > > _ic_func

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