std::vector<bool> pattern (v.size(), false);
for (unsigned int i=0; i<v.size(); i+=1+i)
{
- v(i) += 1.;//PetscScalar (i,i);
+ v(i) += PetscScalar (i,i);
pattern[i] = true;
}
v.compress (VectorOperation::add);
- // check that they are ok, and this time
- // all of them
+ // check that they are ok, and this time all of them
for (unsigned int i=0; i<v.size(); ++i)
- Assert ( ( (pattern[i]==true) ) || //&& (v(i)==std::complex<double> (1.,1.)) ) ||
- ( (pattern[i]==false) ),
+ Assert ( ( (pattern[i]==true) && (v(i).real()==i) && (v(i).imag()==i) ) ||
+ //&& (v(i)==std::complex<double> (1.,1.)) ) ||
+ ( (pattern[i]==false) && (v(i).real()==0.) && (v(i).imag()==0.) ),
ExcInternalError());
deallog << "OK" << std::endl;
--- /dev/null
+
+DEAL::OK
// ---------------------------------------------------------------------
-// $Id:
+// $Id: element_access_02.cc
//
// Copyright (C) 2013 by the deal.II authors
//
#include <iostream>
#include <cassert>
-#include <complex>
-
-// test read/write access to matrices AS IS (no cast).
-//
-
-// Note: this test fails where an -1.*(unsigned integer) is used as
-// the input value to a matrix element. This needs to be fixed.
-
// sparse matrix elements
-void test_matrix (PETScWrappers::SparseMatrix &m)
+void test (PETScWrappers::SparseMatrix &m)
{
deallog << "Check matrix access" << std::endl;
// fill up a matrix with some numbers
for (unsigned int k=0; k<m.m(); ++k)
for (unsigned int l=0; l<m.n(); ++l)
- m.set (k,l, PetscScalar (+k+l,-k-l));
-
+ if (k>l)
+ m.set (k,l, PetscScalar (k+l,-1.*(k+l)));
+
m.compress (VectorOperation::add);
- // This fails, because the write above fails - see output file
+ // check the matrix is correctly filled
for (unsigned int k=0; k<m.m(); ++k)
for (unsigned int l=0; l<m.n(); ++l)
- Assert (m(k,l).real () == -1.*m(k,l).imag (),
+ Assert (m(k,l).real () == -1.*(m(k,l).imag ()),
ExcInternalError());
-
+
deallog << "OK" << std::endl;
}
{
std::ofstream logfile ("element_access_02/output");
dealii::deallog.attach (logfile);
- dealii::deallog.depth_console (0);
+ dealii::deallog.depth_console (0);
deallog.threshold_double(1.e-10);
try
{
PetscInitialize (&argc, &argv, (char*) 0, (char*) 0);
{
- PETScWrappers::SparseMatrix m (5,5,5);
- test_matrix (m);
+ PETScWrappers::SparseMatrix m (10,10,10);
+ test (m);
deallog << "matrix:" << std::endl;
m.print (logfile);
--- /dev/null
+
+DEAL::Check matrix access
+DEAL::OK
+DEAL::matrix:
+(1,0) (1.00000,-1.00000)
+(2,0) (2.00000,-2.00000)
+(2,1) (3.00000,-3.00000)
+(3,0) (3.00000,-3.00000)
+(3,1) (4.00000,-4.00000)
+(3,2) (5.00000,-5.00000)
+(4,0) (4.00000,-4.00000)
+(4,1) (5.00000,-5.00000)
+(4,2) (6.00000,-6.00000)
+(4,3) (7.00000,-7.00000)
+(5,0) (5.00000,-5.00000)
+(5,1) (6.00000,-6.00000)
+(5,2) (7.00000,-7.00000)
+(5,3) (8.00000,-8.00000)
+(5,4) (9.00000,-9.00000)
+(6,0) (6.00000,-6.00000)
+(6,1) (7.00000,-7.00000)
+(6,2) (8.00000,-8.00000)
+(6,3) (9.00000,-9.00000)
+(6,4) (10.0000,-10.0000)
+(6,5) (11.0000,-11.0000)
+(7,0) (7.00000,-7.00000)
+(7,1) (8.00000,-8.00000)
+(7,2) (9.00000,-9.00000)
+(7,3) (10.0000,-10.0000)
+(7,4) (11.0000,-11.0000)
+(7,5) (12.0000,-12.0000)
+(7,6) (13.0000,-13.0000)
+(8,0) (8.00000,-8.00000)
+(8,1) (9.00000,-9.00000)
+(8,2) (10.0000,-10.0000)
+(8,3) (11.0000,-11.0000)
+(8,4) (12.0000,-12.0000)
+(8,5) (13.0000,-13.0000)
+(8,6) (14.0000,-14.0000)
+(8,7) (15.0000,-15.0000)
+(9,0) (9.00000,-9.00000)
+(9,1) (10.0000,-10.0000)
+(9,2) (11.0000,-11.0000)
+(9,3) (12.0000,-12.0000)
+(9,4) (13.0000,-13.0000)
+(9,5) (14.0000,-14.0000)
+(9,6) (15.0000,-15.0000)
+(9,7) (16.0000,-16.0000)
+(9,8) (17.0000,-17.0000)
+
// check SparseMatrix::add(other, factor)
-// This is the same as sparse_matrix_02.cc, but uses integer input to
-// complex numbers. AT the time of writing, this documents the element
-// access problem for matrices.
-//
-// TODO: Fix this before going further with petsc-scalar=complex.
+// This is in general the same as sparse_matrix_02.cc, but uses
+// integer input to complex numbers. Since it was done, make a note of
+// a generic failure / annoyance
#include "../tests.h"
#include <deal.II/lac/petsc_vector.h>
for (unsigned int k=0; k<m2.m(); ++k)
{
// This fails
- m2.set(k,k,PetscScalar(k,-k));
+ // m2.set(k,k,PetscScalar(k,-k));
// This is ok
- // m2.set(k,k,PetscScalar(k,-1.0*k));
+ m2.set(k,k,PetscScalar(k,-1.0*k));
}
m2.compress(VectorOperation::add);
-// check Vector
-
-// This is the similar to sparse_matrix_02.cc as it uses integer input
-// to complex numbers. This purposefully illustrates that this
-// assignment DOES NOT works for PETScWrappers::Vector.
+// check Vector, make a note of a generic failure / annoyance
#include "../tests.h"
#include <deal.II/lac/petsc_vector.h>
+#include <deal.II/lac/vector.h>
#include <fstream>
#include <iostream>
#include <vector>
for (unsigned int k=0; k<v2.size(); ++k)
{
// This fails
- v2(k) = PetscScalar (k,-k);
+ // v2(k) = PetscScalar (k,-k);
// This is ok
- // v2(k) = PetscScalar (k,-1.0*k);
+ v2(k) = PetscScalar (k,-1.0*k);
}
v2.compress(VectorOperation::add);
deallog << "OK" << std::endl;
}
-
-
int main (int argc, char **argv)
{
std::ofstream logfile("vector_02/output");