read_cells Subroutine

private subroutine read_cells(filename, m)

Reads cell definitions from cells.dat.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: filename
type(mesh_t), intent(inout) :: m

Calls

proc~~read_cells~~CallsGraph proc~read_cells mod_mesh_io::read_cells proc~fatal_error mod_kinds::fatal_error proc~read_cells->proc~fatal_error

Called by

proc~~read_cells~~CalledByGraph proc~read_cells mod_mesh_io::read_cells proc~read_native_mesh mod_mesh_io::read_native_mesh proc~read_native_mesh->proc~read_cells program~lowmach_react_hex lowmach_react_hex program~lowmach_react_hex->proc~read_native_mesh

Source Code

   subroutine read_cells(filename, m)
      character(len=*), intent(in) :: filename
      type(mesh_t), intent(inout) :: m

      integer :: unit_id, ios, i, id
      integer :: nodes(8)
      real(rk) :: cx, cy, cz, volume

      open(newunit=unit_id, file=trim(filename), status='old', action='read', iostat=ios)
      if (ios /= 0) call fatal_error('mesh_io', 'could not open '//trim(filename))

      read(unit_id, *, iostat=ios) m%ncells
      if (ios /= 0 .or. m%ncells <= 0) call fatal_error('mesh_io', 'invalid cells header')

      allocate(m%cells(m%ncells))
      do i = 1, m%ncells
         read(unit_id, *, iostat=ios) id, nodes, cx, cy, cz, volume
         if (ios /= 0) call fatal_error('mesh_io', 'failed reading cell')
         if (id < 1 .or. id > m%ncells) call fatal_error('mesh_io', 'cell id out of range')
         if (volume <= 0.0_rk) call fatal_error('mesh_io', 'cell volume must be positive')
         m%cells(id)%id = id
         m%cells(id)%nodes = nodes
         m%cells(id)%center = [cx, cy, cz]
         m%cells(id)%volume = volume
      end do

      close(unit_id)
   end subroutine read_cells