Changeset 3f6604


Ignore:
Timestamp:
Sep 6, 2015, 10:27:54 PM (10 years ago)
Author:
Frederik Heber <heber@…>
Children:
199fe3
Parents:
b303d0
git-author:
Frederik Heber <heber@…> (03/13/15 15:03:26)
git-committer:
Frederik Heber <heber@…> (09/06/15 22:27:54)
Message:

tempcommit: Some fixes to interpolate_test.

  • now they don't fail anymore and test something sensible.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • test/unit_test/unit_test/interpolate_test.cpp

    rb303d0 r3f6604  
    3434using namespace VMG;
    3535
    36 const vmg_float sine_factor = 2.0 * Math::pi;
     36const Vector sine_factor(1.5 * Math::pi, 3.7 * Math::pi, 2.213 * Math::pi);
    3737
    3838static inline vmg_float f(const Vector& pos)
    3939{
    40   return std::sin(sine_factor*pos.X())
    41        * std::sin(sine_factor*pos.Y())
    42        * std::sin(sine_factor*pos.Z());
     40  return std::sin(sine_factor[0]*pos.X())
     41       * std::sin(sine_factor[1]*pos.Y())
     42       * std::sin(sine_factor[2]*pos.Z());
    4343}
    4444
    45 /*
    4645static inline Vector grad_f(const Vector& pos)
    4746{
    48   return -1.0 * sine_factor * Vector(std::cos(sine_factor*pos.X()) * std::sin(sine_factor*pos.Y()) * std::sin(sine_factor*pos.Z()),
    49                                      std::sin(sine_factor*pos.X()) * std::cos(sine_factor*pos.Y()) * std::sin(sine_factor*pos.Z()),
    50                                      std::sin(sine_factor*pos.X()) * std::sin(sine_factor*pos.Y()) * std::cos(sine_factor*pos.Z()));
     47  return -1.0 * sine_factor * Vector(std::cos(sine_factor[0]*pos.X()) * std::sin(sine_factor[1]*pos.Y()) * std::sin(sine_factor[2]*pos.Z()),
     48                                     std::sin(sine_factor[0]*pos.X()) * std::cos(sine_factor[1]*pos.Y()) * std::sin(sine_factor[2]*pos.Z()),
     49                                     std::sin(sine_factor[0]*pos.X()) * std::sin(sine_factor[1]*pos.Y()) * std::cos(sine_factor[2]*pos.Z()));
    5150}
    52 */
    5351
    5452struct InterpolateFixture
     
    10199        p.Pos() += 0.5 * grid->Extent().MeshWidth();
    102100        ip.Evaluate(p);
    103         BOOST_CHECK_SMALL(p.Pot() - f(p.Pos()), vmg_float(1.0e-7));
     101        BOOST_CHECK_SMALL(p.Pot() - f(p.Pos()), vmg_float(1.0e-6));
    104102
    105103      }
     
    107105}
    108106
    109 /*
    110107BOOST_AUTO_TEST_CASE(InterpolateFieldTest)
    111108{
     
    115112  Particle::Particle p;
    116113
    117   vmg_float max_error = 0.0;
     114  vmg_float max_error = std::numeric_limits<vmg_float>::min();
    118115
    119116  for(p.Pos().X()=grid->Extent().Begin().X(); p.Pos().X()<grid->Extent().End().X(); p.Pos().X() += 0.01 * (grid->Extent().End().X() - grid->Extent().Begin().X()))
     
    130127        ip.Evaluate(p);
    131128
    132         for (int j=0; j<3; ++j)
    133           max_error = std::max(max_error, p.Field()[j] - grad_f(p.Pos())[j]);
    134 
     129        for (int j=0; j<3; ++j) {
     130          BOOST_CHECK_SMALL(p.Field()[j] - grad_f(p.Pos())[j], vmg_float(1.0e-4));
     131          if (fabs(grad_f(p.Pos())[j]) > 1e-10)
     132                max_error = std::max(max_error, fabs((p.Field()[j] - grad_f(p.Pos())[j])/grad_f(p.Pos())[j]));
     133        }
    135134      }
    136135
    137   std::printf("Max error: %e\n", max_error);
     136  std::printf("Max rel. error: %e\n", max_error);
    138137
     138  max_error = std::numeric_limits<vmg_float>::min();
    139139  p.Pos().X() = 0.25;
    140140  p.Pos().Y() = 0.25;
     
    149149
    150150    ip.Evaluate(p);
     151
     152    for (int j=0; j<3; ++j) {
     153          BOOST_CHECK_SMALL(p.Field()[j] - grad_f(p.Pos())[j], vmg_float(1.0e-4));
     154      if (fabs(grad_f(p.Pos())[j]) > 1e-10)
     155        max_error = std::max(max_error, fabs((p.Field()[j] - grad_f(p.Pos())[j])/grad_f(p.Pos())[j]));
     156    }
    151157  }
     158  std::printf("Max rel. error moving along z: %e\n", max_error);
    152159}
    153 */
     160
    154161
    155162BOOST_AUTO_TEST_SUITE_END()
Note: See TracChangeset for help on using the changeset viewer.