]> https://gitweb.dealii.org/ - dealii-svn.git/blob - tests/gla/vec_02.cc
Replace headers in tests, too
[dealii-svn.git] / tests / gla / vec_02.cc
1 // ---------------------------------------------------------------------
2 // $Id$
3 //
4 // Copyright (C) 2004 - 2013 by the deal.II authors
5 //
6 // This file is part of the deal.II library.
7 //
8 // The deal.II library is free software; you can use it, redistribute
9 // it, and/or modify it under the terms of the GNU Lesser General
10 // Public License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
12 // The full text of the license can be found in the file LICENSE at
13 // the top level of the deal.II distribution.
14 //
15 // ---------------------------------------------------------------------
16
17
18
19 // assignment of ghost vectors
20
21 #include "../tests.h"
22 #include <deal.II/lac/generic_linear_algebra.h>
23 #include <deal.II/base/index_set.h>
24 #include <fstream>
25 #include <iostream>
26 #include <iomanip>
27 #include <vector>
28
29 #include "gla.h"
30
31 template <class LA> 
32 void test ()
33 {
34   unsigned int myid = Utilities::MPI::this_mpi_process (MPI_COMM_WORLD);
35   unsigned int numproc = Utilities::MPI::n_mpi_processes (MPI_COMM_WORLD);
36   
37   if (myid==0)
38     deallog << "numproc=" << numproc << std::endl;
39
40                                    // each processor owns 2 indices and all
41                                    // are ghosting Element 1 (the second)
42
43   IndexSet local_active(numproc*2);
44   local_active.add_range(myid*2,myid*2+2);
45   IndexSet local_relevant(numproc*2);
46   local_relevant.add_range(1,2);
47
48   typename LA::MPI::Vector vb(local_active, MPI_COMM_WORLD);
49   typename LA::MPI::Vector v(local_active, local_relevant, MPI_COMM_WORLD);
50   typename LA::MPI::Vector v2(local_active, local_relevant, MPI_COMM_WORLD);
51
52   vb = 1.0;
53   v2 = vb;
54
55                                    // set local values
56   vb(myid*2)=myid*2.0;
57   vb(myid*2+1)=myid*2.0+1.0;
58
59   vb.compress(VectorOperation::insert);
60   vb*=2.0;
61   v=vb;
62
63   Assert(vb.size() == numproc*2, ExcInternalError());
64   Assert(v.size() == numproc*2, ExcInternalError());
65
66   Assert(!vb.has_ghost_elements(), ExcInternalError());
67   Assert(v.has_ghost_elements(), ExcInternalError());
68   
69                                    // check local values
70   if (Utilities::MPI::this_mpi_process (MPI_COMM_WORLD) == 0)
71     {
72       deallog << myid*2 << ":" << v(myid*2) << std::endl;
73       deallog << myid*2+1 << ":" << v(myid*2+1) << std::endl;
74     }
75   
76                                    //assignment from ghosted to ghosted
77   v2 = v;
78   Assert(v2(1) == 2.0, ExcInternalError());
79   Assert(v2(myid*2) == myid*4.0, ExcInternalError());
80   Assert(v2(myid*2+1) == myid*4.0+2.0, ExcInternalError());
81
82
83   
84   Assert(v(myid*2) == myid*4.0, ExcInternalError());
85   Assert(v(myid*2+1) == myid*4.0+2.0, ExcInternalError());
86   
87
88                                    // check ghost values
89   if (Utilities::MPI::this_mpi_process (MPI_COMM_WORLD) == 0)
90     deallog << "ghost: " << v(1) << std::endl;
91   Assert(v(1) == 2.0, ExcInternalError());
92
93                                    // done
94   if (myid==0)
95     deallog << "OK" << std::endl;
96 }
97
98
99
100 int main (int argc, char **argv)
101 {
102   Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv);
103   unsigned int myid = Utilities::MPI::this_mpi_process (MPI_COMM_WORLD);
104
105   deallog.push(Utilities::int_to_string(myid));
106
107   if (myid == 0)
108     {
109       std::ofstream logfile(output_file_for_mpi("vec_02").c_str());
110       deallog.attach(logfile);
111       deallog << std::setprecision(4);
112       deallog.depth_console(0);
113       deallog.threshold_double(1.e-10);
114
115       { 
116         deallog.push("PETSc");
117         test<LA_PETSc>();
118         deallog.pop();  
119         deallog.push("Trilinos");
120         test<LA_Trilinos>();
121         deallog.pop();  
122       }
123       
124     }
125   else
126       { 
127         deallog.push("PETSc");
128         test<LA_PETSc>();
129         deallog.pop();  
130         deallog.push("Trilinos");
131         test<LA_Trilinos>();
132         deallog.pop();  
133       }
134
135   if (myid==9999)
136     test<LA_Dummy>();
137   
138
139 }

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.