solve_flow.py 1.37 KB
Newer Older
sfritschi's avatar
sfritschi committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from mpi4py import MPI

comm = MPI.COMM_WORLD
rank = comm.Get_rank()
root = 0

import sys
sys.path.append('../')

from netflow import *

def main():
    
    if (len(sys.argv) != 2):
        if (rank == root):
            print("Usage: python3 solve_flow.py <path-to-network>")
        comm.Abort(1)
    
    net = None
    
    # Only initialize on root rank
    if (rank == root):
        netPath = sys.argv[1]
        try:
sfritschi's avatar
sfritschi committed
25
            net = netflow.load_network_from(netPath)
sfritschi's avatar
sfritschi committed
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
        except Exception as e:
            print("Error: {}".format(e))
            comm.Abort(1)
        
        print("Pores: %d" % (len(net.pores)))
        
    start = MPI.Wtime()
    pA, QA = netflow.solve_flow_periodic(network=net, \
                solver=netflow.Solver.PETSC, mu=1e-3, c=1, P2L=-1e3)
    end = MPI.Wtime()
    
    if rank == root:
        print("PETSc time: %e s" % (end - start))
    
    start = MPI.Wtime()
    pB, QB = netflow.solve_flow_periodic(network=net, \
                solver=netflow.Solver.CG, mu=1e-3, c=1, P2L=-1e3)
    end = MPI.Wtime()
    
    if rank == root:
        print("Other time: %e s" % (end - start))
        
        diff = 0.
        count = 0
        for pore in net.pores:
            if pore in pA:
                count += 1
                diff += (pA[pore] - pB[pore])**2
        print("MSE: %e" % (diff / count))
        
if __name__ == '__main__':
    main()