2 #include "femparameters.h" 
    4 #include "libmesh/parsed_function.h" 
    5 #include "libmesh/zero_function.h" 
    6 #include "libmesh/auto_ptr.h"  
    8 #include <unordered_set> 
   12 #define GETPOT_INPUT(A) { A = input(#A, A);                             \ 
   13     variable_names.insert(#A);                                          \ 
   14     const std::string stringval = input(#A, std::string());             \ 
   15     variable_assignments.push_back(std::string(#A "=") + stringval); } 
   16 #define GETPOT_INT_INPUT(A) { A = input(#A, (int)A);                    \ 
   17     variable_names.insert(#A);                                          \ 
   18     const std::string stringval = input(#A, std::string());             \ 
   19     variable_assignments.push_back(std::string(#A "=") + stringval); } 
   21 #define GETPOT_REGISTER(A) {                                            \ 
   22     variable_names.insert(#A);                                          \ 
   23     std::string stringval = input(#A, std::string());                   \ 
   24     variable_assignments.push_back(std::string(#A "=") + stringval); } 
   28   initial_timestep(0), n_timesteps(100),
 
   31   timesolver_core(
"euler"),
 
   32   end_time(
std::numeric_limits<
Real>::max()),
 
   33   deltat(0.0001), timesolver_theta(0.5),
 
   34   timesolver_maxgrowth(0.), timesolver_tolerance(0.),
 
   35   timesolver_upper_tolerance(0.),
 
   36   steadystate_tolerance(0.),
 
   37   timesolver_norm(0, 
L2),
 
   40   domaintype(
"square"), domainfile(
"mesh.xda"), elementtype(
"quad"),
 
   42   domain_xmin(0.0), domain_ymin(0.0), domain_zmin(0.0),
 
   43   domain_edge_width(1.0), domain_edge_length(1.0), domain_edge_height(1.0),
 
   44   coarsegridx(1), coarsegridy(1), coarsegridz(1),
 
   45   coarserefinements(0), extrarefinements(0),
 
   46   mesh_redistribute_func(
"0"),
 
   48   mesh_partitioner_type(
"Default"),
 
   50   nelem_target(8000), global_tolerance(0.0),
 
   51   refine_fraction(0.3), coarsen_fraction(0.3), coarsen_threshold(10),
 
   53   initial_adaptivesteps(0),
 
   56   write_gmv_error(false), write_tecplot_error(false),
 
   57   write_exodus_error(false),
 
   58   output_xda(false), output_xdr(false),
 
   59   output_bz2(true), output_gz(true),
 
   60   output_gmv(false), output_tecplot(false),
 
   61   output_exodus(false), output_nemesis(false),
 
   65 #ifdef LIBMESH_ENABLE_PERIODIC
 
   66   periodic_boundaries(0),
 
   69   run_simulation(true), run_postprocess(false),
 
   71   fe_family(1, 
"LAGRANGE"), fe_order(1, 1),
 
   72   extra_quadrature_order(0),
 
   74   analytic_jacobians(true), verify_analytic_jacobians(0.0),
 
   76   print_solution_norms(false), print_solutions(false),
 
   77   print_residual_norms(false), print_residuals(false),
 
   78   print_jacobian_norms(false), print_jacobians(false),
 
   79   print_element_solutions(false),
 
   80   print_element_residuals(false),
 
   81   print_element_jacobians(false),
 
   83   use_petsc_snes(false),
 
   84   time_solver_quiet(true), solver_quiet(true), solver_verbose(false),
 
   85   reuse_preconditioner(true),
 
   86   require_residual_reduction(true),
 
   87   min_step_length(1e-5),
 
   88   max_linear_iterations(200000), max_nonlinear_iterations(20),
 
   89   relative_step_tolerance(1.e-7), relative_residual_tolerance(1.e-10),
 
   90   absolute_residual_tolerance(1.e-10),
 
   92   linear_tolerance_multiplier(1.e-3),
 
   94   initial_sobolev_order(1),
 
   95   initial_extra_quadrature(0),
 
   96   refine_uniformly(false),
 
   97   indicator_type(
"kelly"), patch_reuse(true), sobolev_order(1)
 
  124            j = i->second.begin(); j != i->second.end();
 
  134            j = i->second.begin(); j != i->second.end();
 
  141                                                         const std::string & func_value)
 
  143   if (func_type == 
"parsed")
 
  144     return libmesh_make_unique<ParsedFunction<Number>>(func_value);
 
  145   else if (func_type == 
"zero")
 
  146     return libmesh_make_unique<ZeroFunction<Number>>();
 
  148     libmesh_not_implemented();
 
  150   return std::unique_ptr<FunctionBase<Number>>();
 
  155                          const std::vector<std::string> * other_variable_names)
 
  157   std::vector<std::string> variable_assignments;
 
  158   std::unordered_set<std::string> variable_names;
 
  159   if (other_variable_names)
 
  160     for (std::size_t i=0; i != other_variable_names->size(); ++i)
 
  162         const std::string & 
name = (*other_variable_names)[i];
 
  163         const std::string stringval = input(
name, std::string());
 
  164         variable_assignments.push_back(
name + 
"=" + stringval);
 
  169   GETPOT_INPUT(
transient);
 
  181   const unsigned int n_timesolver_norm = input.vector_variable_size(
"timesolver_norm");
 
  183   for (
unsigned int i=0; i != n_timesolver_norm; ++i)
 
  185       int current_norm = 0; 
 
  190       current_norm = input(
"timesolver_norm", current_norm, i);
 
  191       if (current_norm == 0)
 
  193       else if (current_norm == 1)
 
  195       else if (current_norm == 2)
 
  237 #ifndef LIBMESH_HAVE_GZSTREAM 
  241 #ifndef LIBMESH_HAVE_BZ2 
  246 #ifndef LIBMESH_HAVE_GMV 
  252 #ifndef LIBMESH_HAVE_TECPLOT_API 
  258 #ifndef LIBMESH_HAVE_EXODUS_API 
  263 #ifndef LIBMESH_HAVE_NEMESIS_API 
  269   const unsigned int n_system_types =
 
  270     input.vector_variable_size(
"system_types");
 
  274       for (
unsigned int i=0; i != n_system_types; ++i)
 
  281 #ifdef LIBMESH_ENABLE_PERIODIC 
  283   const unsigned int n_periodic_bcs =
 
  284     input.vector_variable_size(
"periodic_boundaries");
 
  293           libMesh::out << 
"Periodic boundaries need rectilinear domains" << std::endl;;
 
  296       for (
unsigned int i=0; i != n_periodic_bcs; ++i)
 
  298           const unsigned int myboundary =
 
  299             input(
"periodic_boundaries", -1, i);
 
  315                   myboundary << std::endl;;
 
  335                   myboundary << std::endl;;
 
  343 #endif // LIBMESH_ENABLE_PERIODIC 
  347   std::string zero_string = 
"zero";
 
  348   std::string empty_string = 
"";
 
  350   GETPOT_REGISTER(dirichlet_condition_types);
 
  351   GETPOT_REGISTER(dirichlet_condition_values);
 
  352   GETPOT_REGISTER(dirichlet_condition_boundaries);
 
  355   const unsigned int n_dirichlet_conditions=
 
  356     input.vector_variable_size(
"dirichlet_condition_types");
 
  358   if (n_dirichlet_conditions !=
 
  359       input.vector_variable_size(
"dirichlet_condition_values"))
 
  362                    << 
" Dirichlet condition types does not match " 
  363                    << input.vector_variable_size(
"dirichlet_condition_values")
 
  364                    << 
" Dirichlet condition values." << std::endl;
 
  369   if (n_dirichlet_conditions !=
 
  370       input.vector_variable_size(
"dirichlet_condition_boundaries"))
 
  373                    << 
" Dirichlet condition types does not match " 
  374                    << input.vector_variable_size(
"dirichlet_condition_boundaries")
 
  375                    << 
" Dirichlet condition boundaries." << std::endl;
 
  380   if (n_dirichlet_conditions !=
 
  381       input.vector_variable_size(
"dirichlet_condition_variables"))
 
  384                    << 
" Dirichlet condition types does not match " 
  385                    << input.vector_variable_size(
"dirichlet_condition_variables")
 
  386                    << 
" Dirichlet condition variables sets." << std::endl;
 
  391   for (
unsigned int dc=0; dc != n_dirichlet_conditions; ++dc)
 
  393       const std::string func_type =
 
  394         input(
"dirichlet_condition_types", zero_string, dc);
 
  396       const std::string func_value =
 
  397         input(
"dirichlet_condition_values", empty_string, dc);
 
  405       const std::string variable_set =
 
  406         input(
"dirichlet_condition_variables", empty_string, dc);
 
  408       for (
unsigned int i=0; i != variable_set.size(); ++i)
 
  410           if (variable_set[i] == 
'1')
 
  412           else if (variable_set[i] != 
'0')
 
  414               libMesh::out << 
"Unable to understand Dirichlet variable set" 
  415                            << variable_set << std::endl;
 
  421   GETPOT_REGISTER(neumann_condition_types);
 
  422   GETPOT_REGISTER(neumann_condition_values);
 
  423   GETPOT_REGISTER(neumann_condition_boundaries);
 
  426   const unsigned int n_neumann_conditions=
 
  427     input.vector_variable_size(
"neumann_condition_types");
 
  429   if (n_neumann_conditions !=
 
  430       input.vector_variable_size(
"neumann_condition_values"))
 
  433                    << 
" Neumann condition types does not match " 
  434                    << input.vector_variable_size(
"neumann_condition_values")
 
  435                    << 
" Neumann condition values." << std::endl;
 
  440   if (n_neumann_conditions !=
 
  441       input.vector_variable_size(
"neumann_condition_boundaries"))
 
  444                    << 
" Neumann condition types does not match " 
  445                    << input.vector_variable_size(
"neumann_condition_boundaries")
 
  446                    << 
" Neumann condition boundaries." << std::endl;
 
  451   if (n_neumann_conditions !=
 
  452       input.vector_variable_size(
"neumann_condition_variables"))
 
  455                    << 
" Neumann condition types does not match " 
  456                    << input.vector_variable_size(
"neumann_condition_variables")
 
  457                    << 
" Neumann condition variables sets." << std::endl;
 
  462   for (
unsigned int nc=0; nc != n_neumann_conditions; ++nc)
 
  464       const std::string func_type =
 
  465         input(
"neumann_condition_types", zero_string, nc);
 
  467       const std::string func_value =
 
  468         input(
"neumann_condition_values", empty_string, nc);
 
  476       const std::string variable_set =
 
  477         input(
"neumann_condition_variables", empty_string, nc);
 
  479       for (
unsigned int i=0; i != variable_set.size(); ++i)
 
  481           if (variable_set[i] == 
'1')
 
  483           else if (variable_set[i] != 
'0')
 
  485               libMesh::out << 
"Unable to understand Neumann variable set" 
  486                            << variable_set << std::endl;
 
  492   GETPOT_REGISTER(initial_condition_types);
 
  493   GETPOT_REGISTER(initial_condition_values);
 
  494   GETPOT_REGISTER(initial_condition_subdomains);
 
  496   const unsigned int n_initial_conditions=
 
  497     input.vector_variable_size(
"initial_condition_types");
 
  499   if (n_initial_conditions !=
 
  500       input.vector_variable_size(
"initial_condition_values"))
 
  503                    << 
" initial condition types does not match " 
  504                    << input.vector_variable_size(
"initial_condition_values")
 
  505                    << 
" initial condition values." << std::endl;
 
  510   if (n_initial_conditions !=
 
  511       input.vector_variable_size(
"initial_condition_subdomains"))
 
  514                    << 
" initial condition types does not match " 
  515                    << input.vector_variable_size(
"initial_condition_subdomains")
 
  516                    << 
" initial condition subdomains." << std::endl;
 
  521   for (
unsigned int i=0; i != n_initial_conditions; ++i)
 
  523       const std::string func_type =
 
  524         input(
"initial_condition_types", zero_string, i);
 
  526       const std::string func_value =
 
  527         input(
"initial_condition_values", empty_string, i);
 
  536   GETPOT_REGISTER(other_interior_function_types);
 
  537   GETPOT_REGISTER(other_interior_function_values);
 
  538   GETPOT_REGISTER(other_interior_function_subdomains);
 
  539   GETPOT_REGISTER(other_interior_function_ids);
 
  541   const unsigned int n_other_interior_functions =
 
  542     input.vector_variable_size(
"other_interior_function_types");
 
  544   if (n_other_interior_functions !=
 
  545       input.vector_variable_size(
"other_interior_function_values"))
 
  548                    << 
" other interior function types does not match " 
  549                    << input.vector_variable_size(
"other_interior_function_values")
 
  550                    << 
" other interior function values." << std::endl;
 
  555   if (n_other_interior_functions !=
 
  556       input.vector_variable_size(
"other_interior_function_subdomains"))
 
  559                    << 
" other interior function types does not match " 
  560                    << input.vector_variable_size(
"other_interior_function_subdomains")
 
  561                    << 
" other interior function subdomains." << std::endl;
 
  566   if (n_other_interior_functions !=
 
  567       input.vector_variable_size(
"other_interior_function_ids"))
 
  570                    << 
" other interior function types does not match " 
  571                    << input.vector_variable_size(
"other_interior_function_ids")
 
  572                    << 
" other interior function ids." << std::endl;
 
  577   for (
unsigned int i=0; i != n_other_interior_functions; ++i)
 
  579       const std::string func_type =
 
  580         input(
"other_interior_function_types", zero_string, i);
 
  582       const std::string func_value =
 
  583         input(
"other_interior_function_values", empty_string, i);
 
  589         input(
"other_interior_condition_ids", 
int(0), i);
 
  595   GETPOT_REGISTER(other_boundary_function_types);
 
  596   GETPOT_REGISTER(other_boundary_function_values);
 
  597   GETPOT_REGISTER(other_boundary_function_boundaries);
 
  598   GETPOT_REGISTER(other_boundary_function_ids);
 
  600   const unsigned int n_other_boundary_functions =
 
  601     input.vector_variable_size(
"other_boundary_function_types");
 
  603   if (n_other_boundary_functions !=
 
  604       input.vector_variable_size(
"other_boundary_function_values"))
 
  607                    << 
" other boundary function types does not match " 
  608                    << input.vector_variable_size(
"other_boundary_function_values")
 
  609                    << 
" other boundary function values." << std::endl;
 
  614   if (n_other_boundary_functions !=
 
  615       input.vector_variable_size(
"other_boundary_function_boundaries"))
 
  618                    << 
" other boundary function types does not match " 
  619                    << input.vector_variable_size(
"other_boundary_function_boundaries")
 
  620                    << 
" other boundary function boundaries." << std::endl;
 
  625   if (n_other_boundary_functions !=
 
  626       input.vector_variable_size(
"other_boundary_function_ids"))
 
  629                    << 
" other boundary function types does not match " 
  630                    << input.vector_variable_size(
"other_boundary_function_ids")
 
  631                    << 
" other boundary function ids." << std::endl;
 
  636   for (
unsigned int i=0; i != n_other_boundary_functions; ++i)
 
  638       const std::string func_type =
 
  639         input(
"other_boundary_function_types", zero_string, i);
 
  641       const std::string func_value =
 
  642         input(
"other_boundary_function_values", empty_string, i);
 
  648         input(
"other_boundary_function_ids", 
int(0), i);
 
  659   const unsigned int n_fe_family =
 
  660     std::max(1u, input.vector_variable_size(
"fe_family"));
 
  661   fe_family.resize(n_fe_family, 
"LAGRANGE");
 
  662   for (
unsigned int i=0; i != n_fe_family; ++i)
 
  665   const unsigned int n_fe_order =
 
  666     input.vector_variable_size(
"fe_order");
 
  668   for (
unsigned int i=0; i != n_fe_order; ++i)
 
  713   std::vector<std::string> bad_variables =
 
  714     input.unidentified_arguments(variable_assignments);
 
  719   std::vector<std::string> actually_bad_variables;
 
  720   for (std::size_t i = 0; i < bad_variables.size(); ++i)
 
  724       if (bad_variables[i].empty() || bad_variables[i][0] != 
'-')
 
  726           std::string bad_variable_name =
 
  727             bad_variables[i].substr(0, bad_variables[i].find(
'='));
 
  728           if (!variable_names.count(bad_variable_name))
 
  729             actually_bad_variables.push_back(bad_variables[i]);
 
  735         if (bad_variables.size() > (i+1) &&
 
  736             !bad_variables[i+1].empty() &&
 
  737             bad_variables[i+1][0] != 
'-')
 
  741   if (this->
comm().rank() == 0 && !actually_bad_variables.empty())
 
  743       libMesh::err << 
"ERROR: Unrecognized variables:" << std::endl;
 
  744       for (
auto var : actually_bad_variables)
 
  746       libMesh::err << 
"Not found among recognized variables:" << std::endl;
 
  747       for (std::size_t i = 0; i != variable_names.size(); ++i)