File: test_vec.py

package info (click to toggle)
ngspetsc 0.1.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 27,120 kB
  • sloc: python: 3,391; makefile: 42; sh: 29
file content (63 lines) | stat: -rw-r--r-- 1,796 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
'''
This module test the vec class
'''
import pytest
pytest.importorskip("ngsolve")

from ngsolve import Mesh, H1, BilinearForm, LinearForm, dx
from netgen.geom2d import unit_square
import netgen.meshing as ngm

from mpi4py.MPI import COMM_WORLD

from ngsPETSc import Matrix, VectorMapping

def test_vec_map_ngs_petsc():
    '''
    Testing the mapping from NGSolve Vec to PETSc Vec
    '''
    if COMM_WORLD.rank == 0:
        mesh = Mesh(unit_square.GenerateMesh(maxh=0.1).Distribute(COMM_WORLD))
    else:
        mesh = Mesh(ngm.Mesh.Receive(COMM_WORLD))
    fes = H1(mesh, order=1, dirichlet="left|right|top|bottom")
    u,v = fes.TnT()
    M = BilinearForm(u*v*dx).Assemble().mat
    ngsVec = M.CreateColVector()
    Map = VectorMapping(fes)
    Map.petscVec(ngsVec)

def test_vec_map_petsc_ngs():
    '''
    Testing the mapping from PETSc Vec to NGSolve Vec
    '''
    if COMM_WORLD.rank == 0:
        mesh = Mesh(unit_square.GenerateMesh(maxh=0.1).Distribute(COMM_WORLD))
    else:
        mesh = Mesh(ngm.Mesh.Receive(COMM_WORLD))
    fes = H1(mesh, order=1, dirichlet="left|right|top|bottom")
    u,v = fes.TnT()
    m = BilinearForm(u*v*dx).Assemble()
    M = Matrix(m.mat, fes)
    petscVec = M.mat.createVecLeft()
    Map = VectorMapping(fes)
    Map.ngsVec(petscVec)

def test_vec_map():
    '''
    Testing the assembling
    '''
    if COMM_WORLD.rank == 0:
        mesh = Mesh(unit_square.GenerateMesh(maxh=0.1).Distribute(COMM_WORLD))
    else:
        mesh = Mesh(ngm.Mesh.Receive(COMM_WORLD))
    fes = H1(mesh, order=1, dirichlet="left|right|top|bottom")
    _,v = fes.TnT()
    L = LinearForm(v*dx).Assemble().vec
    Map = VectorMapping(fes)
    _ = Map.petscVec(L)

if __name__ == '__main__':
    test_vec_map_ngs_petsc()
    test_vec_map_petsc_ngs()
    test_vec_map()