Constrain a node instead of a face

41 views
Skip to first unread message

Giang Huynh

unread,
Feb 1, 2023, 10:51:09 PM2/1/23
to deal.II User Group
Hi all,

I have a simple domain having nodal coordinate as follows:
node 1: (0,0)
node 2: (1,0)
node 3: (1,1)
node 4: (0,1)
I want to fix node 1 in the x and y directions, and node 2 in only the y direction.
Currently, I just have known one way to apply constraints in Deal.II by using:

for(auto& cell: triangulation.active_cell_iterators())
{
    for (unsigned int f = 0; f< GeometryInfo<dim>::faces_per_cell; ++f)
    {
         if(cell->face(f)->at_boundary())
         {
              const Point<dim> face_center = cell->face(f)->center();
              if(std::abs(face_center[0])<=1.0e-10 )
              {
                    cell->face(f)->set_boundary_id(0);
              }
         }
      }
}
However, this way constrains a face instead of a node. How do I apply a constraint on a node only?

Thank you,
Giang

Wolfgang Bangerth

unread,
Feb 2, 2023, 3:52:03 PM2/2/23
to dea...@googlegroups.com

> I have a simple domain having nodal coordinate as follows:
> node 1: (0,0)
> node 2: (1,0)
> node 3: (1,1)
> node 4: (0,1)
> I want to fix node 1 in the x and y directions, and node 2 in only the y
> direction.

What you need to do is find out which vertex contains the node you care
about, then which DoFs are associated with that vertex, and then which
one of these corresponds to the x or y direction.

You'd do this as follows:

for(auto& cell: triangulation.active_cell_iterators())
for (unsigned int v = 0; v<cell->n_vertices(); ++v)
if (cell->vertex(v) = {0,0})
{
const types::global_dof_index i
= cell->vertex_dof_index(v,0); // x-DoF at that vertex
constraints.add_line(i);
constraints.add_inhomogeneity(i, 42); // constrain x-DoF to 42
}
else if (cell->vertex(v) = {1,0})
{
const types::global_dof_index i
= cell->vertex_dof_index(v,1); // y-DoF at that vertex
constraints.add_line(i);
constraints.add_inhomogeneity(i, 84); // constrain y-DoF to 84
}

Best
W.

--
------------------------------------------------------------------------
Wolfgang Bangerth email: bang...@colostate.edu
www: http://www.math.colostate.edu/~bangerth/
Reply all
Reply to author
Forward
0 new messages