Esempio n. 1
0
// NewVec creates a new MPI vector of local size n
func NewVec(local, global int64) (*Vec, error) {
	v := new(Vec)
	perr := C.VecCreateMPI(C.PETSC_COMM_WORLD, C.PetscInt(local), C.PetscInt(global), &v.v)
	if perr != 0 {
		return nil, errors.New("Error creating vector")
	}
	return v, nil
}
Esempio n. 2
0
// NewBlockedIS creates a blocked index set
//
// icopy == true means that the indices are copied, whereas icopy == false means that the PETSC_USE_POINTER is called.
// note that if icopy==false, you must *NOT* delete this pointer.
func NewBlockedIS(bs, nlocal int64, idx []int64) (*IS, error) {
	ret := new(IS)
	perr := C.ISCreateBlock(C.PETSC_COMM_WORLD, C.PetscInt(bs), C.PetscInt(nlocal), (*C.PetscInt)(unsafe.Pointer(&idx[0])), C.PETSC_COPY_VALUES, &ret.is)
	if perr != 0 {
		return nil, errors.New("Error creating blocked index set")
	}
	return ret, nil
}
Esempio n. 3
0
// NewStrideIS creates a new index set, based on strides
func NewStrideIS(nlocal, first, step int64) (*IS, error) {
	ret := new(IS)
	perr := C.ISCreateStride(C.PETSC_COMM_WORLD, C.PetscInt(nlocal), C.PetscInt(first), C.PetscInt(step), &ret.is)
	if perr != 0 {
		return nil, errors.New("Error creating strided index set")
	}
	return ret, nil
}
Esempio n. 4
0
// NewGhostVecBlocked creates a ghosted vector where the ghosts are specified by blocks
//
// bs is the blocksize and ghostndx are the
// indices of the ghosts. Note that local and global are the total number of elements (not
// blocsk), while nghostblocks and ghostndx are specified in terms of blocks.
//
func NewGhostVecBlocked(local, global, bs int64, ghostndx []int64) (*Vec, error) {
	v := new(Vec)
	ng := int64(len(ghostndx))
	perr := C.VecCreateGhostBlock(C.PETSC_COMM_WORLD, C.PetscInt(bs), C.PetscInt(local), C.PetscInt(global),
		C.PetscInt(ng), (*C.PetscInt)(unsafe.Pointer(&ghostndx[0])), &v.v)
	if perr != 0 {
		return nil, errors.New("Error creating vector")
	}
	return v, nil
}
Esempio n. 5
0
//SetValuesBlockedPtr sets values based on global indices. If add is true, then use ADD_VALUES, otherwise INSERT_VALUES.
//Must be followed by AssemblyBegin/End
func (v *Vec) SetValuesBlockedPtr(ix []int64, y uintptr, add bool) error {
	var iora C.InsertMode = C.INSERT_VALUES
	if add {
		iora = C.ADD_VALUES
	}
	perr := C.VecSetValuesBlocked(v.v, C.PetscInt(len(ix)), (*C.PetscInt)(unsafe.Pointer(&ix[0])), (*C.PetscScalar)(unsafe.Pointer(y)), iora)
	if perr != 0 {
		return errors.New("Error setting values")
	}
	return nil
}
Esempio n. 6
0
// NewVecBlocked creates a new blocked MPI vector
func NewVecBlocked(local, global, bs int64) (*Vec, error) {
	v := new(Vec)
	perr := C.VecCreate(C.PETSC_COMM_WORLD, &v.v)
	if perr != 0 {
		return nil, errors.New("Error creating vector")
	}
	perr = C.setTypeMPI(v.v)
	if perr != 0 {
		return nil, errors.New("Error creating vector -- setting type")
	}
	perr = C.VecSetBlockSize(v.v, C.PetscInt(bs))
	if perr != 0 {
		return nil, errors.New("Error creating vector -- setting bs")
	}
	perr = C.VecSetSizes(v.v, C.PetscInt(local), C.PetscInt(global))
	if perr != 0 {
		return nil, errors.New("Error creating vector -- setting bs")
	}

	return v, nil
}
Esempio n. 7
0
// NewGeneralIS creates a general index set
//
// icopy == true means that the indices are copied, whereas icopy == false means that the PETSC_USE_POINTER is called.
// note that if icopy==false, you must *NOT* delete this pointer.
func NewGeneralIS(nlocal int64, idx []int64, icopy bool) (*IS, error) {
	var mode C.PetscCopyMode
	switch icopy {
	case true:
		mode = C.PETSC_COPY_VALUES
	case false:
		mode = C.PETSC_USE_POINTER
	}

	ret := new(IS)
	perr := C.ISCreateGeneral(C.PETSC_COMM_WORLD, C.PetscInt(nlocal), (*C.PetscInt)(unsafe.Pointer(&idx[0])), mode, &ret.is)
	if perr != 0 {
		return nil, errors.New("Error creating general index set")
	}
	return ret, nil
}