How to access Dof values of solution vector according to their geometric location?

59 views
Skip to first unread message

Tim hyvärinen

unread,
Mar 25, 2024, 11:13:22 AM3/25/24
to deal.II User Group
Hi, deal.ii developers and users

Recently, I get this question as been mentioned in subject.

I have a saddle point problem on hand. The system of vector-valued PDEs is non-linear. I implement the solver with Newton iteration without line search. And I also need to set up a specific initial configuration for iteration. 

Here comes the question, I don't have clear idea how to access and write down a specific value on the 0-th solution vector according to every Dof's geometric location on grid.  

Let's say we have a 3-components vector-valued unknown. Geometry domain is  2 * 2 * 2 size cube.  I want to set Dofs, which are inside ball x^2+y^2+z^2=1,  to be  (1, 1, 1) at every vertex. While the rest of Dofs of the cube to be (1,0,0) at very vertex. 

I went through docs of DoFHandler,  DoFTools, ComponentMask and CellAccessor. Unfortunately, I only figured out that I can access certain DoFs in solution vector by loop over IndexSet, which is generated by DoFTools::extract_dofs(DofHandler., ComponentMask). I still no idea how to control the access through geometric information i.g., vertex's coordinates.

Is there any clue or idea how this could be done?

Best,
Timo

Wolfgang Bangerth

unread,
Mar 25, 2024, 12:13:44 PM3/25/24
to dea...@googlegroups.com

On 3/25/24 09:13, Tim hyvärinen wrote:
>
> Let's say we have a 3-components vector-valued unknown. Geometry domain
> is  2 * 2 * 2 size cube.  I want to set Dofs, which are inside ball
> x^2+y^2+z^2=1,  to be  (1, 1, 1) at every vertex. While the rest of Dofs
> of the cube to be (1,0,0) at very vertex.
>
> I went through docs of DoFHandler,  DoFTools, ComponentMask and
> CellAccessor. Unfortunately, I only figured out that I can access
> certain DoFs in solution vector by loop over IndexSet, which is
> generated by DoFTools::extract_dofs(DofHandler., ComponentMask). I still
> no idea how to control the access through geometric information i.g.,
> vertex's coordinates.

Tim:
you need to turn the problem around. You're *first* trying to partition
your DoFs into ones inside/outside the sphere and in a *second* step for
each element of the set assign them a value. Instead, combine the steps:
think of it as a loop over all DoFs and for each you determine whether
it is inside or outside the sphere, and assign a value.

In practice, the way to do this is to call
VectorTools::interpolate()
with a function object that will look like this:

class StartingValues : public Function<dim>
{
double vector_value (const Point<dim> &p) {
if (p inside sphere)
return 1,1,1
else
return 1,0,0
}
};

Best
W.
Reply all
Reply to author
Forward
0 new messages