void DerivedRBConstruction<RBConstruction>::load_rb_solution()
{
  START_LOG("load_rb_solution()", "DerivedRBConstruction");

  solution->zero();

  if(get_rb_evaluation().RB_solution.size() > get_rb_evaluation().get_n_basis_functions())
  {
    libMesh::err << "ERROR: rb_eval contains " << get_rb_evaluation().get_n_basis_functions() << " basis functions."
                 << " RB_solution vector constains " << get_rb_evaluation().RB_solution.size() << " entries."
                 << " RB_solution in RBConstruction::load_rb_solution is too long!" << std::endl;
    libmesh_error();
  }

  DerivedRBEvaluation<RBEvaluation>& der_rb_eval =
    libmesh_cast_ref<DerivedRBEvaluation<RBEvaluation>&>(get_rb_evaluation());

  EquationSystems& es = this->get_equation_systems();
  RBConstruction& uber_system = es.get_system<RBConstruction>(uber_system_name);

  for(unsigned int i=0; i<get_rb_evaluation().RB_solution.size(); i++)
    for(unsigned int j=0; j<uber_system.get_rb_evaluation().get_n_basis_functions(); j++)
    {
      solution->add(get_rb_evaluation().RB_solution(i)*der_rb_eval.derived_basis_functions[i](j),
                    uber_system.get_rb_evaluation().get_basis_function(j));
    }

  update();

  STOP_LOG("load_rb_solution()", "DerivedRBConstruction");
}
Real DerivedRBConstruction<RBConstruction>::truth_solve(int plot_solution)
{
  START_LOG("truth_solve()", "DerivedRBConstruction");

  EquationSystems& es = this->get_equation_systems();
  RBConstruction& uber_system = es.get_system<RBConstruction>(uber_system_name);

  set_uber_current_parameters();

  uber_system.get_rb_evaluation().set_parameters(uber_system.get_parameters());
  uber_system.get_rb_evaluation().rb_solve(uber_system.get_rb_evaluation().get_n_basis_functions());

  if(plot_solution > 0)
  {
    uber_system.load_rb_solution();
    *solution = *(uber_system.solution);

#ifdef LIBMESH_HAVE_EXODUS_API
    ExodusII_IO(get_mesh()).write_equation_systems ("unter_uber_truth.e",
                                              this->get_equation_systems());
#endif
  }

  STOP_LOG("truth_solve()", "DerivedRBConstruction");

  // Don't bother returning the norm of the uber solution
  return 0.;
}
Exemple #3
0
void RBEvaluation::clear()
{
  START_LOG("clear()", "RBEvaluation");

  // Clear the basis functions
  for(unsigned int i=0; i<basis_functions.size(); i++)
  {
    if (basis_functions[i])
    {
      basis_functions[i]->clear();
      delete basis_functions[i];
      basis_functions[i] = NULL;
    }
  }
  set_n_basis_functions(0);

  clear_riesz_representors();

  // Clear the Greedy param list
  for(unsigned int i=0; i<greedy_param_list.size(); i++)
    greedy_param_list[i].clear();
  greedy_param_list.clear();

  STOP_LOG("clear()", "RBEvaluation");
}
Exemple #4
0
void NewmarkSystem::update_rhs ()
{
  START_LOG("update_rhs ()", "NewmarkSystem");

  // zero the rhs-vector
  NumericVector<Number> & the_rhs = *this->rhs;
  the_rhs.zero();

  // get writable references to some vectors
  NumericVector<Number> & rhs_m = this->get_vector("rhs_m");
  NumericVector<Number> & rhs_c = this->get_vector("rhs_c");


  // zero the vectors for matrix-vector product
  rhs_m.zero();
  rhs_c.zero();

  // compute auxiliary vectors rhs_m and rhs_c
  rhs_m.add(_a_0, this->get_vector("displacement"));
  rhs_m.add(_a_2, this->get_vector("velocity"));
  rhs_m.add(_a_3, this->get_vector("acceleration"));

  rhs_c.add(_a_1, this->get_vector("displacement"));
  rhs_c.add(_a_4, this->get_vector("velocity"));
  rhs_c.add(_a_5, this->get_vector("acceleration"));

  // compute rhs
  the_rhs.add(this->get_vector("force"));
  the_rhs.add_vector(rhs_m, this->get_matrix("mass"));
  the_rhs.add_vector(rhs_c, this->get_matrix("damping"));

  STOP_LOG("update_rhs ()", "NewmarkSystem");
}
Exemple #5
0
std::pair<unsigned int,Real> RBSCMConstruction::compute_SCM_bounds_on_training_set()
{
  START_LOG("compute_SCM_bounds_on_training_set()", "RBSCMConstruction");

  // Now compute the maximum bound error over training_parameters
  unsigned int new_C_J_index = 0;
  Real max_SCM_error = 0.;

  unsigned int first_index = get_first_local_training_index();
  for(unsigned int i=0; i<get_local_n_training_samples(); i++)
  {
    set_params_from_training_set(first_index+i);
    rb_scm_eval->set_parameters( get_parameters() );
    Real LB = rb_scm_eval->get_SCM_LB();
    Real UB = rb_scm_eval->get_SCM_UB();

    Real error_i = SCM_greedy_error_indicator(LB, UB);

    if( error_i > max_SCM_error )
    {
      max_SCM_error = error_i;
      new_C_J_index = i;
    }
  }

  unsigned int global_index = first_index + new_C_J_index;
  std::pair<unsigned int,Real> error_pair(global_index, max_SCM_error);
  get_global_max_error_pair(this->comm(),error_pair);

  STOP_LOG("compute_SCM_bounds_on_training_set()", "RBSCMConstruction");

  return error_pair;
}
Exemple #6
0
void RBSCMConstruction::enrich_C_J(unsigned int new_C_J_index)
{
  START_LOG("enrich_C_J()", "RBSCMConstruction");

  set_params_from_training_set_and_broadcast(new_C_J_index);

  rb_scm_eval->C_J.push_back(get_parameters());

  libMesh::out << std::endl << "SCM: Added mu = (";

  RBParameters::const_iterator it     = get_parameters().begin();
  RBParameters::const_iterator it_end = get_parameters().end();
  for( ; it != it_end; ++it)
  {
    if(it != get_parameters().begin()) libMesh::out << ",";
    std::string param_name = it->first;
    RBParameters C_J_params = rb_scm_eval->C_J[rb_scm_eval->C_J.size()-1];
    libMesh::out << C_J_params.get_value(param_name);
  }
  libMesh::out << ")" << std::endl;

  // Finally, resize C_J_stability_vector and SCM_UB_vectors
  rb_scm_eval->C_J_stability_vector.push_back(0.);

  std::vector<Real> zero_vector(get_rb_theta_expansion().get_n_A_terms());
  rb_scm_eval->SCM_UB_vectors.push_back(zero_vector);

  STOP_LOG("enrich_C_J()", "RBSCMConstruction");
}
Exemple #7
0
void RBSCMConstruction::compute_SCM_bounding_box()
{
  START_LOG("compute_SCM_bounding_box()", "RBSCMConstruction");

  // Resize the bounding box vectors
  rb_scm_eval->B_min.resize(get_rb_theta_expansion().get_n_A_terms());
  rb_scm_eval->B_max.resize(get_rb_theta_expansion().get_n_A_terms());

  for(unsigned int q=0; q<get_rb_theta_expansion().get_n_A_terms(); q++)
  {
    matrix_A->zero();
    add_scaled_symm_Aq(q, 1.);

    // Compute B_min(q)
    eigen_solver->set_position_of_spectrum(SMALLEST_REAL);
    set_eigensolver_properties(q);

    solve();
    unsigned int nconv = get_n_converged();
    if (nconv != 0)
    {
      std::pair<Real, Real> eval = get_eigenpair(0);

      // ensure that the eigenvalue is real
      libmesh_assert_less (eval.second, TOLERANCE);

      rb_scm_eval->set_B_min(q, eval.first);
      libMesh::out << std::endl << "B_min("<<q<<") = " << rb_scm_eval->get_B_min(q) << std::endl;
    }
    else
    {
      libMesh::err << "Eigen solver for computing B_min did not converge" << std::endl;
      libmesh_error();
    }

    // Compute B_max(q)
    eigen_solver->set_position_of_spectrum(LARGEST_REAL);
    set_eigensolver_properties(q);

    solve();
    nconv = get_n_converged();
    if (nconv != 0)
    {
      std::pair<Real, Real> eval = get_eigenpair(0);

      // ensure that the eigenvalue is real
      libmesh_assert_less (eval.second, TOLERANCE);

      rb_scm_eval->set_B_max(q,eval.first);
      libMesh::out << "B_max("<<q<<") = " << rb_scm_eval->get_B_max(q) << std::endl;
    }
    else
    {
      libMesh::err << "Eigen solver for computing B_max did not converge" << std::endl;
      libmesh_error();
    }
  }

  STOP_LOG("compute_SCM_bounding_box()", "RBSCMConstruction");
}
Exemple #8
0
void NewmarkSystem::update_u_v_a ()
{
  START_LOG("update_u_v_a ()", "NewmarkSystem");

  // get some references for convenience
  const NumericVector<Number> &  solu = *this->solution;

  NumericVector<Number> &  disp_vec   = this->get_vector("displacement");
  NumericVector<Number> &  vel_vec    = this->get_vector("velocity");
  NumericVector<Number> &  acc_vec    = this->get_vector("acceleration");
  NumericVector<Number> &  old_acc    = this->get_vector("old_acceleration");
  NumericVector<Number> &  old_solu   = this->get_vector("old_solution");

  // copy data
  old_solu = disp_vec;
  disp_vec = solu;
  old_acc  = acc_vec;

  // compute the new acceleration vector
  acc_vec.scale(-_a_3);
  acc_vec.add(_a_0, disp_vec);
  acc_vec.add(-_a_0, old_solu);
  acc_vec.add(-_a_2,vel_vec);

  // compute the new velocity vector
  vel_vec.add(_a_6,old_acc);
  vel_vec.add(_a_7,acc_vec);

  STOP_LOG("update_u_v_a ()", "NewmarkSystem");
}
Exemple #9
0
Real StatisticsVector<T>::median()
{
  const dof_id_type n = cast_int<dof_id_type>(this->size());

  if (n == 0)
    return 0.;

  START_LOG ("median()", "StatisticsVector");

  std::sort(this->begin(), this->end());

  const dof_id_type lhs = (n-1) / 2;
  const dof_id_type rhs = n / 2;

  Real the_median = 0;


  if (lhs == rhs)
    {
      the_median = static_cast<Real>((*this)[lhs]);
    }

  else
    {
      the_median = ( static_cast<Real>((*this)[lhs]) +
                     static_cast<Real>((*this)[rhs]) ) / 2.0;
    }

  STOP_LOG ("median()", "StatisticsVector");

  return the_median;
}
void RBEIMConstruction::update_RB_system_matrices()
{
  START_LOG("update_RB_system_matrices()", "RBEIMConstruction");

  Parent::update_RB_system_matrices();

  unsigned int RB_size = get_rb_evaluation().get_n_basis_functions();

  RBEIMEvaluation& eim_eval = cast_ref<RBEIMEvaluation&>(get_rb_evaluation());

  // update the EIM interpolation matrix
  for(unsigned int j=0; j<RB_size; j++)
    {
      // Sample the basis functions at the
      // new interpolation point
      get_rb_evaluation().get_basis_function(j).localize(*_ghosted_meshfunction_vector, this->get_dof_map().get_send_list());

      if(!_performing_extra_greedy_step)
        {
          eim_eval.interpolation_matrix(RB_size-1,j) =
            evaluate_mesh_function( eim_eval.interpolation_points_var[RB_size-1],
                                    eim_eval.interpolation_points[RB_size-1] );
        }
      else
        {
          eim_eval.extra_interpolation_matrix_row(j) =
            evaluate_mesh_function( eim_eval.extra_interpolation_point_var,
                                    eim_eval.extra_interpolation_point );
        }
    }

  STOP_LOG("update_RB_system_matrices()", "RBEIMConstruction");
}
Exemple #11
0
  std::pair<unsigned int, Real> LinearSolver<T>::adjoint_solve (SparseMatrix<T> & mat,
					       NumericVector<T>& sol,
					       NumericVector<T>& rhs,
					       const double tol,
					       const unsigned int n_iter)
  {
    // Log how long the linear solve takes.
    START_LOG("adjoint_solve()", "LinearSolver");

    // Take the discrete adjoint
    mat.close();
    mat.get_transpose(mat);

    // Call the solve function for the relevant linear algebra library and
    // solve the transpose matrix
    const std::pair<unsigned int, Real> totalrval =  this->solve (mat, sol, rhs, tol, n_iter);

    // Now transpose back and restore the original matrix
    // by taking the discrete adjoint
    mat.get_transpose(mat);

    // Stop logging the nonlinear solve
    STOP_LOG("adjoint_solve()", "LinearSolver");

    return totalrval;

  }
void PetscDiffSolver::init ()
{
  START_LOG("init()", "PetscDiffSolver");

  Parent::init();

  int ierr=0;

#if PETSC_VERSION_LESS_THAN(2,1,2)
  // At least until Petsc 2.1.1, the SNESCreate had a different
  // calling syntax.  The second argument was of type SNESProblemType,
  // and could have a value of either SNES_NONLINEAR_EQUATIONS or
  // SNES_UNCONSTRAINED_MINIMIZATION.
  ierr = SNESCreate(libMesh::COMM_WORLD, SNES_NONLINEAR_EQUATIONS, &_snes);
  CHKERRABORT(libMesh::COMM_WORLD,ierr);
#else
  ierr = SNESCreate(libMesh::COMM_WORLD,&_snes);
  CHKERRABORT(libMesh::COMM_WORLD,ierr);
#endif

#if PETSC_VERSION_LESS_THAN(2,3,3)
  ierr = SNESSetMonitor (_snes, __libmesh_petsc_diff_solver_monitor,
                         this, PETSC_NULL);
#else
  // API name change in PETSc 2.3.3
  ierr = SNESMonitorSet (_snes, __libmesh_petsc_diff_solver_monitor,
                         this, PETSC_NULL);
#endif
  CHKERRABORT(libMesh::COMM_WORLD,ierr);

  ierr = SNESSetFromOptions(_snes);
  CHKERRABORT(libMesh::COMM_WORLD,ierr);

  STOP_LOG("init()", "PetscDiffSolver");
}
Exemple #13
0
Real StatisticsVector<T>::median()
{
  const unsigned int n   = this->size();

  if (n == 0)
    return 0.;

  START_LOG ("median()", "StatisticsVector");

  std::sort(this->begin(), this->end());

  const unsigned int lhs = (n-1) / 2;
  const unsigned int rhs = n / 2;

  Real median = 0;


  if (lhs == rhs)
    {
      median = static_cast<Real>((*this)[lhs]);
    }

  else
    {
      median = ( static_cast<Real>((*this)[lhs]) +
		 static_cast<Real>((*this)[rhs]) ) / 2.0;
    }

  STOP_LOG ("median()", "StatisticsVector");

  return median;
}
Exemple #14
0
void FEMap::compute_map(const unsigned int dim,
			const std::vector<Real>& qw,
			const Elem* elem)
{
  if (elem->has_affine_map())
    {
      compute_affine_map(dim, qw, elem);
      return;
    }

   // Start logging the map computation.
  START_LOG("compute_map()", "FEMap");

  libmesh_assert(elem);

  const unsigned int n_qp = libmesh_cast_int<unsigned int>(qw.size());

  // Resize the vectors to hold data at the quadrature points
  this->resize_quadrature_map_vectors(dim, n_qp);

  // Compute map at all quadrature points
  for (unsigned int p=0; p!=n_qp; p++)
    this->compute_single_point_map(dim, qw, elem, p);

  // Stop logging the map computation.
  STOP_LOG("compute_map()", "FEMap");
}
void DerivedRBConstruction<RBConstruction>::enrich_RB_space()
{
  START_LOG("enrich_RB_space()", "DerivedRBConstruction");

  EquationSystems& es = this->get_equation_systems();
  RBConstruction& uber_system = es.get_system<RBConstruction>(uber_system_name);
  const unsigned int uber_size = uber_system.get_rb_evaluation().get_n_basis_functions();

  DenseVector<Number> new_bf = uber_system.get_rb_evaluation().RB_solution;

  // Need to cast the RBEvaluation object
  DerivedRBEvaluation<RBEvaluation>& der_rb_eval =
    libmesh_cast_ref<DerivedRBEvaluation<RBEvaluation>&>(get_rb_evaluation());

  // compute Gram-Schmidt orthogonalization
  DenseVector<Number> proj_sum(uber_size);
  for(unsigned int index=0; index<get_rb_evaluation().get_n_basis_functions(); index++)
  {
    // orthogonalize using the Identity matrix as the inner product,
    // since the uber basis functions should be orthogonal already
    // (i.e. neglect possible rounding errors in uber orthogonalization)
    Number scalar = new_bf.dot(der_rb_eval.derived_basis_functions[index]);
    proj_sum.add(scalar, der_rb_eval.derived_basis_functions[index]);
  }
  new_bf -= proj_sum;
  new_bf.scale(1./new_bf.l2_norm());

  // load the new basis function into the basis_functions vector.
  der_rb_eval.derived_basis_functions.push_back( new_bf );

  STOP_LOG("enrich_RB_space()", "DerivedRBConstruction");
}
const Elem* PointLocatorTree::perform_linear_search(const Point& p,
                                                    const std::set<subdomain_id_type> *allowed_subdomains,
                                                    bool use_close_to_point,
                                                    Real close_to_point_tolerance) const
{
  START_LOG("perform_linear_search", "PointLocatorTree");

  // The type of iterator depends on the Trees::BuildType
  // used for this PointLocator.  If it's
  // TREE_LOCAL_ELEMENTS, we only want to double check
  // local elements during this linear search.
  MeshBase::const_element_iterator pos =
    this->_build_type == Trees::LOCAL_ELEMENTS ?
    this->_mesh.active_local_elements_begin() : this->_mesh.active_elements_begin();

  const MeshBase::const_element_iterator end_pos =
    this->_build_type == Trees::LOCAL_ELEMENTS ?
    this->_mesh.active_local_elements_end() : this->_mesh.active_elements_end();

  for ( ; pos != end_pos; ++pos)
    {
      if (!allowed_subdomains ||
          allowed_subdomains->count((*pos)->subdomain_id()))
        {
          if(!use_close_to_point)
            {
              if ((*pos)->contains_point(p))
                {
                  STOP_LOG("perform_linear_search", "PointLocatorTree");
                  return (*pos);
                }
            }
          else
            {
              if ((*pos)->close_to_point(p, close_to_point_tolerance))
                {
                  STOP_LOG("perform_linear_search", "PointLocatorTree");
                  return (*pos);
                }
            }
        }
    }

  STOP_LOG("perform_linear_search", "PointLocatorTree");
  return NULL;
}
Real RBEIMConstruction::compute_best_fit_error()
{
  START_LOG("compute_best_fit_error()", "RBEIMConstruction");

  const unsigned int RB_size = get_rb_evaluation().get_n_basis_functions();

  // load up the parametrized function for the current parameters
  truth_solve(-1);

  switch(best_fit_type_flag)
    {
      // Perform an L2 projection in order to find an approximation to solution (from truth_solve above)
    case(PROJECTION_BEST_FIT):
      {
        // compute the rhs by performing inner products
        DenseVector<Number> best_fit_rhs(RB_size);

        inner_product_matrix->vector_mult(*inner_product_storage_vector, *solution);
        for(unsigned int i=0; i<RB_size; i++)
          {
            best_fit_rhs(i) = inner_product_storage_vector->dot(get_rb_evaluation().get_basis_function(i));
          }

        // Now compute the best fit by an LU solve
        get_rb_evaluation().RB_solution.resize(RB_size);
        DenseMatrix<Number> RB_inner_product_matrix_N(RB_size);
        get_rb_evaluation().RB_inner_product_matrix.get_principal_submatrix(RB_size, RB_inner_product_matrix_N);

        RB_inner_product_matrix_N.lu_solve(best_fit_rhs, get_rb_evaluation().RB_solution);
        break;
      }
      // Perform EIM solve in order to find the approximation to solution
      // (rb_solve provides the EIM basis function coefficients used below)
    case(EIM_BEST_FIT):
      {
        // Turn off error estimation for this rb_solve, we use the linfty norm instead
        get_rb_evaluation().evaluate_RB_error_bound = false;
        get_rb_evaluation().set_parameters( get_parameters() );
        get_rb_evaluation().rb_solve(RB_size);
        get_rb_evaluation().evaluate_RB_error_bound = true;
        break;
      }
    default:
      libmesh_error_msg("Should not reach here");
    }

  // load the error into solution
  for(unsigned int i=0; i<get_rb_evaluation().get_n_basis_functions(); i++)
    {
      solution->add(-get_rb_evaluation().RB_solution(i), get_rb_evaluation().get_basis_function(i));
    }

  Real best_fit_error = solution->linfty_norm();

  STOP_LOG("compute_best_fit_error()", "RBEIMConstruction");

  return best_fit_error;
}
Exemple #18
0
void RBSCMConstruction::add_scaled_symm_Aq(unsigned int q_a, Number scalar)
{
  START_LOG("add_scaled_symm_Aq()", "RBSCMConstruction");
  // Load the operators from the RBConstruction
  EquationSystems& es = this->get_equation_systems();
  RBConstruction& rb_system = es.get_system<RBConstruction>(RB_system_name);
  rb_system.add_scaled_Aq(scalar, q_a, matrix_A, true);
  STOP_LOG("add_scaled_symm_Aq()", "RBSCMConstruction");
}
void DerivedRBConstruction<RBConstruction>::update_RB_system_matrices()
{
  START_LOG("update_RB_system_matrices()", "DerivedRBConstruction");

  DerivedRBEvaluation<RBEvaluation>& der_rb_eval =
    libmesh_cast_ref<DerivedRBEvaluation<RBEvaluation>&>(get_rb_evaluation());

  EquationSystems& es = this->get_equation_systems();
  RBConstruction& uber_system = es.get_system<RBConstruction>(uber_system_name);

  unsigned int derived_RB_size = get_rb_evaluation().get_n_basis_functions();
  unsigned int uber_RB_size    = uber_system.get_rb_evaluation().get_n_basis_functions();

  const unsigned int Q_a = get_rb_theta_expansion().get_n_A_terms();
  const unsigned int Q_f = get_rb_theta_expansion().get_n_F_terms();

  DenseVector<Number> temp_vector;
  for(unsigned int q_f=0; q_f<Q_f; q_f++)
  {
    for(unsigned int i=(derived_RB_size-delta_N); i<derived_RB_size; i++)
    {
      uber_system.get_rb_evaluation().RB_Fq_vector[q_f].get_principal_subvector(uber_RB_size, temp_vector);
      get_rb_evaluation().RB_Fq_vector[q_f](i) = temp_vector.dot(der_rb_eval.derived_basis_functions[i]);
    }
  }

  DenseMatrix<Number> temp_matrix;
  for(unsigned int i=(derived_RB_size-delta_N); i<derived_RB_size; i++)
  {
    for(unsigned int n=0; n<get_rb_theta_expansion().get_n_outputs(); n++)
      for(unsigned int q_l=0; q_l<get_rb_theta_expansion().get_n_output_terms(n); q_l++)
      {
        uber_system.get_rb_evaluation().RB_output_vectors[n][q_l].get_principal_subvector(uber_RB_size, temp_vector);
        get_rb_evaluation().RB_output_vectors[n][q_l](i) = temp_vector.dot(der_rb_eval.derived_basis_functions[i]);
      }

    for(unsigned int j=0; j<derived_RB_size; j++)
    {
      for(unsigned int q_a=0; q_a<Q_a; q_a++)
      {
        // Compute reduced Aq matrix
        uber_system.get_rb_evaluation().RB_Aq_vector[q_a].get_principal_submatrix(uber_RB_size, temp_matrix);
        temp_matrix.vector_mult(temp_vector, der_rb_eval.derived_basis_functions[j]);
        get_rb_evaluation().RB_Aq_vector[q_a](i,j) = der_rb_eval.derived_basis_functions[i].dot(temp_vector);

        if(i!=j)
        {
          temp_vector.zero();
          temp_matrix.vector_mult(temp_vector, der_rb_eval.derived_basis_functions[i]);
          get_rb_evaluation().RB_Aq_vector[q_a](j,i) = (der_rb_eval.derived_basis_functions[j]).dot(temp_vector);
        }
      }
    }
  }

  STOP_LOG("update_RB_system_matrices()", "DerivedRBConstruction");
}
Exemple #20
0
void RBSCMConstruction::evaluate_stability_constant()
{
  START_LOG("evaluate_stability_constant()", "RBSCMConstruction");

  // Get current index of C_J
  const unsigned int j = rb_scm_eval->C_J.size()-1;

  eigen_solver->set_position_of_spectrum(SMALLEST_REAL);

  // We assume B is set in system assembly
  // For coercive problems, B is set to the inner product matrix
  // For non-coercive time-dependent problems, B is set to the mass matrix

  // Set matrix A corresponding to mu_star
  matrix_A->zero();
  for(unsigned int q=0; q<get_rb_theta_expansion().get_n_A_terms(); q++)
  {
    add_scaled_symm_Aq(q, get_rb_theta_expansion().eval_A_theta(q,get_parameters()));
  }

  set_eigensolver_properties(-1);
  solve();
  unsigned int nconv = get_n_converged();
  if (nconv != 0)
  {
    std::pair<Real, Real> eval = get_eigenpair(0);

    // ensure that the eigenvalue is real
    libmesh_assert_less (eval.second, TOLERANCE);

    // Store the coercivity constant corresponding to mu_star
    rb_scm_eval->set_C_J_stability_constraint(j,eval.first);
    libMesh::out << std::endl << "Stability constant for C_J("<<j<<") = "
                 << rb_scm_eval->get_C_J_stability_constraint(j) << std::endl << std::endl;

    // Compute and store the vector y = (y_1, \ldots, y_Q) for the
    // eigenvector currently stored in eigen_system.solution.
    // We use this later to compute the SCM upper bounds.
    Real norm_B2 = libmesh_real( B_inner_product(*solution, *solution) );

    for(unsigned int q=0; q<get_rb_theta_expansion().get_n_A_terms(); q++)
    {
      Real norm_Aq2 = libmesh_real( Aq_inner_product(q, *solution, *solution) );

      rb_scm_eval->set_SCM_UB_vector(j,q,norm_Aq2/norm_B2);
    }
  }
  else
  {
    libMesh::err << "Error: Eigensolver did not converge in evaluate_stability_constant"
                 << std::endl;
    libmesh_error();
  }

  STOP_LOG("evaluate_stability_constant()", "RBSCMConstruction");
}
Exemple #21
0
T StatisticsVector<T>::maximum() const
{
  START_LOG ("maximum()", "StatisticsVector");

  const T max = *(std::max_element(this->begin(), this->end()));

  STOP_LOG ("maximum()", "StatisticsVector");

  return max;
}
Exemple #22
0
void GnuPlotIO::write_nodal_data (const std::string& fname,
				  const std::vector<Number>& soln,
				  const std::vector<std::string>& names)
{
  START_LOG("write_nodal_data()", "GnuPlotIO");

  this->write_solution(fname, &soln, &names);

  STOP_LOG("write_nodal_data()", "GnuPlotIO");
}
Exemple #23
0
void EquationSystems::update ()
{
  START_LOG("update()","EquationSystems");

  // Localize each system's vectors
  for (unsigned int i=0; i != this->n_systems(); ++i)
    this->get_system(i).update();

  STOP_LOG("update()","EquationSystems");
}
Exemple #24
0
void MeshData::translate (const MeshBase & out_mesh,
                          std::vector<Number> & values,
                          std::vector<std::string> & names) const
{
  libmesh_assert (_active || _compatibility_mode);

  START_LOG("translate()", "MeshData");

  const unsigned int n_comp = this->n_val_per_node();

  // transfer our nodal data to a vector
  // that may be written concurrently
  // with the \p out_mesh.
  {
    // reserve memory for the nodal data
    values.reserve(n_comp*out_mesh.n_nodes());

    // iterate over the mesh's nodes
    MeshBase::const_node_iterator       nodes_it  = out_mesh.nodes_begin();
    const MeshBase::const_node_iterator nodes_end = out_mesh.nodes_end();

    // Do not use the \p get_data() method, but the operator()
    // method, since this returns by default a zero value,
    // when there is no nodal data.
    for (; nodes_it != nodes_end; ++nodes_it)
      {
        const Node * node = *nodes_it;

        for (unsigned int c= 0; c<n_comp; c++)
          values.push_back(this->operator()(node, c));
      }
  }



  // Now we have the data, nicely stored in \p values.
  // It remains to give names to the data, then write to
  // file.
  {
    names.reserve(n_comp);

    // this naming scheme only works up to n_comp=100
    // (at least for gmv-accepted variable names)
    libmesh_assert_less (n_comp, 100);

    for (unsigned int n=0; n<n_comp; n++)
      {
        std::ostringstream name_buf;
        name_buf << "bc_" << n;
        names.push_back(name_buf.str());
      }
  }

  STOP_LOG("translate()", "MeshData");
}
  std::pair<unsigned int, Real>
  PetscDMNonlinearSolver<T>::solve (SparseMatrix<T>& jac_in,  // System Jacobian Matrix
				    NumericVector<T>& x_in,   // Solution vector
				    NumericVector<T>& r_in,   // Residual vector
				    const double,             // Stopping tolerance
				    const unsigned int)
  {
    START_LOG("solve()", "PetscNonlinearSolver");
    this->init ();

    // Make sure the data passed in are really of Petsc types
    libmesh_cast_ptr<PetscMatrix<T>*>(&jac_in);
    libmesh_cast_ptr<PetscVector<T>*>(&r_in);

    // Extract solution vector
    PetscVector<T>* x = libmesh_cast_ptr<PetscVector<T>*>(&x_in);

    int ierr=0;
    int n_iterations =0;

    // Should actually be a PetscReal, but I don't know which version of PETSc first introduced PetscReal
    Real final_residual_norm=0.;

    if (this->user_presolve)
      this->user_presolve(this->system());

    //Set the preconditioning matrix
    if (this->_preconditioner)
      this->_preconditioner->set_matrix(jac_in);

    ierr = SNESSolve (this->_snes, PETSC_NULL, x->vec());
    CHKERRABORT(libMesh::COMM_WORLD,ierr);

    ierr = SNESGetIterationNumber(this->_snes,&n_iterations);
    CHKERRABORT(libMesh::COMM_WORLD,ierr);

    ierr = SNESGetLinearSolveIterations(this->_snes, &this->_n_linear_iterations);
    CHKERRABORT(libMesh::COMM_WORLD,ierr);

    ierr = SNESGetFunctionNorm(this->_snes,&final_residual_norm);
    CHKERRABORT(libMesh::COMM_WORLD,ierr);

    // Get and store the reason for convergence
    SNESGetConvergedReason(this->_snes, &this->_reason);

    //Based on Petsc 2.3.3 documentation all diverged reasons are negative
    this->converged = (this->_reason >= 0);

    this->clear();

    STOP_LOG("solve()", "PetscNonlinearSolver");

    // return the # of its. and the final residual norm.
    return std::make_pair(n_iterations, final_residual_norm);
  }
Exemple #26
0
unsigned int PetscDiffSolver::solve()
{
  this->init();

  START_LOG("solve()", "PetscDiffSolver");

  PetscVector<Number> &x =
    *(libmesh_cast_ptr<PetscVector<Number>*>(_system.solution.get()));
  PetscMatrix<Number> &jac =
    *(libmesh_cast_ptr<PetscMatrix<Number>*>(_system.matrix));
  PetscVector<Number> &r =
    *(libmesh_cast_ptr<PetscVector<Number>*>(_system.rhs));

#ifdef LIBMESH_ENABLE_CONSTRAINTS
  _system.get_dof_map().enforce_constraints_exactly(_system);
#endif

  int ierr = 0;

  ierr = SNESSetFunction (_snes, r.vec(),
                          __libmesh_petsc_diff_solver_residual, this);
    LIBMESH_CHKERRABORT(ierr);

  ierr = SNESSetJacobian (_snes, jac.mat(), jac.mat(),
                          __libmesh_petsc_diff_solver_jacobian, this);
    LIBMESH_CHKERRABORT(ierr);

# if PETSC_VERSION_LESS_THAN(2,2,0)

  ierr = SNESSolve (_snes, x.vec(), &_outer_iterations);
         LIBMESH_CHKERRABORT(ierr);

// 2.2.x style
#elif PETSC_VERSION_LESS_THAN(2,3,0)

  ierr = SNESSolve (_snes, x.vec());
         LIBMESH_CHKERRABORT(ierr);

// 2.3.x & newer style
#else

  ierr = SNESSolve (_snes, PETSC_NULL, x.vec());
         LIBMESH_CHKERRABORT(ierr);

#endif

  STOP_LOG("solve()", "PetscDiffSolver");

  SNESConvergedReason reason;
  SNESGetConvergedReason(_snes, &reason);

  this->clear();

  return convert_solve_result(reason);
}
  void RadialBasisInterpolation<KDDim,RBF>::interpolate_field_data (const std::vector<std::string> &field_names,
								    const std::vector<Point>  &tgt_pts,
								    std::vector<Number> &tgt_vals) const
  {
    START_LOG ("interpolate_field_data()", "RadialBasisInterpolation<>");

    libmesh_experimental();

    const unsigned int
      n_vars    = this->n_field_variables(),
      n_src_pts = this->_src_pts.size(),
      n_tgt_pts = tgt_pts.size();

    libmesh_assert_equal_to (_weights.size(),    this->_src_vals.size());
    libmesh_assert_equal_to (field_names.size(), this->n_field_variables());

    // If we already have field variables, we assume we are appending.
    // that means the names and ordering better be identical!
    if (this->_names.size() != field_names.size())
      {
	libMesh::err << "ERROR:  when adding field data to an existing list the\n"
		     << "varaible list must be the same!\n";
	libmesh_error();
      }
    for (unsigned int v=0; v<this->_names.size(); v++)
      if (_names[v] != field_names[v])
	{
	  libMesh::err << "ERROR:  when adding field data to an existing list the\n"
		       << "varaible list must be the same!\n";
	  libmesh_error();
	}


    RBF rbf(_r_bbox);

    tgt_vals.resize (n_tgt_pts*n_vars); /**/ std::fill (tgt_vals.begin(), tgt_vals.end(), Number(0.));

    for (unsigned int tgt=0; tgt<n_tgt_pts; tgt++)
      {
	const Point &p (tgt_pts[tgt]);

	for (unsigned int i=0; i<n_src_pts; i++)
	  {
	    const Point &x_i(_src_pts[i]);
	    const Real
	      r_i   = (p - x_i).size(),
	      phi_i = rbf(r_i);

	    for (unsigned int var=0; var<n_vars; var++)
	      tgt_vals[tgt*n_vars + var] += _weights[i*n_vars + var]*phi_i;
	  }
      }

    STOP_LOG ("interpolate_field_data()", "RadialBasisInterpolation<>");
  }
unsigned int PetscDiffSolver::solve()
{
  this->init();

  START_LOG("solve()", "PetscDiffSolver");

  PetscVector<Number> &x =
    *(libmesh_cast_ptr<PetscVector<Number>*>(_system.solution.get()));
  PetscMatrix<Number> &jac =
    *(libmesh_cast_ptr<PetscMatrix<Number>*>(_system.matrix));
  PetscVector<Number> &r =
    *(libmesh_cast_ptr<PetscVector<Number>*>(_system.rhs));

#ifdef LIBMESH_ENABLE_CONSTRAINTS
  _system.get_dof_map().enforce_constraints_exactly(_system);
#endif

  int ierr = 0;

  ierr = SNESSetFunction (_snes, r.vec(),
                          __libmesh_petsc_diff_solver_residual, this);
    CHKERRABORT(libMesh::COMM_WORLD,ierr);

  ierr = SNESSetJacobian (_snes, jac.mat(), jac.mat(),
                          __libmesh_petsc_diff_solver_jacobian, this);
    CHKERRABORT(libMesh::COMM_WORLD,ierr);

# if PETSC_VERSION_LESS_THAN(2,2,0)

  ierr = SNESSolve (_snes, x.vec(), &_outer_iterations);
         CHKERRABORT(libMesh::COMM_WORLD,ierr);

// 2.2.x style
#elif PETSC_VERSION_LESS_THAN(2,3,0)

  ierr = SNESSolve (_snes, x.vec());
         CHKERRABORT(libMesh::COMM_WORLD,ierr);

// 2.3.x & newer style
#else

  ierr = SNESSolve (_snes, PETSC_NULL, x.vec());
         CHKERRABORT(libMesh::COMM_WORLD,ierr);

#endif

  STOP_LOG("solve()", "PetscDiffSolver");

  this->clear();

  // FIXME - We'll worry about getting the solve result right later...

  return DiffSolver::CONVERGED_RELATIVE_RESIDUAL;
}
void PetscDiffSolver::clear()
{
  START_LOG("clear()", "PetscDiffSolver");

  int ierr=0;

  ierr = LibMeshSNESDestroy(&_snes);
  CHKERRABORT(libMesh::COMM_WORLD,ierr);

  STOP_LOG("clear()", "PetscDiffSolver");
}
Exemple #30
0
void PetscDiffSolver::clear()
{
  START_LOG("clear()", "PetscDiffSolver");

  int ierr=0;

  ierr = LibMeshSNESDestroy(&_snes);
  LIBMESH_CHKERRABORT(ierr);

  STOP_LOG("clear()", "PetscDiffSolver");
}