CppNoddy  0.92
Loading...
Searching...
No Matches
MatrixDistributed_petscd_mumps.cpp
Go to the documentation of this file.
1/// \file DistributedMatrixTest_petscz.cpp
2/// \ingroup Tests
3/// \ingroup Matrix
4/// A superficial sanity check
5
6#include <DistributedMatrix.h>
7#include <DistributedVector.h>
9#include <PetscSession.h>
10#include <Types.h>
11#include <mpi.h>
12
13using namespace std;
14using namespace CppNoddy;
15
16
17int main(int argc, char *argv[])
18{
19 PetscSession::getInstance(argc,argv);
20
21 PetscPrintf(PETSC_COMM_WORLD, "\n=== Vector: A distributed (double) example ==========\n\n");
22
23 std::size_t Nx(101);
24 std::size_t Ny(101);
25 std::size_t N(Nx*Ny);
26 double deltax = 1.0/(Nx-1);
27 double deltaxSq = deltax*deltax;
28 double deltay = 1.0/(Ny-1);
29 double deltaySq = deltay*deltay;
30 DistributedMatrix<double> matA( N, N, 5, 4 );
31 DistributedVector<double> vecB( N );
32
33 for(std::size_t j = 0; j < Ny; ++j ) {
34 matA.set_elt(j,j,1.0);
35 vecB.set_elt(j,0.0);
36 }
37 //
38 for(std::size_t i = 1; i < Nx-1; ++i ) {
39 matA.set_elt( i*Ny, i*Ny, 1.0 );
40 vecB.set_elt( i*Ny, 0.0 );
41 for(std::size_t j = 1; j < Ny-1; ++j ) {
42 DenseVector<int> index;
44 index.push_back( i*Ny+j-1 );
45 value.push_back( 1./deltaySq );
46 index.push_back( i*Ny+j );
47 value.push_back( -2.0/deltaySq - 2.0/deltaxSq);
48 index.push_back( i*Ny+j+1 );
49 value.push_back( 1./deltaySq );
50 index.push_back( (i-1)*Ny + j );
51 value.push_back( 1./deltaxSq );
52 index.push_back( (i+1)*Ny + j );
53 value.push_back( 1./deltaxSq );
54 matA.set_row( i*Ny+j, index, value );
55 vecB.set_elt( i*Ny+j, 1.0 );
56 }
57 matA.set_elt( i*Ny+Ny-1, i*Ny+Ny-1, 1.0 );
58 vecB.set_elt( i*Ny+Ny-1, 0.0 );
59 }
60 for(std::size_t j = 0; j < Ny; ++j ) {
61 matA.set_elt( Ny*(Nx-1) + j , Ny*(Nx-1) + j, 1.0 );
62 vecB.set_elt( Ny*(Nx-1) + j, 0.0 );
63 }
64
65 matA.final_assembly();
66 vecB.final_assembly();
67
68 //matA.view();
69 //vecB.view();
70
71 DistributedLinearSystem<double> system( &matA, &vecB );
72 system.solve();
73
74 cout << vecB.two_norm() << "\n";
75
76 //vecB.view();
77
78}
79
80
81
int main()
Definition: ArcCircle.cpp:39
Specification of a sparse-storage distributed linear system class.
A matrix class that constructs a SPARSE/DISTRIBUTED matrix using PETSc.
A class that constructs a SPARSE/DISTRIBUTED vector using PETSc.
An DenseVector class – a dense vector object.
Definition: DenseVector.h:34
void push_back(const _Type &fill)
A pass-thru definition of push_back.
Definition: DenseVector.h:310
A collection of OO numerical routines aimed at simple (typical) applied problems in continuum mechani...

© 2012

R.E. Hewitt