Adjacency, connectivity and mass flux through internal faces

Questions and remarks about code_saturne usage
Forum rules
Please read the forum usage recommendations before posting.
Post Reply
jtache
Posts: 25
Joined: Thu Apr 19, 2012 4:01 pm

Adjacency, connectivity and mass flux through internal faces

Post by jtache »

Hello,

I'm trying to write a cs_user_extra_operations routine that is basically supposed to fill a matrix M[ncel, ncel] with values depending on local mass fluxes through faces of each cell.

To do that for each cell, I need to make :
  • a loop on all cells (rows of the matrix M)
    • that contains a loop on all cells (colums of the matrix)
      • that contains a loop on internal and boundary faces
        1. test with ifacel(1, ifac) and ifacel(2, ifac) to identify which cells share the face ifac
        2. get mass flux through this face with

          Code: Select all

          call field_get_key_int(ivarfl(iu), kimasf, iflmas)
          call field_get_key_int(ivarfl(iu), kbmasf, iflmab)
        3. compute desired value and store it in the matrix M :
Unfortunately, this algorithm is far too expensive because of the loops, even with a small mesh, this is why I would like to get help on the following items:
  1. cell->cells adjacency : I read in the forum that it may be possible to access directly to the neighborhood of a given cell with a cs_mesh_adjancency _t structure. How can I use this in my subroutine in order to drop one of my loops on mesh cells?
  2. cell->faces connectivity : if I'd get this connectivity, I could get rif off my loop on faces. I read in the forum that
    the cells->faces array (reverse of faces->cells) is built temporarily for some stages, but only kept permanently for Lagrangian calculations
    .
    I tried to use the lagrangian module but I think it works only for turbulent calculations : am I right?
    When I tried to use some variables of the lagrangian module in my subroutine (use lagran),

    Code: Select all

    WRITE(nfecra, *) "lndnod = ", lndnod
    I got the following message at compilation stage :

    Code: Select all

    Error: Symbol ‘lndnod’ at (1) has no IMPLICIT type
    It seems that I made a mistake since I can't access to lndnod or icocel[lndnod].
    Is there any other array I could access to get the ids of the faces of each cell? Maybe with cs_selector_get_i_face_list((icell, &n_faces, face_list);)?
  3. orientation of mass flux through an internal face : I used ifacel(*,ifac) to get ids of the 2 cells that share an internal ifac : how is oriented the mass flux kimasf (positive or negative) ? is it positive from ifacel(1,ifac)to ifacel(2,ifac) and negative in the other way?
    [\list]

    Thanks a lot for your help!

    Best regards,
    Jeremie
Yvan Fournier
Posts: 4070
Joined: Mon Feb 20, 2012 3:25 pm

Re: Adjacency, connectivity and mass flux through internal faces

Post by Yvan Fournier »

Hello,

The Fortran access to face-vertices connectivity has been removed if I remember correctly, so lndnod exists only in older versions. In newer versions, you must use the C functions and structures.

In the same way, cs_glob_mesh_adjancency is only available in C, and gives you cell->cell connectivity, not cell->faces. And I do not recommend forcing Lagrangian jut to get a structure.

It would seem you could do something simpler:
  • initialize you matrix to zero
  • loop in faces: for each face, increment a contribution from this face to matching i, j terms in matrix
In practice, if the number of cells is anything esls than extremely small, you need a sparse matrix structure, so could do a first pass to count faces per cell (the number of nonzeroes), build an index (CSR structure) from that, and assign column numbers and do assembly in the second pass.

In parallel, accounting for ghost cells might work (I need to think about it), but I am not sure.

In C, you could use the cs_matrix_assembler API which is perfectly adapted to what you need (for a sparse matrix). Or you could diretly do it using PETSc. In, Fortran, I have no "direct" solution.

Regarding the face orientation aspects, yes it follows the "natural" (face-normal based) face orientation, so should be positive from ifacel(1,ifac)to ifacel(2,ifac).

You may want to check the code in cs_balance_by_zone.c for examples of using balances.

Best regards,

Yvan
jtache
Posts: 25
Joined: Thu Apr 19, 2012 4:01 pm

Re: Adjacency, connectivity and mass flux through internal faces

Post by jtache »

Thank you Yvan for your feedback, I'm going to process your advises.

Best regards,
Jeremie
Post Reply