#NEWLINE# @ contextmanager #NEWLINE# def vec_context( self , readonly = True ) : #NEWLINE# #INDENT# 'A context manager for a :class:`PETSc.Vec` from a :class:`Dat`.\n\n        :param readonly: Access the data read-only (use :meth:`Dat.data_ro`)\n                         or read-write (use :meth:`Dat.data`). Read-write\n                         access requires a halo update.' #NEWLINE# assert ( self . dtype == PETSc . ScalarType ) , ( "Can't create Vec with type %s, must be %s" % ( self . dtype , PETSc . ScalarType ) ) #NEWLINE# acc = ( ( lambda d : d . data_ro ) if readonly else ( lambda d : d . data ) ) #NEWLINE# self . _force_evaluation ( read = True , write = ( not readonly ) ) #NEWLINE# if ( not hasattr ( self , '_vec' ) ) : #NEWLINE# #INDENT# size = self . dataset . layout_vec . getSizes ( ) #NEWLINE# self . _vec = PETSc . Vec ( ) . createWithArray ( acc ( self ) , size = size , bsize = self . cdim ) #NEWLINE# #UNINDENT# self . _vec . stateIncrease ( ) #NEWLINE# ( yield self . _vec ) #NEWLINE# if ( not readonly ) : #NEWLINE# #INDENT# self . needs_halo_update = True