Setting an initial condition by fixing the DOF values themselves

28 views
Skip to first unread message

Bruno Blais

unread,
Apr 25, 2019, 8:58:31 AM4/25/19
to deal.II User Group
Hello everyone,
I believe this is a relatively dumb question, but I seem to struggle with this basic concept.
I would like to be able to set-up an initial condition by fixing the value of the DOF themselves by using their x,y(,z) position with a ParsedFuction.

Generally, I set the initial condition by using an L2 projection of the function (for complex function and higher order element I know this is more appropriate).
However, for some stuff I would like to be able to fix the value of the DOF directly.
My issue is, through the doxygen, I have not found a way to loop through the DOF and to extract their position, even more when I have high order element or when I have a multiplicity (say velocity-vector + pressure).

What I would be looking into doing would be something similar to :

loop over local DOF;
  get DOF position
  get DOF component (u[0], u[1], u[2], p)
  calculate parsed function using the point
  set the value of the DOF
end

Is it something that is possible? This is a weird way of iterating since I know we always loop over the cells. Maybe there is a way to achieve this by looping over the cells and then looping over the DOF of the cells? This would be slightly redundant, but I do not care since I am doing this only once.

Thank you for everything!
Bruno


Wolfgang Bangerth

unread,
Apr 25, 2019, 9:32:09 AM4/25/19
to dea...@googlegroups.com
On 4/25/19 6:58 AM, Bruno Blais wrote:
> I would like to be able to set-up an initial condition by fixing the value of
> the DOF themselves by using their x,y(,z) position with a ParsedFuction.
>
> Generally, I set the initial condition by using an L2 projection of the
> function (for complex function and higher order element I know this is more
> appropriate).
> However, for some stuff I would like to be able to fix the value of the DOF
> directly.
> My issue is, through the doxygen, I have not found a way to loop through the
> DOF and to extract their position, even more when I have high order element or
> when I have a multiplicity (say velocity-vector + pressure).
>
> What I would be looking into doing would be something similar to :
>
> loop over local DOF;
>   get DOF position
>   get DOF component (u[0], u[1], u[2], p)
>   calculate parsed function using the point
>   set the value of the DOF
> end
>
> Is it something that is possible? This is a weird way of iterating since I
> know we always loop over the cells. Maybe there is a way to achieve this by
> looping over the cells and then looping over the DOF of the cells? This would
> be slightly redundant, but I do not care since I am doing this only once.

You can get the locations of DoFs using DoFTools::map_dofs_to_support_points().

But maybe the easier way is to use VectorTools::interpolate_boundary_values()
or project() and just pass it a function object that describes the function
you want to set in terms of (x,y,z). This could be your ParsedFunction.
interpolate_b_v() will then call your parsed function with a bunch of points
that happen to correspond to the DoF locations, but it makes the connection
internally and you no longer need to worry about which DoF sits where.

Best
W.


--
------------------------------------------------------------------------
Wolfgang Bangerth email: bang...@colostate.edu
www: http://www.math.colostate.edu/~bangerth/

Message has been deleted

Bruno Blais

unread,
Apr 25, 2019, 4:36:19 PM4/25/19
to deal.II User Group
Dear Wolfgang, this was easier than I thought.
I followed your suggestion and used VectorTools::interpolate.
Everything works as expected.
Thank you very much

Final solution:

 
// initialConditionParameters.uvw is the parsed function
 // newton_update is a local vector

  const FEValuesExtractors::Vector velocities (0);
  const FEValuesExtractors::Scalar pressure (dim);
  const MappingQ<dim>      mapping (degreeVelocity_,femParameters.qmapping_all);

  VectorTools::interpolate(mapping,
                           dof_handler,
                           initialConditionParameters.uvw,
                           newton_update,
                           fe.component_mask(velocities));

Thanks again!
Reply all
Reply to author
Forward
0 new messages