Dear Deal.II community

While modifying the step 26 code for simulation of additive manufacturing 
process, I have changed the class of fe object from FE_Q to 
hp::FECollection which has produced the following error on compilation :
In file included from /usr/local/include/deal.II/dofs/dof_handler.h:32,
                 from 
/home/pushkar/additive-instep/AdditiveSimulation.cc:41:
/usr/local/include/deal.II/hp/fe_collection.h: In instantiation of 
‘dealii::hp::FECollection<dim, spacedim>::FECollection(const FETypes& ...) 
[with FETypes = {int}; int dim = 2; int spacedim = 2]’:
/home/pushkar/additive-instep/AdditiveSimulation.cc:191:41:   required from 
‘AdditiveSimulation::ThermalProfile<dim>::ThermalProfile() [with int dim = 
2]’
/home/pushkar/additive-instep/AdditiveSimulation.cc:454:25:   required from 
here
/usr/local/include/deal.II/hp/fe_collection.h:469:77: error: static 
assertion failed: Not all of the input arguments of this function are 
derived from FiniteElement<dim,spacedim>!
  469 |     static_assert(is_base_of_all<FiniteElement<dim, spacedim>, 
FETypes...>::value,
      
|                                                                             
^~~~~
/usr/local/include/deal.II/hp/fe_collection.h:478:7: error: cannot convert 
‘const int’ to ‘const dealii::FiniteElement<2, 2>&’
  478 |       push_back (*p);
      |       ^~~~~~~~~
/usr/local/include/deal.II/hp/fe_collection.h:124:56: note:   initializing 
argument 1 of ‘void dealii::hp::FECollection<dim, 
spacedim>::push_back(const dealii::FiniteElement<dim, spacedim>&) [with int 
dim = 2; int spacedim = 2]’
  124 |     void push_back (const FiniteElement<dim,spacedim> &new_fe);
      |                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
/home/pushkar/additive-instep/AdditiveSimulation.cc: In instantiation of 
‘void AdditiveSimulation::ThermalProfile<dim>::setup_system() [with int dim 
= 2]’:
/home/pushkar/additive-instep/AdditiveSimulation.cc:342:5:   required from 
‘void AdditiveSimulation::ThermalProfile<dim>::run() [with int dim = 2]’
/home/pushkar/additive-instep/AdditiveSimulation.cc:455:32:   required from 
here
/home/pushkar/additive-instep/AdditiveSimulation.cc:199:33: error: cannot 
convert ‘dealii::hp::FECollection<2, 2>’ to ‘const dealii::FiniteElement<2, 
2>&’
  199 |     dof_handler.distribute_dofs(fe);
      |                                 ^~
      |                                 |
      |                                 dealii::hp::FECollection<2, 2>
In file included from 
/home/pushkar/additive-instep/AdditiveSimulation.cc:41:
/usr/local/include/deal.II/dofs/dof_handler.h:410:68: note:   initializing 
argument 1 of ‘void dealii::DoFHandler<dim, 
spacedim>::distribute_dofs(const dealii::FiniteElement<dim, spacedim>&) 
[with int dim = 2; int spacedim = 2]’
  410 |   virtual void distribute_dofs (const FiniteElement<dim,spacedim> 
&fe);
      |                                 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
/home/pushkar/additive-instep/AdditiveSimulation.cc:227:54: error: ‘class 
dealii::hp::FECollection<2, 2>’ has no member named ‘degree’
  227 |                                       QGauss<dim>(fe.degree+1),
      |                                                   ~~~^~~~~~
/home/pushkar/additive-instep/AdditiveSimulation.cc:230:57: error: ‘class 
dealii::hp::FECollection<2, 2>’ has no member named ‘degree’
  230 |                                          QGauss<dim>(fe.degree+1),
      |                                                      ~~~^~~~~~
/home/pushkar/additive-instep/AdditiveSimulation.cc: In instantiation of 
‘void AdditiveSimulation::ThermalProfile<dim>::refine_mesh(unsigned int, 
unsigned int) [with int dim = 2]’:
/home/pushkar/additive-instep/AdditiveSimulation.cc:422:13:   required from 
‘void AdditiveSimulation::ThermalProfile<dim>::run() [with int dim = 2]’
/home/pushkar/additive-instep/AdditiveSimulation.cc:455:32:   required from 
here
/home/pushkar/additive-instep/AdditiveSimulation.cc:284:58: error: ‘class 
dealii::hp::FECollection<2, 2>’ has no member named ‘degree’
  284 |                                         QGauss<dim-1>(fe.degree+1),
      |                                                       ~~~^~~~~~
make[2]: *** [CMakeFiles/AdditiveSimulation.dir/build.make:82: 
CMakeFiles/AdditiveSimulation.dir/AdditiveSimulation.cc.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:183: 
CMakeFiles/AdditiveSimulation.dir/all] Error 2
make: *** [Makefile:103: all] Error 2


Any resolution in this scenario will be beneficial and I look forward to 
developers to guide me with this. For reference, I have attached the .cc 
file

Regards
Pushkar

-- 
The deal.II project is located at http://www.dealii.org/
For mailing list/forum options, see 
https://groups.google.com/d/forum/dealii?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"deal.II User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/dealii/b9ba0f3a-6906-4b4f-b91c-edcc5c62e229n%40googlegroups.com.
/* ---------------------------------------------------------------------
 *
 * Copyright (C) 2013 - 2017 by the deal.II authors
 *
 * This file is part of the deal.II library.
 *
 * The deal.II library is free software; you can use it, redistribute
 * it, and/or modify it under the terms of the GNU Lesser General
 * Public License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * The full text of the license can be found in the file LICENSE at
 * the top level of the deal.II distribution.
 *
 * ---------------------------------------------------------------------

 *
 * Author: Wolfgang Bangerth, Texas A&M University, 2013
 */


#include <deal.II/base/utilities.h>
#include <deal.II/base/quadrature_lib.h>
#include <deal.II/base/function.h>
#include <deal.II/base/logstream.h>

#include <deal.II/lac/vector.h>
#include <deal.II/lac/full_matrix.h>
#include <deal.II/lac/dynamic_sparsity_pattern.h>
#include <deal.II/lac/sparse_matrix.h>
#include <deal.II/lac/solver_cg.h>
#include <deal.II/lac/precondition.h>
#include <deal.II/lac/constraint_matrix.h>

#include <deal.II/grid/tria.h>
#include <deal.II/grid/grid_generator.h>
#include <deal.II/grid/grid_refinement.h>
#include <deal.II/grid/grid_out.h>
#include <deal.II/grid/tria_accessor.h>
#include <deal.II/grid/tria_iterator.h>

#include <deal.II/dofs/dof_handler.h>
#include <deal.II/dofs/dof_accessor.h>
#include <deal.II/dofs/dof_tools.h>

#include <deal.II/fe/fe_q.h>
#include <deal.II/fe/fe_values.h>

#include <deal.II/numerics/data_out.h>
#include <deal.II/numerics/vector_tools.h>
#include <deal.II/numerics/error_estimator.h>
#include <deal.II/numerics/solution_transfer.h>
#include <deal.II/numerics/matrix_tools.h>

#include <deal.II/hp/fe_collection.h>

#include <fstream>
#include <iostream>


namespace AdditiveSimulation
{
  using namespace dealii;


  template <int dim>
  class ThermalProfile
  {
  public:
    ThermalProfile();
    void run();

  private:

    void setup_system();
    void solve_time_step();
    void output_results() const;
    void refine_mesh (const unsigned int min_grid_level,
                      const unsigned int max_grid_level);

    Triangulation<dim>   triangulation;
    hp::FECollection<dim>fe;
    DoFHandler<dim>      dof_handler;

    ConstraintMatrix     constraints;

    SparsityPattern      sparsity_pattern;
    SparseMatrix<double> mass_matrix;
    SparseMatrix<double> laplace_matrix;
    SparseMatrix<double> system_matrix;

    Vector<double>       solution;
    Vector<double>       old_solution;
    Vector<double>       system_rhs;

    double               time;
    double               time_step;
    unsigned int         timestep_number;

    const double         theta;

    const double 		 edge_length;
    const double 		 layerThickness;
    double 				 number_layer;
  };




  template <int dim>
  class RightHandSide : public Function<dim>
  {
  public:
    RightHandSide ()
      :
      Function<dim>(),
      period (0.2)
    {}

    virtual double value (const Point<dim> &p,
                          const unsigned int component = 0) const;

  private:
    const double period;
  };



  template <int dim>
  double RightHandSide<dim>::value (const Point<dim> &p,
                                    const unsigned int component) const
  {
    (void) component;
    Assert (component == 0, ExcIndexRange(component, 0, 1));
    Assert (dim == 2, ExcNotImplemented());

    const double time = this->get_time();
    const double point_within_period = (time/period - std::floor(time/period));

    if ((point_within_period >= 0.0) && (point_within_period <= 0.2))
      {
        if ((p[0] > 0.5) && (p[1] > -0.5))
          return 1;
        else
          return 0;
      }
    else if ((point_within_period >= 0.5) && (point_within_period <= 0.7))
      {
        if ((p[0] > -0.5) && (p[1] > 0.5))
          return 1;
        else
          return 0;
      }
    else
      return 0;
  }



  template <int dim>
  class BoundaryValues : public Function<dim>
  {
  public:
    virtual double value (const Point<dim>  &p,
                          const unsigned int component = 0) const;
  };



  template <int dim>
  double BoundaryValues<dim>::value (const Point<dim> &/*p*/,
                                     const unsigned int component) const
  {
    (void) component;
    Assert (component == 0, ExcIndexRange(component, 0, 1));
    return 0;
  }



  template <int dim>
  ThermalProfile<dim>::ThermalProfile ()
    :
    fe(1),
    dof_handler(triangulation),
    time (0.0),
    time_step(0.01),
    timestep_number (0),
    theta(0.5),
	edge_length(1.0),
	layerThickness(0.02),
	number_layer(edge_length/layerThickness)
  {}



  template <int dim>
  void ThermalProfile<dim>::setup_system()
  {
    dof_handler.distribute_dofs(fe);

    std::cout << std::endl
              << "==========================================="
              << std::endl
              << "Number of active cells: " << triangulation.n_active_cells()
              << std::endl
              << "Number of degrees of freedom: " << dof_handler.n_dofs()
              << std::endl
              << std::endl;

    constraints.clear ();
    DoFTools::make_hanging_node_constraints (dof_handler,
                                             constraints);
    constraints.close();

    DynamicSparsityPattern dsp(dof_handler.n_dofs());
    DoFTools::make_sparsity_pattern(dof_handler,
                                    dsp,
                                    constraints,
                                    /*keep_constrained_dofs = */ true);
    sparsity_pattern.copy_from(dsp);

    mass_matrix.reinit(sparsity_pattern);
    laplace_matrix.reinit(sparsity_pattern);
    system_matrix.reinit(sparsity_pattern);

    MatrixCreator::create_mass_matrix(dof_handler,
                                      QGauss<dim>(fe.degree+1),
                                      mass_matrix);
    MatrixCreator::create_laplace_matrix(dof_handler,
                                         QGauss<dim>(fe.degree+1),
                                         laplace_matrix);

    solution.reinit(dof_handler.n_dofs());
    old_solution.reinit(dof_handler.n_dofs());
    system_rhs.reinit(dof_handler.n_dofs());
  }


  template <int dim>
  void ThermalProfile<dim>::solve_time_step()
  {
    SolverControl solver_control(1000, 1e-8 * system_rhs.l2_norm());
    SolverCG<> cg(solver_control);

    PreconditionSSOR<> preconditioner;
    preconditioner.initialize(system_matrix, 1.0);

    cg.solve(system_matrix, solution, system_rhs,
             preconditioner);

    constraints.distribute(solution);

    std::cout << "     " << solver_control.last_step()
              << " CG iterations." << std::endl;
  }



  template <int dim>
  void ThermalProfile<dim>::output_results() const
  {
    DataOut<dim> data_out;

    data_out.attach_dof_handler(dof_handler);
    data_out.add_data_vector(solution, "U");

    data_out.build_patches();

    const std::string filename = "solution-"
                                 + Utilities::int_to_string(timestep_number, 3) +
                                 ".vtk";
    std::ofstream output(filename.c_str());
    data_out.write_vtk(output);
  }


  template <int dim>
  void ThermalProfile<dim>::refine_mesh (const unsigned int min_grid_level,
                                       const unsigned int max_grid_level)
  {
    Vector<float> estimated_error_per_cell (triangulation.n_active_cells());

    KellyErrorEstimator<dim>::estimate (dof_handler,
                                        QGauss<dim-1>(fe.degree+1),
                                        typename FunctionMap<dim>::type(),
                                        solution,
                                        estimated_error_per_cell);

    GridRefinement::refine_and_coarsen_fixed_fraction (triangulation,
                                                       estimated_error_per_cell,
                                                       0.6, 0.4);

    if (triangulation.n_levels() > max_grid_level)
      for (typename Triangulation<dim>::active_cell_iterator
           cell = triangulation.begin_active(max_grid_level);
           cell != triangulation.end(); ++cell)
        cell->clear_refine_flag ();
    for (typename Triangulation<dim>::active_cell_iterator
         cell = triangulation.begin_active(min_grid_level);
         cell != triangulation.end_active(min_grid_level); ++cell)
      cell->clear_coarsen_flag ();

    SolutionTransfer<dim> solution_trans(dof_handler);

    Vector<double> previous_solution;
    previous_solution = solution;
    triangulation.prepare_coarsening_and_refinement();
    solution_trans.prepare_for_coarsening_and_refinement(previous_solution);

    triangulation.execute_coarsening_and_refinement ();
    setup_system ();

    solution_trans.interpolate(previous_solution, solution);
    constraints.distribute (solution);
  }



  template <int dim>
  void ThermalProfile<dim>::run()
  {
    const unsigned int initial_global_refinement = 2;
    const unsigned int n_adaptive_pre_refinement_steps = 4;

    // Creation of two points
    Point<dim> p1;
    Point<dim> p2;

    // Affecting coordinates to p1 and p2
    for (unsigned int n=0; n<dim ; n++)
    {
    	p1[n] = 0;
    	p2[n] = edge_length;
    }

    p2[dim-1] = layerThickness*number_layer;

    // Generate a parallelepipedium (rectangle in 2D) having a [p1 p2] diagonal
    GridGenerator::hyper_rectangle(triangulation, p1, p2);
    triangulation.refine_global (initial_global_refinement);

    setup_system();

    unsigned int pre_refinement_step = 0;

    Vector<double> tmp;
    Vector<double> forcing_terms;

start_time_iteration:

    tmp.reinit (solution.size());
    forcing_terms.reinit (solution.size());


    VectorTools::interpolate(dof_handler,
                             Functions::ZeroFunction<dim>(),
                             old_solution);
    solution = old_solution;

    output_results();

    while (time <= 0.5)
      {
        time += time_step;
        ++timestep_number;

        std::cout << "Time step " << timestep_number << " at t=" << time
                  << std::endl;

        mass_matrix.vmult(system_rhs, old_solution);

        laplace_matrix.vmult(tmp, old_solution);
        system_rhs.add(-(1 - theta) * time_step, tmp);

        RightHandSide<dim> rhs_function;
        rhs_function.set_time(time);
        VectorTools::create_right_hand_side(dof_handler,
                                            QGauss<dim>(fe.size()+1),
                                            rhs_function,
                                            tmp);
        forcing_terms = tmp;
        forcing_terms *= time_step * theta;

        rhs_function.set_time(time - time_step);
        VectorTools::create_right_hand_side(dof_handler,
                                            QGauss<dim>(fe.size()+1),
                                            rhs_function,
                                            tmp);

        forcing_terms.add(time_step * (1 - theta), tmp);

        system_rhs += forcing_terms;

        system_matrix.copy_from(mass_matrix);
        system_matrix.add(theta * time_step, laplace_matrix);

        constraints.condense (system_matrix, system_rhs);

        {
          BoundaryValues<dim> boundary_values_function;
          boundary_values_function.set_time(time);

          std::map<types::global_dof_index, double> boundary_values;
          VectorTools::interpolate_boundary_values(dof_handler,
                                                   0,
                                                   boundary_values_function,
                                                   boundary_values);

          MatrixTools::apply_boundary_values(boundary_values,
                                             system_matrix,
                                             solution,
                                             system_rhs);
        }

        solve_time_step();

        output_results();

        if ((timestep_number == 1) &&
            (pre_refinement_step < n_adaptive_pre_refinement_steps))
          {
            refine_mesh (initial_global_refinement,
                         initial_global_refinement + n_adaptive_pre_refinement_steps);
            ++pre_refinement_step;

            tmp.reinit (solution.size());
            forcing_terms.reinit (solution.size());

            std::cout << std::endl;

            goto start_time_iteration;
          }
        else if ((timestep_number > 0) && (timestep_number % 5 == 0))
          {
            refine_mesh (initial_global_refinement,
                         initial_global_refinement + n_adaptive_pre_refinement_steps);
            tmp.reinit (solution.size());
            forcing_terms.reinit (solution.size());
          }

        old_solution = solution;
      }
  }
}


int main()
{
  try
    {
      using namespace dealii;
      using namespace AdditiveSimulation;

      ThermalProfile<2> heat_equation_solver;
      heat_equation_solver.run();

    }
  catch (std::exception &exc)
    {
      std::cerr << std::endl << std::endl
                << "----------------------------------------------------"
                << std::endl;
      std::cerr << "Exception on processing: " << std::endl << exc.what()
                << std::endl << "Aborting!" << std::endl
                << "----------------------------------------------------"
                << std::endl;

      return 1;
    }
  catch (...)
    {
      std::cerr << std::endl << std::endl
                << "----------------------------------------------------"
                << std::endl;
      std::cerr << "Unknown exception!" << std::endl << "Aborting!"
                << std::endl
                << "----------------------------------------------------"
                << std::endl;
      return 1;
    }

  return 0;
}

Reply via email to