Skip to content
Snippets Groups Projects
Commit bd013067 authored by oliver.sander_at_tu-dresden.de's avatar oliver.sander_at_tu-dresden.de Committed by Patrick Jaap
Browse files

Fix adolcmaterialtest.cc

The test erroneously checked for a small *absolute* error, but the
numbers in this test are very large (around 1e8), so checking
for a small *relative* error is more appropriate.  This change
makes the test pass.
parent 9892b0c4
Branches releases/2.7
No related tags found
No related merge requests found
Pipeline #27808 passed
#include<config.h> #include<config.h>
#include <fstream>
#include <random> #include <random>
#include <dune/fufem/assemblers/localassemblers/adolclocalenergy.hh> #include <dune/fufem/assemblers/localassemblers/adolclocalenergy.hh>
...@@ -11,7 +10,6 @@ ...@@ -11,7 +10,6 @@
#include <dune/istl/bvector.hh> #include <dune/istl/bvector.hh>
#include <dune/istl/bcrsmatrix.hh> #include <dune/istl/bcrsmatrix.hh>
#include <dune/istl/matrixindexset.hh>
#include <dune/grid/uggrid.hh> #include <dune/grid/uggrid.hh>
...@@ -90,10 +88,15 @@ int main (int argc, char *argv[]) try ...@@ -90,10 +88,15 @@ int main (int argc, char *argv[]) try
for (size_t i=0; i < adolcGradient.size(); ++i) { for (size_t i=0; i < adolcGradient.size(); ++i) {
auto diff = adolcGradient[i] - paperGrad[i]; auto relativeError = (adolcGradient[i] - paperGrad[i]).two_norm()
/ std::max(adolcGradient[i].two_norm(), paperGrad[i].two_norm());
if (diff.two_norm()>1e-5) if (relativeError > 1e-11)
DUNE_THROW(Dune::Exception,"Wrong local derivative, error is "<<diff.two_norm()); {
std::cout << "adolc:\n" << adolcGradient[i] << std::endl;
std::cout << "closed-form:\n" << paperGrad[i] << std::endl;
DUNE_THROW(Dune::Exception,"Wrong local derivative, error is " << relativeError);
}
} }
// Test hessian assembler // Test hessian assembler
...@@ -125,7 +128,6 @@ int main (int argc, char *argv[]) try ...@@ -125,7 +128,6 @@ int main (int argc, char *argv[]) try
auto adolcEndIt = adolcRow.end(); auto adolcEndIt = adolcRow.end();
auto paperIt = paperRow.begin(); auto paperIt = paperRow.begin();
auto paperEndIt = paperRow.end();
for (; adolcIt != adolcEndIt; ++adolcIt, ++paperIt) { for (; adolcIt != adolcEndIt; ++adolcIt, ++paperIt) {
...@@ -133,18 +135,22 @@ int main (int argc, char *argv[]) try ...@@ -133,18 +135,22 @@ int main (int argc, char *argv[]) try
DUNE_THROW(Dune::Exception,"Not the same sparsity pattern!"<<adolcIt.index() DUNE_THROW(Dune::Exception,"Not the same sparsity pattern!"<<adolcIt.index()
<<"!="<<paperIt.index()); <<"!="<<paperIt.index());
auto diff = *adolcIt; auto relativeError = (*adolcIt - *paperIt).frobenius_norm()
diff -= *paperIt; / std::max(adolcIt->frobenius_norm(), paperIt->frobenius_norm());
if (diff.frobenius_norm() > 1e-4) if (relativeError > 1e-11)
DUNE_THROW(Dune::Exception,"Wrong local hessian, error is "<<diff.frobenius_norm()); {
std::cout << "adolc:\n" << *adolcIt << std::endl;
std::cout << "closed-form:\n" << *paperIt << std::endl;
DUNE_THROW(Dune::Exception,"Wrong local hessian, error is " << relativeError);
}
} }
assert(paperIt==paperEndIt); assert(paperIt==paperRow.end());
} }
return 0; return 0;
} catch (Exception e) { } catch (const Exception& e) {
std::cout << e << std::endl; std::cout << e << std::endl;
return 1; return 1;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment