This function \MaiuscolettoBS{must} be used when unstructured grid is used. It saves the connectivity of the unstructured mesh.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=I4P), | intent(in) | :: | NC | |||
integer(kind=I4P), | intent(in) | :: | connect(:) | |||
integer(kind=I4P), | intent(in) | :: | cell_type(1:NC) |
function VTK_CON(NC,connect,cell_type) result(E_IO)
!---------------------------------------------------------------------------------------------------------------------------------
!!This function \MaiuscolettoBS{must} be used when unstructured grid is used. It saves the connectivity of the unstructured
!!mesh.
!---------------------------------------------------------------------------------------------------------------------------------
!---------------------------------------------------------------------------------------------------------------------------------
implicit none
integer(I4P), intent(IN):: NC ! number of cells
integer(I4P), intent(IN):: connect(:) ! mesh connectivity
integer(I4P), intent(IN):: cell_type(1:NC) ! VTK cell type
integer(I4P):: E_IO ! Input/Output inquiring flag: $0$ if IO is done, $> 0$ if IO is not done
character(len=maxlen):: s_buffer ! buffer string
integer(I4P):: ncon ! dimension of connectivity vector
!!The VTK\_CON variables have the following meaning:
!!
!!\begin{description}
!! \item[{\color{RoyalBlue}NC}] indicates the number of all cells.
!! \item[{\color{RoyalBlue}connect}] contains the connectivity of the mesh. It is a vector.
!! \item[{\color{RoyalBlue}cell\_type}] contains the type of every cells. It is a vector of $[1:NC]$.
!! \item[{\color{RoyalBlue}E\_IO}] contains the inquiring integer flag for error handling.
!!\end{description}
!!
!!The vector \MaiuscolettoBS{connect} must follow the VTK legacy standard. It is passed as \MaiuscolettoBS{assumed-shape} array
!!because its dimensions is related to the mesh dimensions in a complex way. Its dimensions can be calculated by the following
!!equation:
!!
!!\begin{equation}
!!dc = NC + \sum\limits_{i = 1}^{NC} {nvertex_i }
!!\label{eq:connectivity dimensions}
!!\end{equation}
!!
!!\noindent where $dc$ is connectivity vector dimension and $nvertex_i$ is the number of vertices of $i^{th}$ cell. The VTK
!!legacy standard for the mesh connectivity is quite obscure at least at first sight. It is more simple analizing an example.
!!Suppose we have a mesh composed by 2 cells, one hexahedron (8 vertices) and one pyramid with square basis (5 vertices); suppose
!!that the basis of pyramid is constitute by a face of the hexahedron and so the two cells share 4 vertices. The equation
!!\ref{eq:connectivity dimensions} gives $dc=2+8+5=15$; the connectivity vector for this mesh can be:
!!
!!\begin{boxred}{Connectivity vector example for VTK legacy standard}
!!\begin{verbatim}
!!! first cell
!!connect(1) = 8 => number of vertices of 1° cell
!!connect(2) = 0 => identification flag of 1° vertex of 1° cell
!!connect(3) = 1 => identification flag of 2° vertex of 1° cell
!!connect(4) = 2 => identification flag of 3° vertex of 1° cell
!!connect(5) = 3 => identification flag of 4° vertex of 1° cell
!!connect(6) = 4 => identification flag of 5° vertex of 1° cell
!!connect(7) = 5 => identification flag of 6° vertex of 1° cell
!!connect(8) = 6 => identification flag of 7° vertex of 1° cell
!!connect(9) = 7 => identification flag of 8° vertex of 1° cell
!!! second cell
!!connect(10) = 5 => number of vertices of 2° cell
!!connect(11) = 0 => identification flag of 1° vertex of 2° cell
!!connect(12) = 1 => identification flag of 2° vertex of 2° cell
!!connect(13) = 2 => identification flag of 3° vertex of 2° cell
!!connect(14) = 3 => identification flag of 4° vertex of 2° cell
!!connect(15) = 8 => identification flag of 5° vertex of 2° cell
!!\end{verbatim}
!!\end{boxred}
!!
!!\noindent Note that the first 4 identification flags of pyramid vertices as the same of the first 4 identification flags of
!!the hexahedron because the two cells share this face. It is also important to note that the identification flags start
!!form $0$ value: this is impose to the VTK standard. The function VTK\_CON does not calculate the connectivity vector: it
!!writes the connectivity vector conforming the VTK standard, but does not calculate it. In the future release of \LIBVTKIO will
!!be included a function to calculate the connectivity vector.
!!
!!The vector variable \MaiuscolettoBS{tipo} must conform the VTK standard \footnote{See the file VTK-Standard at the Kitware
!!homepage.}. It contains the \emph{type} of each cells. For the above example this vector is:
!!
!!\begin{boxred}{Cell-Type vector example for VTK legacy standard}
!!\begin{verbatim}
!!tipo(1) = 12 => VTK hexahedron type of 1° cell
!!tipo(2) = 14 => VTK pyramid type of 2° cell
!!\end{verbatim}
!!\end{boxred}
!!
!!The following is an example of VTK\_CON calling:
!!
!!\begin{boxred}{VTK\_CON Calling}
!!\begin{verbatim}
!!...
!!integer(4), parameter:: NC=2
!!integer(4), parameter:: Nvertex1=8
!!integer(4), parameter:: Nvertex2=5
!!integer(4), parameter:: dc=NC+Nvertex1+Nvertex2
!!integer(4):: connect(1:dc)
!!integer(4):: cell_type(1:NC)
!!...
!!E_IO = VTK_CON(NC,connect,cell_type)
!!...
!!\end{verbatim}
!!\end{boxred}
!---------------------------------------------------------------------------------------------------------------------------------
!---------------------------------------------------------------------------------------------------------------------------------
ncon = size(connect,1)
select case(f_out)
case(f_out_ascii)
write(unit=Unit_VTK,fmt='(A,2'//FI4P//')',iostat=E_IO)'CELLS ',NC,ncon
write(unit=Unit_VTK,fmt=FI4P, iostat=E_IO)connect
write(unit=Unit_VTK,fmt='(A,'//FI4P//')', iostat=E_IO)'CELL_TYPES ',NC
write(unit=Unit_VTK,fmt=FI4P, iostat=E_IO)cell_type
case(f_out_binary)
write(s_buffer, fmt='(A,2'//FI4P//')',iostat=E_IO)'CELLS ',NC,ncon
write(unit=Unit_VTK, iostat=E_IO)trim(s_buffer)//end_rec
write(unit=Unit_VTK, iostat=E_IO)connect
write(unit=Unit_VTK, iostat=E_IO)end_rec
write(s_buffer, fmt='(A,'//FI4P//')', iostat=E_IO)'CELL_TYPES ',NC
write(unit=Unit_VTK, iostat=E_IO)trim(s_buffer)//end_rec
write(unit=Unit_VTK, iostat=E_IO)cell_type
write(unit=Unit_VTK, iostat=E_IO)end_rec
endselect
return
!---------------------------------------------------------------------------------------------------------------------------------
endfunction VTK_CON