Accessing cell data from its ID

75 views
Skip to first unread message

Corbin Foucart

unread,
Apr 29, 2021, 4:48:30 AM4/29/21
to deal.II User Group
Hi all,

I'm looking to map DoF from the bottom of an extruded volumetric mesh to the corresponding DOF on the surface of the mesh. Right now, I'm saving the cell "number"/ID of each cell in the bottom layer of the volume mesh, and want to match it with a surface cell by comparing their centers
  • I could loop over all the volume cells until I find the one matching the surface cell center, but as I have the cell numbers, I would rather access the cell center from the cell id (which looks to me like an unsigned int)
  • something like get_cell(cell_id)->center  --- is this possible?
  • Alternatively, I was thinking that a periodic boundary condition linking the bottom of the volume mesh with the top might be able to achieve the same thing, but I wasn't sure how to go about setting it up
Any pointers would be appreciated!
Corbin

simon...@gmail.com

unread,
Apr 29, 2021, 5:06:57 AM4/29/21
to deal.II User Group
Hi,
I'm not sure I understand exactly what you want to do, but if you know which cell you want in a triangulation by level and index you can get its center by creating the cell iterator. For example:

const int dim = 2;
Triangulation<dim> triangulation;
GridGenerator::hyper_cube(triangulation);

const unsigned int cell_level = 0, cell_index = 0;
const auto cell = Triangulation<dim>::active_cell_iterator(&triangulation,
                                                                                                      cell_level,
                                                                                                      cell_index);
std::cout << cell->center() << std::endl;


Maybe this answer is useful too:
https://github.com/dealii/dealii/wiki/Frequently-Asked-Questions#can-i-convert-triangulation-cell-iterators-to-dofhandler-cell-iterators

Best,
Simon

Daniel Arndt

unread,
Apr 29, 2021, 8:40:48 AM4/29/21
to dea...@googlegroups.com
Corbin,

if you only ever need the DoF mapping periodic DoFTools::make_periodicity_constrainst (https://www.dealii.org/current/doxygen/deal.II/namespaceDoFTools.html#a03324e6e060c6a55191b2c60ad871eab) sound like the right tool for you to use.
Just create a separate AffineConstraints object to be filled and hand it to that function. Then, you can loop through the filled object to either use it as a map directly or you can create a separate data structure. Note that the constraints might not be in the order (bottom -> top) you need them to be. So you might need to adjust that yourself.

Best,
Daniel


--
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+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dealii/122e1b62-e672-446b-8c25-ce6012c1fe3fn%40googlegroups.com.

Corbin Foucart

unread,
May 1, 2021, 9:36:02 PM5/1/21
to deal.II User Group
Thank you, Simon and David. Both answers were helpful. I will try implementing it both ways for practice.

Best,
Corbin

Corbin Foucart

unread,
May 6, 2021, 8:46:57 PM5/6/21
to deal.II User Group
To those who might be following in my footsteps and encounter similar questions:
  • For understanding how accessors/iterators work, the following page was indispensible: https://dealii.org/developer/doxygen/deal.II/group__Iterators.html -- I don't know how I missed it the first time around
  • For transferring bulk fields to surface fields and vice-versa, the GridGenerator::extract_boundary_mesh does *not* keep the dof orientation between the surface cells and the bulk cell faces from which they were extracted
  • However, the map that it returns can be coupled with a DoFHandler loop to construct a DoF map between the extracted surface field and bulk fields, which makes data transfer between the two painless once it's done
    • If all else fails, you can do a one-time comparison of support points to build the DOF map, see the documentation for DoFTools::map_to_support_points
I found that this approach was easier than the periodic boundary condition approach, although both worked.

Thanks, Simon and David!
Corbin
Reply all
Reply to author
Forward
0 new messages