void PrescribedMoleFractionsDirichletOldStyleBCFactory::
  convert_mole_fracs_and_add_to_func
  (const GetPot& input, const std::vector<libMesh::Number>& species_mole_fracs,
   const SpeciesMassFractionsVariable& species_fe_var,
   libMesh::CompositeFunction<libMesh::Number>& composite_func) const
  {
    const std::string& material = species_fe_var.material();

    /*! \todo We should have a ChemsitryWarehouse or something to just
      grab this from one place instead of rebuilding. */
    ChemistryBuilder chem_builder;
    std::unique_ptr<ChemistryType> chem_ptr;
    chem_builder.build_chemistry(input,material,chem_ptr);

    const ChemistryType & chem = *chem_ptr;

    const unsigned int n_vars = species_mole_fracs.size();
    // Compute M
    libMesh::Real M = 0.0;
    for( unsigned int s = 0; s < n_vars; s++ )
      M += species_mole_fracs[s]*chem.M(s);

    // Convert mole fractions to mass fractions and add to function
    for( unsigned int s = 0; s < n_vars; s++ )
      {
        libMesh::Number species_mass_fracs =species_mole_fracs[s]*chem.M(s)/M;

        std::vector<VariableIndex> var_idx(1,species_fe_var.species(s));

        libMesh::ConstFunction<libMesh::Number> const_func(species_mass_fracs);
        composite_func.attach_subfunction(const_func,var_idx);
      }
  }
 void PrescribedVectorValueDirichletOldStyleBCFactory::add_funcs( const GetPot& input,
                                                                  MultiphysicsSystem& system,
                                                                  const std::string& input_string,
                                                                  const std::vector<std::string>& var_names,
                                                                  libMesh::CompositeFunction<libMesh::Number>& composite_func ) const
 {
   for( unsigned int n = 0; n < var_names.size(); n++ )
     {
       std::vector<VariableIndex> dbc_vars(1,system.variable_number(var_names[n]));
       libMesh::Number value = input(input_string, 0.0, n);
       libMesh::ConstFunction<libMesh::Number> const_func(value);
       composite_func.attach_subfunction(const_func, dbc_vars);
     }
 }
Exemplo n.º 3
0
  void ICHandlingBase::init_ic_data( const libMesh::FEMSystem& system,
                                     libMesh::CompositeFunction<libMesh::Number>& all_ics )
  {
    if (this->get_ic_func())
      {
        std::vector<unsigned int> index_map;

        libmesh_assert(_subfunction_variables.size());

        for (unsigned int i=0; i != _subfunction_variables.size();
             ++i)
          index_map.push_back
            (system.variable_number(_subfunction_variables[i]));

        all_ics.attach_subfunction(*this->get_ic_func(), index_map);
      }
  }
Exemplo n.º 4
0
  void ConstantFunctionDirichletBCFactory::add_found_vars( const GetPot& input,
                                                           MultiphysicsSystem& system,
                                                           const std::string& section,
                                                           const std::set<std::string>& vars_found,
                                                           libMesh::CompositeFunction<libMesh::Number>& composite_func,
                                                           std::set<std::string>& vars_added ) const
  {
    libMesh::Number invalid_num = std::numeric_limits<libMesh::Number>::max();

    for( std::set<std::string>::const_iterator var = vars_found.begin();
         var != vars_found.end(); ++var )
      {
        std::vector<VariableIndex> var_idx(1,system.variable_number(*var));

        libMesh::Number value = input(section+"/"+(*var),invalid_num);

        libMesh::ConstFunction<libMesh::Number> const_func(value);
        composite_func.attach_subfunction(const_func,var_idx);
      }

    vars_added = vars_found;
  }
Exemplo n.º 5
0
  void MoleFractionsDirichletBCFactory::add_mole_frac_to_mass_frac(const GetPot& input,
                                                                   const std::string& section,
                                                                   const std::set<std::string>& vars_found,
                                                                   const std::string& material,
                                                                   const SpeciesMassFractionsVariable& species_fe_var,
                                                                   libMesh::CompositeFunction<libMesh::Number>& composite_func,
                                                                   std::set<std::string>& vars_added) const
  {
    unsigned int n_vars_found = vars_found.size();

    // Parse in all the species mole fracs that are in the input (it is assumed non-specified are 0)
    std::vector<libMesh::Number> species_mole_fracs(n_vars_found);
    libMesh::Number invalid_num = std::numeric_limits<libMesh::Number>::max();
    {
      unsigned int count = 0;
      for(std::set<std::string>::const_iterator var = vars_found.begin();
          var != vars_found.end(); ++var )
        {
          species_mole_fracs[count] = input(section+"/"+(*var),invalid_num);
          count++;
        }
    }

    // Make sure mole fracs sum to 1
    libMesh::Number sum = 0.0;
    for(unsigned int v = 0; v < n_vars_found; v++ )
      sum += species_mole_fracs[v];

    libMesh::Number tol = std::numeric_limits<libMesh::Number>::epsilon()*10;
    if( std::abs(sum-1.0) > tol )
      libmesh_error_msg("ERROR: Mole fractions do not sum to 1! Found sum = "+StringUtilities::T_to_string<libMesh::Number>(sum));

    // Extract species names
    std::vector<std::string> species_names(n_vars_found);
    {
      unsigned int count = 0;
      for(std::set<std::string>::const_iterator var = vars_found.begin();
          var != vars_found.end(); ++var )
        {
          std::vector<std::string> split_name;
          // vars_found should have the form "X_<species name>"
          StringUtilities::split_string((*var),"_",split_name);
          libmesh_assert_equal_to(split_name[0],std::string("X"));
          libmesh_assert_equal_to(split_name.size(),2);
          species_names[count] = split_name[1];
          count++;
        }
    }

    // Now convert to mass frac and add to composite function
    /*! \todo We should have a ChemsitryWarehouse or something to just grab this from one place
      instead of rebuilding. */
    ChemistryType chem(input,material);

    libMesh::Real M = 0.0;
    for(unsigned int v = 0; v < n_vars_found; v++ )
      {
        unsigned int s = chem.species_index(species_names[v]);
        M += species_mole_fracs[v]*chem.M(s);
      }

    const std::string& prefix = species_fe_var.prefix();

    for(unsigned int v = 0; v < n_vars_found; v++ )
      {
        // Finish computing species mass fraction
        unsigned int s = chem.species_index(species_names[v]);
        libMesh::Number species_mass_fracs = species_mole_fracs[v]*chem.M(s)/M;

        // Add the function
        std::vector<VariableIndex> var_idx(1,species_fe_var.species(s));
        libMesh::ConstFunction<libMesh::Number> const_func(species_mass_fracs);
        composite_func.attach_subfunction(const_func,var_idx);

        // Log that we added this variable
        vars_added.insert(prefix+species_names[v]);
      }
  }