"Fossies" - the Fresh Open Source Software Archive

Member "dune-istl-2.7.1/dune/istl/test/vbvectortest.cc" (26 Nov 2020, 2880 Bytes) of package /linux/misc/dune/dune-istl-2.7.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "vbvectortest.cc": 2.6.0_vs_2.7.0.

    1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
    2 // vi: set et ts=4 sw=2 sts=2:
    3 #include "config.h"
    4 #include <dune/istl/vbvector.hh>
    5 #include <dune/common/fvector.hh>
    6 #include <dune/common/typetraits.hh>
    7 #include <dune/common/test/testsuite.hh>
    8 
    9 #include <dune/common/test/iteratortest.hh>
   10 
   11 #include <dune/istl/test/vectortest.hh>
   12 
   13 using namespace Dune;
   14 
   15 int main()
   16 {
   17   TestSuite suite;
   18 
   19   VariableBlockVector<FieldVector<double,1> > v1;
   20   VariableBlockVector<FieldVector<double,1> > v2 = v1;
   21   VariableBlockVector<FieldVector<double,1> > v3(10);
   22   VariableBlockVector<FieldVector<double,1> > v4(10,4);
   23 
   24   v3.resize(20);
   25   v4.resize(20,8);
   26 
   27   v3 = v4;
   28 
   29   /*
   30     v3 is now fully initialized due to the former copy operation with
   31     the initialized vector v4.
   32     Calling the create iterator is not allowed, now.
   33     We have to un-initialize it first:
   34   */
   35   std::size_t size = 20;
   36   v3.resize(size); // this makes v3 unitialized again
   37 
   38   // Set block sizes with CreateIterator:
   39   for (auto cIt = v3.createbegin(); cIt!=v3.createend(); ++cIt)
   40     cIt.setblocksize(3);
   41 
   42   v3 = 1.0;
   43 
   44   // Test whether something from <algorithm> can be used to set the block sizes
   45   // We can't use std::fill() here, as that requires a forward iterator, std::fill_n()
   46   // is more lenient and settles for an output iterator
   47   v1.resize(size);
   48   std::fill_n(v1.createbegin(), size, 10);
   49 
   50   // More formally: test whether the CreateIterator is an output iterator in the stl sense
   51   v1.resize(5);
   52   testOutputIterator(v1.createbegin(), 5, 10);
   53 
   54   /* Copy-ing specific blocks with `auto` from a VariableBlockVector is tricky, because
   55    * the returned object will be a reference:
   56    */
   57   auto block0_copy_reference = v3[0];
   58   block0_copy_reference[0] = 4.2; // change first entry in the copy which has reference semantics. This also changes v3!
   59   suite.check(v3[0][0] != 1.0, "Show auto x = v3[0] has reference semantics")
   60     << "Unexpected behaviour: v3[0][0] is " << v3[0][0];
   61 
   62   v3[0][0]=1.0; // reset v3
   63 
   64   // For an actual copy, use the Dune::autoCopy() mechanism
   65   // This will give a BlockVector with the contents of v3[0].
   66   auto block0_autoCopy = Dune::autoCopy(v3[0]);
   67   block0_autoCopy[0] = 4.2;
   68   suite.check(v3[0][0] == 1.0, "Show that v3 was not modified when copying via autoCopy")
   69     << "Unexpected behaviour: v3[0][0] is " << v3[0][0];
   70 
   71 
   72   // Perform more general vector tests:
   73   testHomogeneousRandomAccessContainer(v3);
   74   Dune::testConstructibility<VariableBlockVector<FieldVector<double,1> > >();
   75   testNorms(v3);
   76   testVectorSpaceOperations(v3);
   77   testScalarProduct(v3);
   78 
   79   // Perform tests with a scalar vector entry
   80   VariableBlockVector<double> v5(10);
   81 
   82   testHomogeneousRandomAccessContainer(v5);
   83   Dune::testConstructibility<VariableBlockVector<double> >();
   84   testNorms(v5);
   85   testVectorSpaceOperations(v5);
   86   testScalarProduct(v5);
   87 
   88   return suite.exit();
   89 }