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.