LifeV
VerifySolutions.cpp
Go to the documentation of this file.
1 //@HEADER
2 /*
3 *******************************************************************************
4 
5  Copyright (C) 2014 EPFL, Politecnico di Milano, Emory University
6 
7  This file is part of LifeV.
8 
9  LifeV is free software; you can redistribute it and/or modify
10  it under the terms of the GNU Lesser General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  LifeV is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public License
20  along with LifeV. If not, see <http://www.gnu.org/licenses/>.
21 
22 *******************************************************************************
23 */
24 //@HEADER
25 
26 /*!
27  @file VerifySolutions.cpp
28  @brief This files contains the description of the VerifySolutions class, which is a helper class for checking results by
29  Computing the mean norm and correlation matrix of vectors
30 
31  @author Simone Deparis <simone.deparis@epfl.ch>
32  @date 12-05-2014
33  @mantainer Simone Deparis <simone.deparis@epfl.ch>
34 
35  */
36 
37 #include "VerifySolutions.hpp"
38 #include <vector>
39 #include <iostream>
40 
41 namespace LifeV
42 {
43 
45  M_NormMean (0),
47  M_VectorList (0)
48 {
49 }
50 
52 {
53 }
54 
55 void VerifySolutions::PushBack (VectorEpetra const& newVector)
56 {
57 
58  M_VectorList.push_back (newVector);
59 }
60 
62 {
63  if (M_VectorList.size() == 0)
64  {
65  M_NormMean = 0;
66  M_CorrelationMatrix.Shape (0, 0);
67  return;
68  }
69 
70  // Compute Mean Vector
71  std::list<VectorEpetra>::iterator it = M_VectorList.begin();
72 
73  VectorEpetra MeanVector (*it);
74  ++it;
75  for ( ; it != M_VectorList.end(); ++it)
76  {
77  MeanVector += *it;
78  }
79 
80  MeanVector /= M_VectorList.size();
81  M_NormMean = MeanVector.norm2();
82 
83  // Compute u_i-u, inside a vector
84  std::vector<VectorEpetra> corrVectorsList (M_VectorList.begin(), M_VectorList.end() );
85  std::vector<VectorEpetra>::iterator cit;
86  for (cit = corrVectorsList.begin(); cit != corrVectorsList.end(); ++cit)
87  {
88  *cit -= MeanVector;
89  }
90 
91 
92  // Compute Correlation matrix
93  M_CorrelationMatrix.Shape (corrVectorsList.size(), corrVectorsList.size() );
94 
95  for (size_t i (0); i < M_VectorList.size(); ++i)
96  {
97  for (size_t j (i); j < M_VectorList.size(); ++j)
98  {
99  M_CorrelationMatrix (i, j) = corrVectorsList[i].dot (corrVectorsList[j]);
100  M_CorrelationMatrix (j, i) = M_CorrelationMatrix (i, j);
101  }
102  }
103 }
104 
106 {
107  if ( refM.M() != M_CorrelationMatrix.M() || refM.N() != M_CorrelationMatrix.N() )
108  {
109  return false;
110  }
111 
112  for (int i (0); i < refM.M(); ++i)
113  {
114  for (int j (0); j < refM.M(); ++j)
115  {
116  if ( abs (refM (i, j) - M_CorrelationMatrix (i, j) ) > tol )
117  {
118  std::cout << "Correlation matrix changed" << std::endl;
119  return false;
120  }
121  }
122  }
123 
124  std::cout << "Correlation matrix unchanged" << std::endl;
125 
126  return true;
127 }
128 
129 bool VerifySolutions::Check ( Real referenceMean, Real tol) const
130 {
131  if ( abs (referenceMean - M_NormMean) > tol )
132  {
133  std::cout << "Norm of the mean vector changed" << std::endl;
134  return false;
135  }
136 
137  std::cout << "Norm of the mean vector unchanged" << std::endl;
138 
139  return true;
140 }
141 
142 void VerifySolutions::Print () const
143 {
144 
145  std::cout.precision (15);
146 
147  std::cout << "Real referenceMeanNorm = " << M_NormMean << ";" << std::endl;
148 
149  std::cout << "Epetra_SerialDenseMatrix refM("
150  << M_CorrelationMatrix.M() << "," << M_CorrelationMatrix.N() << ");"
151  << std::endl;
152 
153  for (int i (0); i < M_CorrelationMatrix.M(); ++i)
154  {
155  for (int j (0); j < M_CorrelationMatrix.M(); ++j)
156  {
157  std::cout << "refM(" << i << "," << j << ") = " << M_CorrelationMatrix (i, j) << "; ";
158  }
159  std::cout << std::endl;
160  }
161 
162 
163 }
164 
165 } /* namespace LifeV */
VectorEpetra - The Epetra Vector format Wrapper.
void updateInverseJacobian(const UInt &iQuadPt)
void Print() const
Print Mean and Correlation matrix as c++ lines ready to be inserted into the test.
void ComputeCorrelation()
Compute the correlation matrix and norm of the mean.
void PushBack(VectorEpetra const &newVector)
Add a vector to the list of stored vectors.
double Real
Generic real data.
Definition: LifeV.hpp:175
This class helps the testsuites in verifying that the solutions do not change from one execution to t...
bool Check(Real referenceMean, Real tol) const
Checks that the current norm of the mean of the vectors is the same as the one provided by the user...
Real norm2() const
Compute and return the norm 2.