Hello Dr. Bangerth,
It gives wrong(or maybe not enough accuracy) results immediately after
projection. Projection looks fine on the boundaries (I checked both the
plot and error results with Q1 elements+without any refinement, when
everything happens only on boundary). I use 3 different finite element sets
in the same project. Projection on 2 of them looks perfect except this one.
I also attach the corresponding code. You will see the error results
immediately after running.
Thanks,

On Sun, Nov 5, 2017 at 5:55 PM, Wolfgang Bangerth <[email protected]>
wrote:

> On 11/04/2017 02:53 PM, Mustafa Aggul wrote:
>
>>
>> I am trying to project the initial conditions on the following FE space:
>> lsfe(FE_Q<dim>(2), dim). It is quite a straightforward job, but the error
>> and plot of the projected vector (especially upon choosing constant initial
>> condition to make the error basically 0) doesn't look as it supposed to be.
>> I have spent couple of days figuring out what might have gone wrong, but
>> couldn't find a reason. Could you check to see what's going on?
>>
>
> Mustafa -- it's hard to tell. The code does not look suspicious, but you
> don't say what exactly you see? In your example, how does the solution look
> like? Does it look wrong already immediately after projecting the initial
> conditions, or only after doing one time step? You will have to give us
> more information about how exactly things go wrong so that we can help you!
> :-)
>
> Best
>  W.
>
>
> --
> ------------------------------------------------------------------------
> Wolfgang Bangerth          email:                 [email protected]
>                            www: http://www.math.colostate.edu/~bangerth/
>
>
> --
> The deal.II project is located at http://www.dealii.org/
> For mailing list/forum options, see https://groups.google.com/d/fo
> rum/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].
> For more options, visit https://groups.google.com/d/optout.
>



-- 
*Mustafa Aggul*
*Department of Mathematics*
*Michigan Technological University*
*1400 Townsend Drive*
*Houghton, Michigan 49931-1295*
*Tel: 906-487-3135*

-- 
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].
For more options, visit https://groups.google.com/d/optout.
/* ---------------------------------------------------------------------
 *
 * Copyright (C) 2008 - 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: Liang Zhao and Timo Heister, Clemson University, 2016
 */

// @sect3{Include files}

// As usual, we start by including some well-known files:
#include <deal.II/base/quadrature_lib.h>
#include <deal.II/base/function.h>
#include <deal.II/base/logstream.h>
#include <deal.II/base/utilities.h>
#include <deal.II/base/tensor.h>

#include <deal.II/lac/block_vector.h>
#include <deal.II/lac/full_matrix.h>
#include <deal.II/lac/block_sparse_matrix.h>
#include <deal.II/lac/dynamic_sparsity_pattern.h>
#include <deal.II/lac/solver_cg.h>
#include <deal.II/lac/solver_gmres.h>
#include <deal.II/lac/precondition.h>
#include <deal.II/lac/constraint_matrix.h>
#include <deal.II/lac/sparse_direct.h>

#include <deal.II/grid/tria.h>
#include <deal.II/grid/grid_generator.h>
#include <deal.II/grid/tria_accessor.h>
#include <deal.II/grid/tria_iterator.h>
#include <deal.II/grid/manifold_lib.h>
#include <deal.II/grid/grid_refinement.h>
#include <deal.II/grid/tria_boundary_lib.h>
#include <deal.II/grid/grid_tools.h>

#include <deal.II/dofs/dof_handler.h>
#include <deal.II/dofs/dof_renumbering.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_system.h>
#include <deal.II/fe/fe_values.h>

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

// To transfer solutions between meshes, this file is included:
#include <deal.II/numerics/solution_transfer.h>

#include <fstream>
#include <iostream>
#include <sstream>


namespace deferred_correction_with_AV_approximation
{
  using namespace dealii;

  // @sect3{The <code>NavierStokesProblem</code> class template}

  // This is the main function and its member functions.
  // As explained in the introduction, what we obtain at each step is the
  // Newton's update, so we define two variables: the present solution
  // and the update. Additionally, the evaluation point is
  // for temporarily holding Newton update in line search. A sparse matrix
  // for the pressure mass matrix is created for the operator of a block Schur
  // complement preconditioner. We use one ConstraintMatrix for Dirichlet boundary
  // conditions at the initial step and a zero ConstraintMatrix for the Newton
  // is defined by 1/Re which has been discussed in the introduction.

  template <int dim>
  class deferred_correction_with_AV_approximation1
  {
  public:
    deferred_correction_with_AV_approximation1(const double viscosity,
						   const double delta_t,
						   const double delta,
						   const double final_time);
    void run(const unsigned int n_refinements);


  private:
    void setup_dofs();
    void initialize_system_LS();
    void update_constrains_LS(double tn);
    void initial_construction();
    void output_results_LS (const double tnplus1,
        	    			 Vector<double> zeta) const;
    void compute_errors_LS (const double tnplus1,
    			 	 	 	 Vector<double> solution) const;

    const double delta_t;
    const double delta;
    const double final_time;
    const double viscosity;
    double tn;
    double tnplus1;

    Triangulation<dim>           triangulation;

    //
    //intermediate step to find laplacian
    //

    FESystem<dim>                lsfe;
    DoFHandler<dim>              ls_dof_handler;

    ConstraintMatrix             ls_constraint_matrix;

    SparsityPattern        		 ls_sparsity_pattern;
    SparseMatrix<double>    	 ls_system_matrix;

    Vector<double>           	 zeta;
    Vector<double>          	 ls_linear_solver_solution;
    Vector<double>          	 old_zeta;

  };

  template <int dim>
  class lsExactSolution : public Function<dim>
  {
  public:
	  lsExactSolution () : Function<dim>(dim) {}
    virtual void vector_value (const Point<dim> &p,
                               Vector<double>   &value) const;
  };
  template <int dim>
  void
  lsExactSolution<dim>::vector_value (const Point<dim> &p,
                                    Vector<double>   &values) const
  {
		const double t = this->get_time();
		const double x = p[0];
		const double y = p[1];

	    values[0] = 1;
	    values[1] = 0;
  }



  template <int dim>
  deferred_correction_with_AV_approximation1<dim>::deferred_correction_with_AV_approximation1(const double viscosity,
													  const double delta_t,
													  const double delta,
													  const double final_time)
    :
	delta_t(delta_t),
	delta(delta),
	final_time(final_time),
    viscosity(viscosity),
	tn(0.0),
	tnplus1(0.0),
    triangulation(Triangulation<dim>::maximum_smoothing),

    lsfe(FE_Q<dim>(2), dim),
    ls_dof_handler(triangulation)

	{}



  template <int dim>
  void deferred_correction_with_AV_approximation1<dim>::setup_dofs()
  {
	    ls_system_matrix.clear();
	    {
	    	ls_dof_handler.distribute_dofs(lsfe);

	    }

  }


  // @sect4{StationaryNavierStokes::initialize_system_AV}
  // On each mesh the sparsity pattern and the size of the linear system
  // are different. This function initializes them after mesh refinement.

  template <int dim>
  void deferred_correction_with_AV_approximation1<dim>::initialize_system_LS()
  {
    {
      DynamicSparsityPattern l_dsp (ls_dof_handler.n_dofs());
      DoFTools::make_sparsity_pattern (ls_dof_handler, l_dsp, ls_constraint_matrix);
      ls_sparsity_pattern.copy_from (l_dsp);
    }

    ls_system_matrix.reinit (ls_sparsity_pattern);

    zeta.reinit (ls_dof_handler.n_dofs());
    old_zeta.reinit (ls_dof_handler.n_dofs());
    ls_linear_solver_solution.reinit (ls_dof_handler.n_dofs());

    unsigned int dof_w = ls_dof_handler.n_dofs();

    std::cout << "************************************************************" << std::endl;
    std::cout << std::endl;
    std::cout << "Number of degrees of freedom in the LS step: "
              << ls_dof_handler.n_dofs()
              << " (" << dof_w << ')'
              << std::endl;
    std::cout << std::endl;

  }

  // @sect4{StationaryNavierStokes::update_constrains_LS}
  // Updates constrains for the current time

  template <int dim>
  void deferred_correction_with_AV_approximation1<dim>::update_constrains_LS(double tn)
  {
	  ls_constraint_matrix.clear();
	    {
		  lsExactSolution<dim> ls_boundary_values;
		  ls_boundary_values.set_time (tn);

		  VectorTools::interpolate_boundary_values (ls_dof_handler,
	    	                                            0,
														ls_boundary_values,
	    	                                            ls_constraint_matrix);
	    }

	   ls_constraint_matrix.close();

	   std::cout << "Constrain Matrix has been updated for LS approximation at tnplus1 = " << tnplus1 << std::endl;
  }


  // @sect4{StationaryNavierStokes::output_results}
  // This function is the same as in step-22.
  template <int dim>
  void deferred_correction_with_AV_approximation1<dim>::output_results_LS (const double tn,
		  	  	  	  	  	  	  	  	  	  	  			Vector<double> zeta)  const
  {
    std::vector<std::string> solution_names (dim, "velocity_l");

    std::vector<DataComponentInterpretation::DataComponentInterpretation>
    data_component_interpretation
    (dim, DataComponentInterpretation::component_is_part_of_vector);

    DataOut<dim> data_out;
    data_out.attach_dof_handler (ls_dof_handler);
    data_out.add_data_vector (zeta, solution_names,
                              DataOut<dim>::type_dof_data,
                              data_component_interpretation);
    data_out.build_patches ();

    std::ostringstream filename;
    filename << tn
    		 << "_LS"
             << ".vtk";

    std::ofstream output (filename.str().c_str());
    data_out.write_vtk (output);
  }


  template <int dim>
  void deferred_correction_with_AV_approximation1<dim>::compute_errors_LS (double tnplus1,
		  	  	  	  	  	  	  	  	  	  	  				Vector<double> zeta) const
  {
    lsExactSolution<dim> exact_solution;
    exact_solution.set_time(tnplus1);

    Vector<double> cellwise_errors (triangulation.n_active_cells());
    QTrapez<1>     q_trapez;
    QIterated<dim> quadrature (q_trapez, 1+2 /*degree +1*/);

    VectorTools::integrate_difference (ls_dof_handler, zeta, exact_solution,
                                       cellwise_errors, quadrature,
                                       VectorTools::L2_norm);
    double current_velocity_error = VectorTools::compute_global_error(triangulation,
                                                                cellwise_errors,
                                                                VectorTools::L2_norm);
    std::cout << "Errors: ||e_ul||_L2 = " << current_velocity_error
			  << ",   at time = " << tnplus1
              << std::endl;
    std::cout << std::endl;
  }



  // @sect4{StationaryNavierStokes::run_AV}
  // This is the last step to run for AV approximation

  template <int dim>
  void deferred_correction_with_AV_approximation1<dim>::initial_construction()
  {	  //
	  //LS
	  //

	  update_constrains_LS(tn);
	  initialize_system_LS();

	  lsExactSolution<dim> ls_initial_values;
	  ls_initial_values.set_time (tn);

	  VectorTools::project (ls_dof_handler,
	                        ls_constraint_matrix,
	                        QGauss<dim>(1+2 /*degree + 2*/),
							ls_initial_values,
							old_zeta);



	  zeta=old_zeta;

	  compute_errors_LS(tn, zeta);
	  output_results_LS(tn, zeta);
  }

  // @sect4{StationaryNavierStokes::run}
  // This is the last step to run all the functions

  template <int dim>
  void deferred_correction_with_AV_approximation1<dim>::run(const unsigned int n_refinements)
  {
	    GridGenerator::hyper_cube(triangulation);
	    triangulation.refine_global(n_refinements);

	    std::cout << "Number of active cells: "
	              << triangulation.n_active_cells()
	              << std::endl;
	    std::cout << "************************************************************" << std::endl;

	    setup_dofs();
	    initial_construction();
  }
}

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

	      double nu = 1.0;
	      unsigned int n_refinements = 0;
	      double final_time = 1;

	      double delta_t = final_time/std::pow(2,n_refinements);
	      unsigned int n_time_steps = round(1/delta_t);
	      double delta = delta_t;

	      std::cout << "************************************************************" << std::endl;
	      std::cout << n_time_steps << " time steps will be taken with " << delta_t << " increments" <<std::endl;
	      std::cout << "************************************************************" << std::endl;

	      deferred_correction_with_AV_approximation1<2> flow(nu,delta_t,delta,final_time);
	      flow.run(n_refinements);
	    }

  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