#NEWLINE# @ contextmanager #NEWLINE# def vecscatter( self , readonly = True ) : #NEWLINE# #INDENT# 'A context manager scattering the arrays of all components of this\n        :class:`MixedDat` into a contiguous :class:`PETSc.Vec` and reverse\n        scattering to the original arrays when exiting the context.\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.\n\n        .. note::\n\n           The :class:`~PETSc.Vec` obtained from this context is in\n           the correct order to be left multiplied by a compatible\n           :class:`MixedMat`.  In parallel it is *not* just a\n           concatenation of the underlying :class:`Dat`\\s.' #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 . vec_ro ) if readonly else ( lambda d : d . vec ) ) #NEWLINE# if ( not hasattr ( self , '_vec' ) ) : #NEWLINE# #INDENT# self . _vec = self . dataset . layout_vec . duplicate ( ) #NEWLINE# #UNINDENT# scatters = self . dataset . vecscatters #NEWLINE# for ( d , vscat ) in zip ( vscat , scatters ) : #NEWLINE# #INDENT# with acc ( d ) as v : #NEWLINE# #INDENT# vscat . scatterBegin ( v , self . _vec , addv = PETSc . InsertMode . INSERT_VALUES ) #NEWLINE# vscat . scatterEnd ( v , self . _vec , addv = PETSc . InsertMode . INSERT_VALUES ) #NEWLINE# #UNINDENT# #UNINDENT# ( yield self . _vec ) #NEWLINE# if ( not readonly ) : #NEWLINE# #INDENT# for ( d , vscat ) in zip ( self , scatters ) : #NEWLINE# #INDENT# with acc ( d ) as v : #NEWLINE# #INDENT# vscat . scatterBegin ( self . _vec , v , addv = PETSc . InsertMode . INSERT_VALUES , mode = PETSc . ScatterMode . REVERSE ) #NEWLINE# vscat . scatterEnd ( self . _vec , v , addv = PETSc . InsertMode . INSERT_VALUES , mode = PETSc . ScatterMode . REVERSE ) #NEWLINE# #UNINDENT# #UNINDENT# self . needs_halo_update = True