How to get the anti-clockwise direction for all cells?

Asked by Nguyen Van Dang

Hello,
When I accessed the mesh data by below code, sometimes I got the cell with anti-clockwise direction but sometimes I did not. In fact, I need all cells with anti-clockwise direction. Is there any way to get them?
Any helps are highly appropriated!
Nguyen Van Dang

for (CellIterator c(mesh); !c.end(); ++c)
{
cout << "cell index = " << c->index() << endl;
for (VertexIterator v(*c); !v.end(); ++v)
{
cout << "vertex index = " << v->index() << endl;
cout << "vertex coordinates = " << v->point() << endl;
}
}

Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Anders Logg
Solved:
Last query:
Last reply:
Revision history for this message
Garth Wells (garth-wells) said :
#1

Try calling

    mesh.order()

before iterating over the mesh.

Revision history for this message
Nguyen Van Dang (dang-1032170) said :
#2

Hello,
Thank you for your answer. I've already tried it but nothing changed. Can you tell me if there is another way to solve it?
Thanks in advance,
Nguyen Van Dang.

Revision history for this message
Kristian B. Ølgaard (k.b.oelgaard) said :
#3

DOLFIN uses the UFC ordering convention (check the UFC manual in ufc/doc/manual).
The vertices of a cell is ordered in based on their global number e.g., triangle0 = [v0, v4, v6], not triangle = [v0, v6, v4]
thus the orientation can be both clock-wise and counter clock-wise in a mesh.

Revision history for this message
Nguyen Van Dang (dang-1032170) said :
#4

Would you like to tell me if there is any way to distinguish between them?
Thanks

On Wed, Sep 14, 2011 at 8:30 PM, Kristian B. Ølgaard <
<email address hidden>> wrote:

> Your question #171137 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/171137
>
> Status: Open => Answered
>
> Kristian B. Ølgaard proposed the following answer:
> DOLFIN uses the UFC ordering convention (check the UFC manual in
> ufc/doc/manual).
> The vertices of a cell is ordered in based on their global number e.g.,
> triangle0 = [v0, v4, v6], not triangle = [v0, v6, v4]
> thus the orientation can be both clock-wise and counter clock-wise in a
> mesh.
>
> --
> If this answers your question, please go to the following page to let us
> know that it is solved:
> https://answers.launchpad.net/dolfin/+question/171137/+confirm?answer_id=2
>
> If you still need help, you can reply to this email or go to the
> following page to enter your feedback:
> https://answers.launchpad.net/dolfin/+question/171137
>
> You received this question notification because you asked the question.
>

--
Nguyen Van Dang

Home Tel: +84 7 92 21 36 28
Another email: <email address hidden>

Revision history for this message
Kristian B. Ølgaard (k.b.oelgaard) said :
#5

I don't think DOLFIN provides functionality to do this.

Revision history for this message
Best Anders Logg (logg) said :
#6

On Wed, Sep 14, 2011 at 07:05:57PM -0000, Kristian B. Ølgaard wrote:
> Question #171137 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/171137
>
> Status: Open => Answered
>
> Kristian B. Ølgaard proposed the following answer:
> I don't think DOLFIN provides functionality to do this.

You can call the function cell.orientation() to get the orientation of
a cell (+1 or -1).

--
Anders

Revision history for this message
Kristian B. Ølgaard (k.b.oelgaard) said :
#7

On 14 September 2011 22:25, Anders Logg
<email address hidden> wrote:
> Question #171137 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/171137
>
> Anders Logg proposed the following answer:
> On Wed, Sep 14, 2011 at 07:05:57PM -0000, Kristian B. Ølgaard wrote:
>> Question #171137 on DOLFIN changed:
>> https://answers.launchpad.net/dolfin/+question/171137
>>
>>     Status: Open => Answered
>>
>> Kristian B. Ølgaard proposed the following answer:
>> I don't think DOLFIN provides functionality to do this.
>
> You can call the function cell.orientation() to get the orientation of
> a cell (+1 or -1).

Cell.h says 0 or 1 (+1 or -1 sounds better to me though).
Also the return value of Cell::orientation is double while e.g.,
TriangleCell::orientation returns uint.

Kristian

> --
> Anders
>
> --
> You received this question notification because you are a direct
> subscriber of the question.
>

Revision history for this message
Anders Logg (logg) said :
#8

On Wed, Sep 14, 2011 at 09:01:00PM -0000, Kristian B. Ølgaard wrote:
> Question #171137 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/171137
>
> Kristian B. Ølgaard proposed the following answer:
> On 14 September 2011 22:25, Anders Logg
> <email address hidden> wrote:
> > Question #171137 on DOLFIN changed:
> > https://answers.launchpad.net/dolfin/+question/171137
> >
> > Anders Logg proposed the following answer:
> > On Wed, Sep 14, 2011 at 07:05:57PM -0000, Kristian B. Ølgaard wrote:
> >> Question #171137 on DOLFIN changed:
> >> https://answers.launchpad.net/dolfin/+question/171137
> >>
> >>     Status: Open => Answered
> >>
> >> Kristian B. Ølgaard proposed the following answer:
> >> I don't think DOLFIN provides functionality to do this.
> >
> > You can call the function cell.orientation() to get the orientation of
> > a cell (+1 or -1).
>
> Cell.h says 0 or 1 (+1 or -1 sounds better to me though).

Agree.

> Also the return value of Cell::orientation is double while e.g.,
> TriangleCell::orientation returns uint.

I don't know why it returns a double. Does anyone know?

Should we change to int and +/- 1?

--
Anders

Revision history for this message
Nguyen Van Dang (dang-1032170) said :
#9

Thanks Anders Logg, that solved my question.

Revision history for this message
Anders Logg (logg) said :
#10

On Wed, Sep 14, 2011 at 09:45:41PM -0000, Anders Logg wrote:
> Question #171137 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/171137
>
> Anders Logg proposed the following answer:
> On Wed, Sep 14, 2011 at 09:01:00PM -0000, Kristian B. Ølgaard wrote:
> > Question #171137 on DOLFIN changed:
> > https://answers.launchpad.net/dolfin/+question/171137
> >
> > Kristian B. Ølgaard proposed the following answer:
> > On 14 September 2011 22:25, Anders Logg
> > <email address hidden> wrote:
> > > Question #171137 on DOLFIN changed:
> > > https://answers.launchpad.net/dolfin/+question/171137
> > >
> > > Anders Logg proposed the following answer:
> > > On Wed, Sep 14, 2011 at 07:05:57PM -0000, Kristian B. Ølgaard wrote:
> > >> Question #171137 on DOLFIN changed:
> > >> https://answers.launchpad.net/dolfin/+question/171137
> > >>
> > >>     Status: Open => Answered
> > >>
> > >> Kristian B. Ølgaard proposed the following answer:
> > >> I don't think DOLFIN provides functionality to do this.
> > >
> > > You can call the function cell.orientation() to get the orientation of
> > > a cell (+1 or -1).
> >
> > Cell.h says 0 or 1 (+1 or -1 sounds better to me though).
>
> Agree.
>
> > Also the return value of Cell::orientation is double while e.g.,
> > TriangleCell::orientation returns uint.
>
> I don't know why it returns a double. Does anyone know?
>
> Should we change to int and +/- 1?

I have changed the orientation from double to uint but kept the values
0 and 1 (as opposed to +1, -1) not to break programs depending on it.

--
Anders