Applying boundary values in parll::distr:triang setting for two dof_handler Sparsematrux

59 views
Skip to first unread message

gabriel...@koeln.de

unread,
Mar 26, 2019, 4:43:00 AM3/26/19
to deal.II User Group
Hey everyone,

I am trying to apply boundary conditions on a Sparsematrix with two Dof_handlers in a parallel::distributed::trinagulation setting for the Step-35 tutorial.

At initializing the gradient_operator, I have an object with two Dof_Handlers, which I use for a sparsity pattern.

DoFTools::make_sparsity_pattern (dof_handler_velocity,dof_handler_pressure,dsp);

But when I apply boundary values to a PETSCWrapper::SparseMatrix using this sparsity pattern I get the following error
at the function MatrixTools::apply_boundary_values"

                      The violated condition was: !has_ghost_elements()


I tried another way to apply the boundary conditions with the use of a COnstraintMatrix as in the Step-40 tutorial. But in that case the
make_sparsity_pattern function doesn't work, when I use the commandd:

DoFTools::make_sparsity_pattern (dof_handler_velocity,dof_handler_pressure,dsp,constraints_velocity,false);

(There I get the error "candidate expects 3 arguments, 5 provided).


Does somebody have an idea how I can apply the boundary values efficiently in that case?

Thanks a lot and best regards

Gabriel

Daniel Arndt

unread,
Mar 26, 2019, 8:32:42 AM3/26/19
to deal.II User Group
Gabriel,


I am trying to apply boundary conditions on a Sparsematrix with two Dof_handlers in a parallel::distributed::trinagulation setting for the Step-35 tutorial.

At initializing the gradient_operator, I have an object with two Dof_Handlers, which I use for a sparsity pattern.

DoFTools::make_sparsity_pattern (dof_handler_velocity,dof_handler_pressure,dsp);

But when I apply boundary values to a PETSCWrapper::SparseMatrix using this sparsity pattern I get the following error
at the function MatrixTools::apply_boundary_values"

                      The violated condition was: !has_ghost_elements()

This issue does not come unexpected if you don't tell DoFTools::make_sparsity_pattern about the constraints you wan't to use.  :-)
 

I tried another way to apply the boundary conditions with the use of a COnstraintMatrix as in the Step-40 tutorial. But in that case the
make_sparsity_pattern function doesn't work, when I use the commandd:

DoFTools::make_sparsity_pattern (dof_handler_velocity,dof_handler_pressure,dsp,constraints_velocity,false);

(There I get the error "candidate expects 3 arguments, 5 provided).

A function taking two DoFHandle objects and an AffineConstraints (resp. ConstraintMatrix) object is simply not yet implemented.
It should not be terribly difficult to do that, though. You could essentially just give the overload of DoFTools::make_sparsity_pattern
some more (defaulted) parameters and replace sparsity.add_entries(...) with constraints.add_entries_local_to_global(...).

Do you want to give it a shot? We would happily take such a contribution! Feel free to ask if you have any questions, but

Best,
Daniel

Gabriel Peters

unread,
Mar 26, 2019, 8:55:55 AM3/26/19
to dea...@googlegroups.com
Hi. Thanks a lot for the advice.
I will Try it tomorrow and send a response whether it works.

Regards

Gabriel




Gabriel Peters
Endenicher Str. 310
53121 Bonn
00491525/5478185
Gabriel...@koeln.de

Am 26.03.19 um 13:32 schrieb Daniel Arndt
> --
> 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.
> For more options, visit https://groups.google.com/d/optout.

Gabriel Peters

unread,
Mar 27, 2019, 6:16:18 AM3/27/19
to dea...@googlegroups.com
 
Hey, I just worked through the make_sparsity_pattern code.
I think I know how to fix the mentioned problem. But I dont understand the
how to use the "bool_dof_mask" in the correct way. It is used in he constraints.add_entries_local_to_global(...)
function.
In the make_sparsity_pattern function with a single dof_handler and a constraintmatrix, it is constructed by a fe_collection.
But I don't see how to construct the bool_dof_mask with 2 dof_handlers and respectively 2 fe_collections.
Do you have a clue?
 
Best
Gabriel
Gesendet: Dienstag, 26. März 2019 um 13:32 Uhr
Von: "Daniel Arndt" <daniel...@iwr.uni-heidelberg.de>
An: "deal.II User Group" <dea...@googlegroups.com>
Betreff: [deal.II] Re: Applying boundary values in parll::distr:triang setting for two dof_handler Sparsematrux

Daniel Arndt

unread,
Mar 27, 2019, 8:58:47 AM3/27/19
to deal.II User Group
Gabriel,


Am Mittwoch, 27. März 2019 06:16:18 UTC-4 schrieb Gabriel Peters:
Hey, I just worked through the make_sparsity_pattern code.
I think I know how to fix the mentioned problem. But I dont understand the
how to use the "bool_dof_mask" in the correct way. It is used in he constraints.add_entries_local_to_global(...)
function.
In the make_sparsity_pattern function with a single dof_handler and a constraintmatrix, it is constructed by a fe_collection.
But I don't see how to construct the bool_dof_mask with 2 dof_handlers and respectively 2 fe_collections.
Do you have a clue?
 
"bool_dof_mask" is only used in case the make_*_pattern has a `const Table<2, Coupling> & couplings` parameter. That is currently not the case for the function you are looking at.
For being backward-compatible we need to provide/keep the

void DoFTools::make_sparsity_pattern ( const DoFHandlerType &  dof_row,
                                                           const DoFHandlerType &  dof_col,
                                                           SparsityPatternType & sparsity )

interface anyway, it is fine to add defaulted parameters at the end, but adding `const Table<2, Coupling> & couplings` as third parameter would not.
For now, I would simply assume that all components couple and ignore the last argument for add_entries_local_to_global. We can always create another overload later if specifying the coupling is desired/necessary.

Best,
Daniel

Gabriel Peters

unread,
Mar 27, 2019, 9:12:51 AM3/27/19
to dea...@googlegroups.com
Okay
Thanks a lot.
If it works now, I will contribute it.

Best

Gabriel




Gabriel Peters
Endenicher Str. 310
53121 Bonn
00491525/5478185
Gabriel...@koeln.de

Am 27.03.19 um 13:58 schrieb Daniel Arndt

gabriel...@koeln.de

unread,
Mar 28, 2019, 1:25:37 PM3/28/19
to deal.II User Group
Hey, its me again.
Today I had various tries fixing the upper problem.

At first I extended the make_sparsity_pattern function to

void DoFTools::make_sparsity_pattern ( const DoFHandlerType &  dof_row,
                                                           const DoFHandlerType &  dof_col,
                                                           SparsityPatternType & sparsity,
                                                           const ConstraintMatrix    &constraints,
                                                           const bool                 keep_constrained_dofs)

and also changed the dof_tools.h file in deal.II\source\dofs and changed the adding function;
but when I compiled this I got lots of errors of this kind:
                         error: template-id ‘make_sparsity_pattern<dealii::hp::DoFHandler<1, 3>, dealii::BlockDynamicSparsityPattern>’ for ‘void dealii::DoFTools::make_sparsity_pattern(const dealii::hp::DoFHandler<1, 3>&, const dealii::hp::DoFHandler<1, 3>&, dealii::BlockDynamicSparsityPattern&)’ does not match any template declaration



My second attempt was to make a new function, with a different name, which takes the same arguments as above and does exactly was the classical make_sp_pt(row_id,col_id,sparsity) function does, up to the constraints.add... function.
I also added the header of these function to the dof_tools.h file.
This compiled fine, but when I used this function in my program I got the error:
      undefined reference to: (function parameters).


Could you maybe tel me what I did wrong, or did I do an fundamental error at editting the deal.ii code?


Thanks a lot again and sorry for the long message

Gabriel

Daniel Arndt

unread,
Mar 28, 2019, 4:37:19 PM3/28/19
to deal.II User Group
Gabriel,

At first I extended the make_sparsity_pattern function to

void DoFTools::make_sparsity_pattern ( const DoFHandlerType &  dof_row,
                                                           const DoFHandlerType &  dof_col,
                                                           SparsityPatternType & sparsity,
                                                           const ConstraintMatrix    &constraints,
                                                           const bool                 keep_constrained_dofs)

and also changed the dof_tools.h file in deal.II\source\dofs and changed the adding function;
but when I compiled this I got lots of errors of this kind:
                         error: template-id ‘make_sparsity_pattern<dealii::hp::DoFHandler<1, 3>, dealii::BlockDynamicSparsityPattern>’ for ‘void dealii::DoFTools::make_sparsity_pattern(const dealii::hp::DoFHandler<1, 3>&, const dealii::hp::DoFHandler<1, 3>&, dealii::BlockDynamicSparsityPattern&)’ does not match any template declaration

 
This looks like you were not adapting the signature in the function's definition in source/dofs/dof_tools_constraints.h. It still only has three instead of five parameters.
 
My second attempt was to make a new function, with a different name, which takes the same arguments as above and does exactly was the classical make_sp_pt(row_id,col_id,sparsity) function does, up to the constraints.add... function.
I also added the header of these function to the dof_tools.h file.
This compiled fine, but when I used this function in my program I got the error:
      undefined reference to: (function parameters).
 
This looks like you didn't provide a definition but only a declaration.

Do you have your changes in a GitHub branch such that we can have a look what you did precisely?

Best,
Daniel

gabriel...@koeln.de

unread,
Apr 1, 2019, 9:05:46 AM4/1/19
to deal.II User Group
Hey I just added my changes to a github branch ( https://github.com/gabpeters/dealii/tree/sparsity )
I changed the make_sparsity_pattern(dof_row,dor_col,sparsity) function and also changed the header in the
dof_tools.h file and the signature in the dof_tools_sparsity.inst.in file.
But still I get the following error, when I compile my code:

undefined reference to `void dealii::DoFTools::make_sparsity_pattern<dealii::DoFHandler<3, 3>,
                                          dealii::DynamicSparsityPattern>(dealii::DoFHandler<3, 3> const&, dealii::DoFHandler<3, 3>
                                     const&, dealii::DynamicSparsityPattern&, dealii::ConstraintMatrix const&, bool)'

Did I still forget to change any reference?
Best
Gabriel

PS, you can ignore the makes_sparsity_pattern(...) function which I added to dof_tools_sparsity.cc

Best,
Daniel

Wolfgang Bangerth

unread,
Apr 1, 2019, 11:45:34 AM4/1/19
to dea...@googlegroups.com
On 4/1/19 7:05 AM, gabriel...@koeln.de wrote:
>
> Hey I just added my changes to a github branch (
> https://github.com/gabpeters/dealii/tree/sparsity )
> I changed the make_sparsity_pattern(dof_row,dor_col,sparsity) function
> and also changed the header in the
> dof_tools.h file and the signature in the dof_tools_sparsity.inst.in file.
> But still I get the following error, when I compile my code:
>
> undefined reference to `void
> dealii::DoFTools::make_sparsity_pattern<dealii::DoFHandler<3, 3>,
> dealii::DynamicSparsityPattern>(dealii::DoFHandler<3, 3> const&,
> dealii::DoFHandler<3, 3>
> const&, dealii::DynamicSparsityPattern&, dealii::ConstraintMatrix
> const&, bool)'
>
> Did I still forget to change any reference?

You probably forgot to add an explicit instantiation for your function.
Take a look at the section on "Instantiation of template
functions/classes" here:

https://dealii.org/developer/doxygen/deal.II/CodingConventions.html

Best
W.

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

Daniel Arndt

unread,
Apr 1, 2019, 7:48:41 PM4/1/19
to deal.II User Group
Alex,

Hey I just added my changes to a github branch ( https://github.com/gabpeters/dealii/tree/sparsity )
I changed the make_sparsity_pattern(dof_row,dor_col,sparsity) function and also changed the header in the
dof_tools.h file and the signature in the dof_tools_sparsity.inst.in file.
But still I get the following error, when I compile my code:

undefined reference to `void dealii::DoFTools::make_sparsity_pattern<dealii::DoFHandler<3, 3>,
                                          dealii::DynamicSparsityPattern>(dealii::DoFHandler<3, 3> const&, dealii::DoFHandler<3, 3>
                                     const&, dealii::DynamicSparsityPattern&, dealii::ConstraintMatrix const&, bool)'

Did I still forget to change any reference?

Looking at the GitHub branch it seems that you copied a lot of files from an older deal.II version (you probably modified) to a recent developer version. That is not going to work.
It's best if you make modifications on top off the master branch. Otherwise, it is also fine to make the modifications to an older release. We can certainly sort out how to convert such a patch to one to the recent master.

Best,
Daniel

gabriel...@koeln.de

unread,
Apr 2, 2019, 10:06:11 AM4/2/19
to deal.II User Group
Hey,
you are right, that github branch doesnt look very serious.
Now I cloned a more recent version, and added the Constraintsmatrix and changed the instantiations.
But somehow it still doesn't work. I still get the error "undefined reference..."
I hope I dont bother you too much with all these questions.

Best
Gabriel

Daniel Arndt

unread,
Apr 2, 2019, 9:03:22 PM4/2/19
to deal.II User Group
Gabriel,

Now I cloned a more recent version, and added the Constraintsmatrix and changed the instantiations.

That looks much better!
 
But somehow it still doesn't work. I still get the error "undefined reference..."

Admittedly, getting the instantiations right in this case might not be straightforward.
I created a pull request to your branch at https://github.com/gabpeters/dealii/pull/1 to fix some issues such that the branch at least compiles for me.
If you are satisfied with everything, please create a pull request to the master branch.
 
I hope I dont bother you too much with all these questions.

Not at all! We are happily helping people to contribute.

Best,
Daniel

Gabriel Peters

unread,
Apr 4, 2019, 8:19:59 AM4/4/19
to dea...@googlegroups.com
Hey Daniel,
thanks for the pull, with this instantiation everything compiles fine and I can use it.
But I think I did a mistake somewhere in the function. Using the definiion of the function from your pull request
I call
DoFTools::make_sparsity_pattern (dof_handler_velocity,dof_handler_pressure,dsp,
                    constraints_vel,false);
 
and afterwards I call
 
SparsityTools::distribute_sparsity_pattern (dsp, dof_handler_velocity.n_locally_owned_dofs_per_processor(),mpi_communicator,locally_relevant_dofs_vel);
 
When I run the program on more than 2 processors I get the following error during the distribute_sparsity... function:          
    The violated condition was:     local_lines.is_element(line_n)
    Additional information:
    The index set given to this constraints object indicates constraints for degree of freedom 16 should not be stored by this object, but a constraint is being added.
 
Do you have an idea how I can fix this?
 
(When I run the code on 1 or 2 processors, this error doesnt come up.
But I get divergence in the Gmres mehod,
which might imply that the boundaryconditions are not
applied in the correct way yet, but I first want to focus on the upper error.)
 
 
Thanks and best regards
 
Gabriel
 
 
Gesendet: Mittwoch, 03. April 2019 um 03:03 Uhr

Von: "Daniel Arndt" <daniel...@iwr.uni-heidelberg.de>
An: "deal.II User Group" <dea...@googlegroups.com>
Betreff: Re: [deal.II] Re: Applying boundary values in parll::distr:triang setting for two dof_handler Sparsematrux

Daniel Arndt

unread,
Apr 5, 2019, 8:00:36 AM4/5/19
to deal.II User Group
Gabriel,


But I think I did a mistake somewhere in the function. Using the definiion of the function from your pull request
I call
DoFTools::make_sparsity_pattern (dof_handler_velocity,dof_handler_pressure,dsp,
                    constraints_vel,false);
 
and afterwards I call
 
SparsityTools::distribute_sparsity_pattern (dsp, dof_handler_velocity.n_locally_owned_dofs_per_processor(),mpi_communicator,locally_relevant_dofs_vel);
 
When I run the program on more than 2 processors I get the following error during the distribute_sparsity... function:          
    The violated condition was:     local_lines.is_element(line_n)
    Additional information:
    The index set given to this constraints object indicates constraints for degree of freedom 16 should not be stored by this object, but a constraint is being added.
 
Do you have an idea how I can fix this?

You should first try create a unit test for this function, i.e. a small program that tests the function.
Just create a small (non-trivial) mesh where you can compute the sparsity pattern by hand and compare with the output of the fiunction.
I suspect that you need a second AffineConstraints object, such that you have one for the rows and one for the columns.

Best,
Daniel

Daniel Arndt

unread,
Apr 5, 2019, 9:55:03 AM4/5/19
to deal.II User Group
Gabriel,

to extend on my last post. Finally, I think that your approach with the two DoFHandler objects will give you some more problems.
What is likely happening here is that the AffineConstraints object here is used both for rows and columns although row dofs and column dofs are unrelated.
What you wanted here is to shift the pressure dofs such that they don't overlap with the velocoty dofs. However, you can't just do this using a renumbering since it is currently not allowed.
Even if you get this to work here without shifting, you will have the same problem when assembling your matrix and applying constraints.
I agree with David that the better approach here is to use a FESystem that accounts both for velocity and pressure and follow step-32.

Best,
Daniel

Gabriel Peters

unread,
Apr 5, 2019, 12:40:45 PM4/5/19
to dea...@googlegroups.com





Gabriel Peters
Endenicher Str. 310
53121 Bonn
00491525/5478185
Gabriel...@koeln.de

Am 05.04.19 um 15:55 schrieb Daniel Arndt

> Gabriel,
>
> to extend on my last post. Finally, I think that your approach with the two
> DoFHandler objects will give you some more problems.
> What is likely happening here is that the AffineConstraints object here is
> used both for rows and columns although row dofs and column dofs are
> unrelated.
> What you wanted here is to shift the pressure dofs such that they don't
> overlap with the velocoty dofs. However, you can't just do this using a
> renumbering since it is currently not allowed.

That would habe Been my question to your First post, how to apply 2 constraints in the „constraints.add... function, but your described Problem seems Even Harder to solve.

> Even if you get this to work here without shifting, you will have the same
> problem when assembling your matrix and applying constraints.
> I agree with David that the better approach here is to use a FESystem that
> accounts both for velocity and pressure and follow step-32.
>
> Best,
> Daniel
>
> --

This Sounds like but Problem.
But thanks a lot again. I will try next week to implement the code using Blockmatrices as prescribed. I‘ll let you know if it works or if further questions come up.

Best,
Gabriel

Reply all
Reply to author
Forward
0 new messages