[petsc-users] petsc4py - Convert c example code to Python

Smith, Barry F. bsmith at mcs.anl.gov
Mon Apr 1 09:59:01 CDT 2019


   

> On Apr 1, 2019, at 9:45 AM, Nicola Creati via petsc-users <petsc-users at mcs.anl.gov> wrote:
> 
> Thanks Matt, it solves the problem. The Jacobian matrix is now filled but checking between the C and Python code with MatView there are some differences.
> This is my Jacobian matrix:

   Hmm, just doing a quick eye-ball scan it looks like the matrices have the same numerical values; it is just that the C version has also inserted some additional 0 values at other locations. The solution to both linear systems should be the same but note that the iterative method used to solve the system may converge differently (because some of the preconditions in PETSc construct the preconditioner based on the "non-zero structure" of the matrix and in this construction the 0 locations can affect the preconditioner) hence the partial solution after running the solver may be slightly different between the two solvers. If you run with a direct solver -pc_type lu you should get two answers that are very close to each other.

    Barry

> 
> Mat Object: 1 MPI processes
>   type: seqaij
> row 0: (0, 1.)
> row 1: (1, 1.)
> row 2: (2, 1.)
> row 3: (3, 1.)
> row 4: (4, 1.)
> row 5: (5, 1.)
> row 6: (6, 1.)
> row 7: (7, 1.)
> row 8: (8, 1.)
> row 9: (1, 49.)  (8, 49.)  (9, -196.)  (10, 49.)  (17, 49.)
> row 10: (2, 49.)  (9, 49.)  (10, -196.)  (11, 49.)  (18, 49.)
> row 11: (3, 49.)  (10, 49.)  (11, -196.)  (12, 49.)  (19, 49.)
> row 12: (4, 49.)  (11, 49.)  (12, -196.)  (13, 49.)  (20, 49.)
> row 13: (5, 49.)  (12, 49.)  (13, -196.)  (14, 49.)  (21, 49.)
> row 14: (6, 49.)  (13, 49.)  (14, -196.)  (15, 49.)  (22, 49.)
> row 15: (15, 1.)
> row 16: (16, 1.)
> row 17: (9, 49.)  (16, 49.)  (17, -196.)  (18, 49.)  (25, 49.)
> row 18: (10, 49.)  (17, 49.)  (18, -196.)  (19, 49.)  (26, 49.)
> row 19: (11, 49.)  (18, 49.)  (19, -196.)  (20, 49.)  (27, 49.)
> row 20: (12, 49.)  (19, 49.)  (20, -196.)  (21, 49.)  (28, 49.)
> row 21: (13, 49.)  (20, 49.)  (21, -196.)  (22, 49.)  (29, 49.)
> row 22: (14, 49.)  (21, 49.)  (22, -196.)  (23, 49.)  (30, 49.)
> row 23: (23, 1.)
> row 24: (24, 1.)
> row 25: (17, 49.)  (24, 49.)  (25, -196.)  (26, 49.)  (33, 49.)
> row 26: (18, 49.)  (25, 49.)  (26, -196.)  (27, 49.)  (34, 49.)
> row 27: (19, 49.)  (26, 49.)  (27, -196.)  (28, 49.)  (35, 49.)
> row 28: (20, 49.)  (27, 49.)  (28, -196.)  (29, 49.)  (36, 49.)
> row 29: (21, 49.)  (28, 49.)  (29, -196.)  (30, 49.)  (37, 49.)
> row 30: (22, 49.)  (29, 49.)  (30, -196.)  (31, 49.)  (38, 49.)
> row 31: (31, 1.)
> row 32: (32, 1.)
> row 33: (25, 49.)  (32, 49.)  (33, -196.)  (34, 49.)  (41, 49.)
> row 34: (26, 49.)  (33, 49.)  (34, -196.)  (35, 49.)  (42, 49.)
> row 35: (27, 49.)  (34, 49.)  (35, -196.)  (36, 49.)  (43, 49.)
> row 36: (28, 49.)  (35, 49.)  (36, -196.)  (37, 49.)  (44, 49.)
> row 37: (29, 49.)  (36, 49.)  (37, -196.)  (38, 49.)  (45, 49.)
> row 38: (30, 49.)  (37, 49.)  (38, -196.)  (39, 49.)  (46, 49.)
> row 39: (39, 1.)
> row 40: (40, 1.)
> row 41: (33, 49.)  (40, 49.)  (41, -196.)  (42, 49.)  (49, 49.)
> row 42: (34, 49.)  (41, 49.)  (42, -196.)  (43, 49.)  (50, 49.)
> row 43: (35, 49.)  (42, 49.)  (43, -196.)  (44, 49.)  (51, 49.)
> row 44: (36, 49.)  (43, 49.)  (44, -196.)  (45, 49.)  (52, 49.)
> row 45: (37, 49.)  (44, 49.)  (45, -196.)  (46, 49.)  (53, 49.)
> row 46: (38, 49.)  (45, 49.)  (46, -196.)  (47, 49.)  (54, 49.)
> row 47: (47, 1.)
> row 48: (48, 1.)
> row 49: (41, 49.)  (48, 49.)  (49, -196.)  (50, 49.)  (57, 49.)
> row 50: (42, 49.)  (49, 49.)  (50, -196.)  (51, 49.)  (58, 49.)
> row 51: (43, 49.)  (50, 49.)  (51, -196.)  (52, 49.)  (59, 49.)
> row 52: (44, 49.)  (51, 49.)  (52, -196.)  (53, 49.)  (60, 49.)
> row 53: (45, 49.)  (52, 49.)  (53, -196.)  (54, 49.)  (61, 49.)
> row 54: (46, 49.)  (53, 49.)  (54, -196.)  (55, 49.)  (62, 49.)
> row 55: (55, 1.)
> row 56: (56, 1.)
> row 57: (57, 1.)
> row 58: (58, 1.)
> row 59: (59, 1.)
> row 60: (60, 1.)
> row 61: (61, 1.)
> row 62: (62, 1.)
> row 63: (63, 1.)
> 
> This the output of the original C ex13 code:
> 
> Mat Object: 1 MPI processes
>   type: seqaij
> row 0: (0, 1.)  (1, 0.)  (8, 0.)
> row 1: (0, 0.)  (1, 1.)  (2, 0.)  (9, 0.)
> row 2: (1, 0.)  (2, 1.)  (3, 0.)  (10, 0.)
> row 3: (2, 0.)  (3, 1.)  (4, 0.)  (11, 0.)
> row 4: (3, 0.)  (4, 1.)  (5, 0.)  (12, 0.)
> row 5: (4, 0.)  (5, 1.)  (6, 0.)  (13, 0.)
> row 6: (5, 0.)  (6, 1.)  (7, 0.)  (14, 0.)
> row 7: (6, 0.)  (7, 1.)  (15, 0.)
> row 8: (0, 0.)  (8, 1.)  (9, 0.)  (16, 0.)
> row 9: (1, 49.)  (8, 49.)  (9, -196.)  (10, 49.)  (17, 49.)
> row 10: (2, 49.)  (9, 49.)  (10, -196.)  (11, 49.)  (18, 49.)
> row 11: (3, 49.)  (10, 49.)  (11, -196.)  (12, 49.)  (19, 49.)
> row 12: (4, 49.)  (11, 49.)  (12, -196.)  (13, 49.)  (20, 49.)
> row 13: (5, 49.)  (12, 49.)  (13, -196.)  (14, 49.)  (21, 49.)
> row 14: (6, 49.)  (13, 49.)  (14, -196.)  (15, 49.)  (22, 49.)
> row 15: (7, 0.)  (14, 0.)  (15, 1.)  (23, 0.)
> row 16: (8, 0.)  (16, 1.)  (17, 0.)  (24, 0.)
> row 17: (9, 49.)  (16, 49.)  (17, -196.)  (18, 49.)  (25, 49.)
> row 18: (10, 49.)  (17, 49.)  (18, -196.)  (19, 49.)  (26, 49.)
> row 19: (11, 49.)  (18, 49.)  (19, -196.)  (20, 49.)  (27, 49.)
> row 20: (12, 49.)  (19, 49.)  (20, -196.)  (21, 49.)  (28, 49.)
> row 21: (13, 49.)  (20, 49.)  (21, -196.)  (22, 49.)  (29, 49.)
> row 22: (14, 49.)  (21, 49.)  (22, -196.)  (23, 49.)  (30, 49.)
> row 23: (15, 0.)  (22, 0.)  (23, 1.)  (31, 0.)
> row 24: (16, 0.)  (24, 1.)  (25, 0.)  (32, 0.)
> row 25: (17, 49.)  (24, 49.)  (25, -196.)  (26, 49.)  (33, 49.)
> row 26: (18, 49.)  (25, 49.)  (26, -196.)  (27, 49.)  (34, 49.)
> row 27: (19, 49.)  (26, 49.)  (27, -196.)  (28, 49.)  (35, 49.)
> row 28: (20, 49.)  (27, 49.)  (28, -196.)  (29, 49.)  (36, 49.)
> row 29: (21, 49.)  (28, 49.)  (29, -196.)  (30, 49.)  (37, 49.)
> row 30: (22, 49.)  (29, 49.)  (30, -196.)  (31, 49.)  (38, 49.)
> row 31: (23, 0.)  (30, 0.)  (31, 1.)  (39, 0.)
> row 32: (24, 0.)  (32, 1.)  (33, 0.)  (40, 0.)
> row 33: (25, 49.)  (32, 49.)  (33, -196.)  (34, 49.)  (41, 49.)
> row 34: (26, 49.)  (33, 49.)  (34, -196.)  (35, 49.)  (42, 49.)
> row 35: (27, 49.)  (34, 49.)  (35, -196.)  (36, 49.)  (43, 49.)
> row 36: (28, 49.)  (35, 49.)  (36, -196.)  (37, 49.)  (44, 49.)
> row 37: (29, 49.)  (36, 49.)  (37, -196.)  (38, 49.)  (45, 49.)
> row 38: (30, 49.)  (37, 49.)  (38, -196.)  (39, 49.)  (46, 49.)
> row 39: (31, 0.)  (38, 0.)  (39, 1.)  (47, 0.)
> row 40: (32, 0.)  (40, 1.)  (41, 0.)  (48, 0.)
> row 41: (33, 49.)  (40, 49.)  (41, -196.)  (42, 49.)  (49, 49.)
> row 42: (34, 49.)  (41, 49.)  (42, -196.)  (43, 49.)  (50, 49.)
> row 43: (35, 49.)  (42, 49.)  (43, -196.)  (44, 49.)  (51, 49.)
> row 44: (36, 49.)  (43, 49.)  (44, -196.)  (45, 49.)  (52, 49.)
> row 45: (37, 49.)  (44, 49.)  (45, -196.)  (46, 49.)  (53, 49.)
> row 46: (38, 49.)  (45, 49.)  (46, -196.)  (47, 49.)  (54, 49.)
> row 47: (39, 0.)  (46, 0.)  (47, 1.)  (55, 0.)
> row 48: (40, 0.)  (48, 1.)  (49, 0.)  (56, 0.)
> row 49: (41, 49.)  (48, 49.)  (49, -196.)  (50, 49.)  (57, 49.)
> row 50: (42, 49.)  (49, 49.)  (50, -196.)  (51, 49.)  (58, 49.)
> row 51: (43, 49.)  (50, 49.)  (51, -196.)  (52, 49.)  (59, 49.)
> row 52: (44, 49.)  (51, 49.)  (52, -196.)  (53, 49.)  (60, 49.)
> row 53: (45, 49.)  (52, 49.)  (53, -196.)  (54, 49.)  (61, 49.)
> row 54: (46, 49.)  (53, 49.)  (54, -196.)  (55, 49.)  (62, 49.)
> row 55: (47, 0.)  (54, 0.)  (55, 1.)  (63, 0.)
> row 56: (48, 0.)  (56, 1.)  (57, 0.)
> row 57: (49, 0.)  (56, 0.)  (57, 1.)  (58, 0.)
> row 58: (50, 0.)  (57, 0.)  (58, 1.)  (59, 0.)
> row 59: (51, 0.)  (58, 0.)  (59, 1.)  (60, 0.)
> row 60: (52, 0.)  (59, 0.)  (60, 1.)  (61, 0.)
> row 61: (53, 0.)  (60, 0.)  (61, 1.)  (62, 0.)
> row 62: (54, 0.)  (61, 0.)  (62, 1.)  (63, 0.)
> row 63: (55, 0.)  (62, 0.)  (63, 1.)
> 
> I'm filling in the wrong way.
> Thanks.
> 
> Nicola
> 
> 
> -- 
> 
> Nicola Creati
> Istituto Nazionale di Oceanografia e di Geofisica Sperimentale - OGS www.inogs.it
> Dipartimento di Geofisica della Litosfera Geophysics of Lithosphere Department
> CARS (Cartography and Remote Sensing) Research Group http://www.inogs.it/Cars/
> Borgo Grotta Gigante 42/c 34010 Sgonico - Trieste - ITALY ncreati at ogs.trieste.it
> off.   +39 040 2140 213
> fax.   +39 040 327307
> 
> _____________________________________________________________________
> This communication, that may contain confidential and/or legally privileged information, is intended solely for the use of the intended addressees. Opinions, conclusions and other information contained in this message, that do not relate to the official business of OGS, shall be considered as not given or endorsed by it. Every opinion or advice contained in this communication is subject to the terms and conditions provided by the agreement governing the engagement with such a client. Any use, disclosure, copying or distribution of the contents of this communication by a not-intended recipient or in violation of the purposes of this communication is strictly prohibited and may be unlawful. For Italy only: Ai sensi del D.Lgs.196/2003 - "T.U. sulla Privacy" si precisa che le informazioni contenute in questo messaggio sono riservate ed a uso esclusivo del destinatario.
> 



More information about the petsc-users mailing list