is there a way to refine mesh only in one direction

243 views
Skip to first unread message

Jaekwang Kim

unread,
Mar 29, 2017, 3:01:49 PM3/29/17
to deal.II User Group
Hi all,

I am running deal.ii for study non-newtonian fluids. 

I have a mesh which is attached. 

I am using AMR, but, when I use just conventional function, "cell->refine_flag()" for refinement, 

the flagged cell divide into 4. 

but as my problem only need high resolution in r-direction, 
I want to turn off theta directional refinement. 

So, in red square... I attached my desired refinement way..... 

will that be way to accomplish this? , If needed, I think I can try merge some cell after refinement... 

if I need to describe question. please just let me know

Thanks. 


Bests, 
Jaekwang Kim 

Bruno Turcksin

unread,
Mar 29, 2017, 3:24:28 PM3/29/17
to deal.II User Group
Jaekwang,

you can do anisotropic refinement (http://dealii.org/developer/doxygen/deal.II/classCellAccessor.html#afb6cc537720a5b6381c237abe0887de2) but only in serial. So depending if your code is parallel or not this may be what you are looking for.

Best,

Bruno

Timo Heister

unread,
Mar 29, 2017, 3:28:46 PM3/29/17
to dea...@googlegroups.com
To add to Bruno's answer:

If you don't want to use anisotropic refinement you have two other options:
1. Just accept that you get additional refinement in areas/directions you don't particularly care about. If you have a realistic computation, you likely need to refine many more times and thus the effect should be less pronounced than it is in your example.
2. You may be able to start with a coarse mesh that is more refined along a certain direction to suit your problem (for example by using gmsh like it is done in step-49).

--
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 dealii+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Jaekwang Kim

unread,
Mar 29, 2017, 8:37:28 PM3/29/17
to deal.II User Group
thanks,

I would need it and I am still running serially 

I am sorry but I am not that good at c++, so I was bit confused how to use this function. 

I have just set flag cell like

cell->set_refine_flag ();


Reading the document pages, you linked, I can understand that I should put some argument inside parenthesis. 
I think I should cut my cell in y-direciton (thought that it is  y in local cell direction, it is why), so my input should be.... 

cell->set_refine_flag (RefinementCase::cut_y);


but I get error as...

/Users/kimjaekwang/Programs/dealii/examples/step-1/step-1.cc:79:42: error: 

      'RefinementCase' is not a class, namespace, or enumeration

                  cell->set_refine_flag (RefinementCase::cut_y);

                                         ^

/Users/kimjaekwang/Programs/dealii/include/deal.II/base/geometry_info.h:293:7: note: 

      'RefinementCase' declared here

class RefinementCase : public RefinementPossibilities<dim>



Thanks.



2017년 3월 29일 수요일 오후 2시 24분 28초 UTC-5, Bruno Turcksin 님의 말:

Wolfgang Bangerth

unread,
Mar 29, 2017, 11:20:24 PM3/29/17
to dea...@googlegroups.com
On 03/29/2017 06:37 PM, Jaekwang Kim wrote:
>
> I am sorry but I am not that good at c++, so I was bit confused how to use
> this function.
>
> I have just set flag cell like
>
> *cell->set_refine_flag ();*
>
>
> Reading the document pages, you linked, I can understand that I should put
> some argument inside parenthesis.
> I think I should cut my cell in y-direciton (thought that it is y in local
> cell direction, it is why), so my input should be....
>
> cell->set_refine_flag (RefinementCase::cut_y);
>
>
> but I get error as...
>
> *//Users/kimjaekwang/Programs/dealii/examples/step-1/step-1.cc:79:42:
> /**/error: /*
>
> */ 'RefinementCase' is not a class, namespace, or enumeration/*
>
> / cell->set_refine_flag (RefinementCase::cut_y);/
>
> */ ^/*
>
> *//Users/kimjaekwang/Programs/dealii/include/deal.II/base/geometry_info.h:293:7:
> /**/note: /*
>
> / 'RefinementCase' declared here/
>
> /class RefinementCase : public RefinementPossibilities<dim>/
>


You should read through step-30 to see how this is done.
Best
W.

--
------------------------------------------------------------------------
Wolfgang Bangerth email: bang...@colostate.edu
www: http://www.math.colostate.edu/~bangerth/

Jaekwang Kim

unread,
Mar 30, 2017, 5:39:27 PM3/30/17
to deal.II User Group, bang...@colostate.edu
Always thanks for you. 
I have read step-30, and now i understand how it is done,
I was trying to implement on my problem as like....


Frist, refine_mesh function , I have designated which cell to be refined, 

    template <int dim>

    void

    StokesProblem<dim>::refine_mesh (const unsigned int refinement_cycle, double max_shear)

    //AMR based on Cellwise Shear-rate

    {

        

        GridRefinement::refine_and_coarsen_fixed_number (triangulation,

                                                         cellwise_shear_rate,

                                                         0.1, 0.0); //Here I marked what cells to be refined 

        

        set_anisotropic_flags();//and I called additional function to set anisotropic direction.  

        

        SolutionTransfer<dim,BlockVector<double>> solution_transfer(dof_handler);

        //Prepare Solution Transfer for Block vector solution

        

        //This one is problematic

        triangulation.prepare_coarsening_and_refinement ();

        

        solution_transfer.prepare_for_coarsening_and_refinement(solution);

    

        triangulation.execute_coarsening_and_refinement ();

        

        dof_handler.distribute_dofs (fe);

        DoFRenumbering::Cuthill_McKee (dof_handler);

      

        

        

        std::vector<unsigned int> block_component (dim+1,0);

        block_component[dim] = 1;

        DoFRenumbering::component_wise (dof_handler, block_component);

      

       

     

        triangulation.execute_coarsening_and_refinement ();

     

        std::vector<types::global_dof_index> dofs_per_block (2);

        DoFTools::count_dofs_per_block (dof_handler, dofs_per_block, block_component);

        const unsigned int n_u = dofs_per_block[0], n_p = dofs_per_block[1];

        

        

        // save new space for previous solution

        previous_solution.reinit (2);

        previous_solution.block(0).reinit (n_u);

        previous_solution.block(1).reinit (n_p);

        previous_solution.collect_sizes ();

        

        

        //Transfer solution

        solution_transfer.interpolate(solution, previous_solution);

        

    }

    


After that, I am trying to setting one direction to be refined. cut_x, cut_y, or cut_xy 


template <int dim>

    void

    StokesProblem<dim>::set_anisotropic_flags ()

    {

        typename DoFHandler<dim>::active_cell_iterator cell=dof_handler.begin_active()

        ,endc=dof_handler.end();

        

        for (; cell!=endc; ++cell)

        {

            if (cell->refine_flag_set())

            {

                //For a just test case, I am trying to cut in one direction ,x y  

               //std::cout <<" Now just pass"<<std::endl;

              Case1 // cell->set_refine_flag(RefinementCase<dim>::cut_x);

              Case2 //  cell->set_refine_flag(RefinementCase<dim>::cut_y);

                 cell->set_refine_flag(RefinementCase<dim>::cut_xy); //For this case, the cell will be just cut as isotropy refinement 

            }

        }

        

    

    }


Among three cases, the code is one working with "cell->set_refine_flag(RefinementCase<dim>::cut_xy);" 


When I try to refine my cells only in x or y direction, I just receives error as follow...


cell->set_refine_flag(RefinementCase<dim>::cut_x);

cell->set_refine_flag(RefinementCase<dim>::cut_y);


especially this error has occurred when code is running the line " triangulation.prepare_coarsening_and_refinement () "... in refinement function.. 


Do you have any ideas what might be a possible problem ? 



An error occurred in line <12146> of file </Users/kimjaekwang/dealii-8.4.1/source/grid/tria.cc> in function

    void dealii::(anonymous namespace)::possibly_refine_unrefined_island(const typename Triangulation<dim, spacedim>::cell_iterator &, const bool) [dim = 2, spacedim = 2]

The violated condition was: 

    cell->refine_flag_set() == false

The name and call sequence of the exception was:

    ExcInternalError()

Additional Information: 

This exception -- which is used in many places in the library -- usually indicates that some condition which the author of the code thought must be satisfied at a certain point in an algorithm, is not fulfilled. An example would be that the first part of an algorithm sorts elements of an array in ascending order, and a second part of the algorithm later encounters an an element that is not larger than the previous one.


There is usually not very much you can do if you encounter such an exception since it indicates an error in deal.II, not in your own program. Try to come up with the smallest possible program that still demonstrates the error and contact the deal.II mailing lists with it to obtain help.




2017년 3월 29일 수요일 오후 10시 20분 24초 UTC-5, Wolfgang Bangerth 님의 말:

Bruno Turcksin

unread,
Mar 31, 2017, 3:22:37 PM3/31/17
to dea...@googlegroups.com
Jaekwang,

2017-03-30 17:39 GMT-04:00 Jaekwang Kim <jaekw...@gmail.com>:
> //This one is problematic
> triangulation.prepare_coarsening_and_refinement ();
It could be a bug in the library, most people don't use anisotropic
refinement. This function is not always necessary (and it is not used
in step-30). So what happens if you remove it? For us to really help
you, we need a small code that triggers the error.

Best,

Bruno

Jaekwang Kim

unread,
Mar 31, 2017, 3:30:10 PM3/31/17
to deal.II User Group
Thanks Bruno ! and Dr. Wolfgang! 

I found that what was the problem.

I was using 'maximum' Meshsmoothing which does not allow 

So, It was not a bug of deal.ii but I was using wrong smoothing method that does not go along with anisotropy, 

I just changed my Meshsmoothing Method, that allow anisotropy refinement. 

For my problem, anisotropy refinement still works very well!



Thank you agains all of you 

Jaekwang


2017년 3월 31일 금요일 오후 2시 22분 37초 UTC-5, Bruno Turcksin 님의 말:

Wolfgang Bangerth

unread,
Mar 31, 2017, 7:08:16 PM3/31/17
to dea...@googlegroups.com
On 03/31/2017 01:30 PM, Jaekwang Kim wrote:
>
> I found that what was the problem.
>
> I was using 'maximum' Meshsmoothing which does not allow
>
> So, It was not a bug of deal.ii but I was using wrong smoothing method
> that does not go along with anisotropy,

Well, it is still a bug that the library did not handle this in a more
gracefully way, i.e., that you did not get a polite error that suggests
what is happening here and why.

So I would still be interested in having a small testcase that shows the
problem and that would allow us to look into this some more...

Jaekwang Kim

unread,
Apr 1, 2017, 4:23:15 PM4/1/17
to deal.II User Group, bang...@colostate.edu

Here, I attached simple case that I encounter same error message. 

Most of code is just same at that of step-5, but I am using mesh-file that is made from other software. (I attach my mesh file too)



At constructor, there is a issue. 



template <int dim>

Step5<dim>::Step5 () :

  triangulation (Triangulation<dim>::maximum_smoothing), //If I don't have this line, the code works well with anisotropy refinement.  

However, if I use Maximum_smoothing for my triangulation, I run into same error message. 

  fe (1),

  dof_handler (triangulation)

{}





2017년 3월 31일 금요일 오후 6시 8분 16초 UTC-5, Wolfgang Bangerth 님의 말:
CMakeLists.txt
mesh_stretch.inp
step-5.cc
Reply all
Reply to author
Forward
0 new messages