C++ language in step16

33 views
Skip to first unread message

yy.wayne

unread,
Sep 25, 2022, 11:02:57 PM9/25/22
to deal.II User Group
In step16 function assemble_system() and assemble_multigrid(), there are 2 variables/functions defined as:
auto cell_worker =   
    [&](const typename DoFHandler<dim>::active_cell_iterator &cell
        ScratchData<dim> & scratch_data
        CopyData & copy_data
       { this->cell_worker(cell, scratch_data, copy_data); };
auto copier
    [&](const CopyData &cd
       { this->constraints.distribute_local_to_global(cd.cell_matrix,
                                                                                       cd.cell_rhs, 
                                                                                       cd.local_dof_indices, 
                                                                                       system_matrix, system_rhs); };
I'm not expert in C++ and these codes seem confusing to me. Are cell_worker and copier defined here variables or functions? And why we define a new cell_worker here (is it because we cannot directly pass this->cell_worker to MeshWorker::mesh_loop) ? Sorry it might be silly. Should I know the terminology for this "technique" I can google myself.
Thank you.

Daniel Arndt

unread,
Sep 26, 2022, 8:42:54 AM9/26/22
to dea...@googlegroups.com
cell_worker and copier are lambda functions. You can think of them as in-place structs with a call operator (operator()) with the specified signature. We define a new cell_worker object because the place we are passing it into expects the object to have a call operator that does what this->cell_worker implements.

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/c284ce35-13ec-4afd-8ef3-5fdde8fd68can%40googlegroups.com.

yy.wayne

unread,
Sep 26, 2022, 11:15:19 AM9/26/22
to deal.II User Group
Thank you Daniel.
Reply all
Reply to author
Forward
0 new messages