boundary matrix

43 views
Skip to first unread message

Nikki Holtzer

unread,
Mar 6, 2021, 11:30:43 PM3/6/21
to deal.II User Group
Hello everyone!

For a 1d problem, I would like to implement a "boundary matrix" for an absorbing boundary condition such as the one presented in Step 24 for only the left boundary. Is it necessary to have the 'if' statement be a conditional over faces like in Step 24 even though it is a 1d problem or is something like

if (cell->at_boundary() && (face->boundary_id() == 1)) {
}
acceptable?

Thank you

Wolfgang Bangerth

unread,
Mar 7, 2021, 1:49:12 PM3/7/21
to dea...@googlegroups.com
The statement is ok I believe (have you tried?), the question is what you want
to do after that.

Best
W.

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

Nikki Holtzer

unread,
Mar 7, 2021, 3:00:12 PM3/7/21
to deal.II User Group
Yes, I have tried it. The problem I am having is with the 'face->boundary_id() == 1' piece. I get an error which states that :
'face' was not declared in this scope. 

The only other place that 'face' appears in my code is where I set the boundary ids like the following:

triangulation.begin_active->face()->set_boundary_id()

Is there an easier way to access that boundary in the second half of that if statement above other than

(face->boundary_id() == 1)

or is this the correct approach and it needs to be amended somehow?

peter rum

unread,
Mar 7, 2021, 3:07:09 PM3/7/21
to deal.II User Group
I am not completely sure what you want to accomplish, but I think the following code should work for your purpose:
```
for(const auto & cell : triangulation.active_cell_iterators())
  for(const auto & face : cell-> face_iterators())
    if(face->at_boundary() && face->boundary_id() == 1)
      // do something useful
```
(plus minus a few typos)

Hope that helps,
Peter

Wolfgang Bangerth

unread,
Mar 7, 2021, 3:10:22 PM3/7/21
to dea...@googlegroups.com
On 3/7/21 9:00 PM, Nikki Holtzer wrote:
> Yes, I have tried it. The problem I am having is with the 'face->boundary_id()
> == 1' piece. I get an error which states that :
> 'face' was not declared in this scope.
>
> The only other place that 'face' appears in my code is where I set the
> boundary ids like the following:
>
> triangulation.begin_active->face()->set_boundary_id()
>
> Is there an easier way to access that boundary in the second half of that if
> statement above other than
>
> (face->boundary_id() == 1)

So let's start with the root cause, the error you get that
'face' was not declared in this scope
Did you declare a local variable called 'face'? If not, you can clearly not
use it. But if you look at the place where you probably copied that code from,
you will see how you can declare such a variable -- you will just have to copy
the declaration as well.

This falls in a category of problems I see quite a lot in my students, so
you're in good company: You get an error, and you try to work around it ("Is
there an easier way...") without really understanding what the root cause is.
That's a bit like saying

I have two variables x and y which I believe to be equal to 2 and 3, but if
I write x+y I get 6. Is there a different way for me to add x to y so that
the result is 5?

That's not a useful approach. Instead of just walking away from something that
superficially doesn't work as expected, spend the time to read the details of
error messages and to understand *why* it is not working. It will make you a
better programmer if you make that a habit!

Best
Wolfgang

Nikki Holtzer

unread,
Mar 7, 2021, 4:16:01 PM3/7/21
to deal.II User Group
Thank you for your input! That was my first attempt at tackling this. However, I run into problems with the line 

for(const auto & face : cell-> face_iterators()).

No matter what member function I choose off of the DoFCellAccessor class template reference, I get some version of the following: 

class dealii::DoFCellAccessor<dealii::DoFHandler<1, 1>, false>’ has no member named ‘face_iterators’; did you mean ‘face_iterator’?

If I then try the correction: I obtain the following:

invalid use of ‘using face_iterator'= class dealii::TriaIterator<dealii::DoFAccessor<0, dealii::DoFHandler<1, 1>, false> >’

Like I said, this seems to happen with all the member functions I choose for DoFCellAccessor. 

Wolfgang Bangerth

unread,
Mar 9, 2021, 4:16:36 AM3/9/21
to dea...@googlegroups.com
On 3/7/21 10:16 PM, Nikki Holtzer wrote:
> Thank you for your input! That was my first attempt at tackling this. However,
> I run into problems with the line
>
> for(const auto & face : cell-> face_iterators()).
>
> No matter what member function I choose off of the DoFCellAccessor class
> template reference, I get some version of the following:
>
> class dealii::DoFCellAccessor<dealii::DoFHandler<1, 1>, false>’ has no member
> named ‘face_iterators’; did you mean ‘face_iterator’?

I'm pretty sure that function should exist. What deal.II version are you using?

But, if that doesn't work, you can always do this instead
```
for(const auto & cell : triangulation.active_cell_iterators())
for (unsigned int f=0; f<GeometryInfo<dim>::faces_per_cell; ++f)
{
const auto face = cell->face(f);
if(face->at_boundary() && face->boundary_id() == 1)
// do something useful
}
```

Nikki Holtzer

unread,
Mar 10, 2021, 2:29:49 PM3/10/21
to deal.II User Group

I am using dealii version 9.1.1. The alternative you suggested has resolved my issue.

Thank you,
Nikki 
Reply all
Reply to author
Forward
0 new messages