FreeFem / FreeFem-sources

FreeFEM source code
https://freefem.org/
Other
770 stars 191 forks source link

Th.bordermeasure documented but raise error. #66

Closed Joalland closed 5 years ago

Joalland commented 5 years ago

Freefem++ v3.47 on linux. When trying to run the following script: FreeFem-doc/docs/documentation/MeshGeneration.md#mesh-connectivity-and-data

Mesh Connectivity and data

The following example explains methods to obtain mesh information.

// Mesh
mesh Th = square(2, 2);

cout << "// Get data of the mesh" << endl;
{
    int NbTriangles = Th.nt;
    real MeshArea = Th.measure;
    real BorderLenght = Th.bordermeasure;

    cout << "Number of triangle(s) = " << NbTriangles << endl;
    cout << "Mesh area = " << MeshArea << endl;
    cout << "Border length = " << BorderLenght << endl;

    // Th(i) return the vextex i of Th
    // Th[k] return the triangle k of Th
    // Th[k][i] return the vertex i of the triangle k of Th
    for (int i = 0; i < NbTriangles; i++)
        for (int j = 0; j < 3; j++)
            cout << i << " " << j << " - Th[i][j] = " << Th[i][j]
                 << ", x = " << Th[i][j].x
                 << ", y= " << Th[i][j].y
                 << ", label=" << Th[i][j].label << endl;
}

cout << "// Hack to get vertex coordinates" << endl;
{
    fespace femp1(Th, P1);
    femp1 Thx=x,Thy=y;

    int NbVertices = Th.nv;
    cout << "Number of vertices = " << NbVertices << endl;

    for (int i = 0; i < NbVertices; i++)
        cout << "Th(" << i << ") : " << Th(i).x << " " << Th(i).y << " " << Th(i).label
             << endl << "\told method: " << Thx[][i] << " " << Thy[][i] << endl;
}

cout << "// Method to find information of point (0.55,0.6)" << endl;
{
    int TNumber = Th(0.55, 0.6).nuTriangle; //the triangle number
    int RLabel = Th(0.55, 0.6).region; //the region label

    cout << "Triangle number in point (0.55, 0.6): " << TNumber << endl;
    cout << "Region label in point (0.55, 0.6): " << RLabel << endl;
}

cout << "// Information of triangle" << endl;
{
    int TNumber = Th(0.55, 0.6).nuTriangle;
    real TArea = Th[TNumber].area; //triangle area
    real TRegion = Th[TNumber].region; //triangle region
    real TLabel = Th[TNumber].label; //triangle label, same as region for triangles

    cout << "Area of triangle " << TNumber << ": " << TArea << endl;
    cout << "Region of triangle " << TNumber << ": " << TRegion << endl;
    cout << "Label of triangle " << TNumber << ": " << TLabel << endl;
}

cout << "// Hack to get a triangle containing point x, y or region number (old method)" << endl;
{
    fespace femp0(Th, P0);
    femp0 TNumbers; //a P0 function to get triangle numbering
    for (int i = 0; i < Th.nt; i++)
        TNumbers[][i] = i;
    femp0 RNumbers = region; //a P0 function to get the region number

    int TNumber = TNumbers(0.55, 0.6); // Number of the triangle containing (0.55, 0,6)
    int RNumber = RNumbers(0.55, 0.6); // Number of the region containing (0.55, 0,6)

    cout << "Point (0.55,0,6) :" << endl;
    cout << "\tTriangle number = " << TNumber << endl;
    cout << "\tRegion number = " << RNumber << endl;
}

cout << "// New method to get boundary information and mesh adjacent" << endl;
{
    int k = 0;
    int l=1;
    int e=1;

    // Number of boundary elements
    int NbBoundaryElements = Th.nbe;
    cout << "Number of boundary element = " << NbBoundaryElements << endl;
    // Boundary element k in {0, ..., Th.nbe}
    int BoundaryElement = Th.be(k);
    cout << "Boundary element " << k << " = " << BoundaryElement << endl;
    // Vertice l in {0, 1} of boundary element k
    int Vertex = Th.be(k)[l];
    cout << "Vertex " << l << " of boundary element " << k << " = " << Vertex << endl;
    // Triangle containg the boundary element k
    int Triangle = Th.be(k).Element;
    cout << "Triangle containing the boundary element " << k << " = " << Triangle << endl;
    // Triangle egde nubmer containing the boundary element k
    int Edge = Th.be(k).whoinElement;
    cout << "Triangle edge number containing the boundary element " << k << " = " << Edge << endl;
    // Adjacent triangle of the triangle k by edge e
    int Adjacent = Th[k].adj(e); //The value of e is changed to the corresponding edge in the adjacent triangle
    cout << "Adjacent triangle of the triangle " << k << " by edge " << e << " = " << Adjacent << endl;
    cout << "\tCorresponding edge = " << e << endl;
    // If there is no adjacent triangle by edge e, the same triangle is returned
    //Th[k] == Th[k].adj(e)
    // Else a different triangle is returned
    //Th[k] != Th[k].adj(e)
}

cout << "// Print mesh connectivity " << endl;
{
    int NbTriangles = Th.nt;
    for (int k = 0; k < NbTriangles; k++)
        cout << k << " : " << int(Th[k][0]) << " " << int(Th[k][1])
             << " " << int(Th[k][2])
             << ", label " << Th[k].label << endl;

    for (int k = 0; k < NbTriangles; k++)
        for (int e = 0, ee; e < 3; e++)
            //set ee to e, and ee is change by method adj,
            cout << k << " " << e << " <=> " << int(Th[k].adj((ee=e))) << " " << ee
                 << ", adj: " << (Th[k].adj((ee=e)) != Th[k]) << endl;

    int NbBoundaryElements = Th.nbe;
    for (int k = 0; k < NbBoundaryElements; k++)
        cout << k << " : " << Th.be(k)[0] << " " << Th.be(k)[1]
             << " , label " << Th.be(k).label
             << ", triangle " << int(Th.be(k).Element)
             << " " << Th.be(k).whoinElement << endl;

    real[int] bb(4);
    boundingbox(Th, bb);
    // bb[0] = xmin, bb[1] = xmax, bb[2] = ymin, bb[3] =ymax
    cout << "boundingbox:" << endl;
    cout << "xmin = " << bb[0]
         << ", xmax = " << bb[1]
         << ", ymin = " << bb[2]
         << ", ymax = " << bb[3] << endl;
}

`-- FreeFem++ v 3.470000 (date 2017-12-20) Load: lg_fem lg_mesh lg_mesh3 eigenvalue 1 : // Mesh 2 : mesh Th = square(2, 2); 3 : 4 : cout << "// Get data of the mesh" << endl; 5 : { 6 : int NbTriangles = Th.nt; 7 : real MeshArea = Th.measure; 8 : real BorderLenght = Th.bordermeasure No operator .bordermeasure for type

I've got the following error:

Error line number 8, in file Lap1D.edp, before token bordermeasure current line = 8 Compile error : line number :8, bordermeasure error Compile error : line number :8, bordermeasure code = 1 mpirank: 0

Has .bordermeasure been replaced ? Is this script still working ?

sgarnotel commented 5 years ago

I think your version of FreeFem++ is too old. It works for me with FreeFem++-v4.0

What is your linux distribution ? If you are on Ubuntu, you can download this DEB package for the version 3.62, a version 4.0 DEB package will be available soon

Joalland commented 5 years ago

I use Linux mint 19.1 based on ubuntu 18.04 and freefem++ is packaged with the version 3.47. I've just compiled the 4.0 from source and all is working fine (including this script). Sorry for this inconvenient bug report.

Thanks for your answer.