Skip to content
Snippets Groups Projects
Commit cc564534 authored by Elias Pipping's avatar Elias Pipping Committed by Elias Pipping
Browse files

Fix up CurvedFunction

parent 8f71e42d
No related branches found
No related tags found
No related merge requests found
#ifndef CURVED_FUNCTION_HH
#define CURVED_FUNCTION_HH
#include <cmath>
#include <dune/fufem/interval.hh>
namespace Dune {
......@@ -35,16 +36,14 @@ template <class NonlinearityType> class CurvedFunction {
}
void domain(Interval<double> &domain) const {
// TODO
domain[0] = 0;
domain[1] = 1;
domain[0] = -M_PI;
domain[1] = M_PI;
}
void cartesian(double m, VectorType &y) const {
y = 0;
y.axpy(1 - m, x);
y.axpy(m, dir);
y /= y.two_norm();
y.axpy(std::cos(m), x);
y.axpy(std::sin(m), dir);
}
private:
......@@ -54,17 +53,18 @@ template <class NonlinearityType> class CurvedFunction {
VectorType const &x;
VectorType const &dir;
/*
Tangential vector within the plane, with positive direction.
/* If x and d were normalised, we would have
< (1-m)x + m*y,-m*|y|^2*x+(1-m)*|x|^2*y>
= -m(1-m)|y|^2<x,x> + m(1-m)|x|^2<y,y> (because <x,y> = 0)
= 0
cartesian(a) = cos(a) * x + sin(a) * d and
tangent(a) = -sin(a) * x + cos(a) * d.
Since we x and d are not normalised and the return of
cartesian() is fixed, we scale the tangent.
*/
void tangentialDirection(double m, VectorType &y) const {
y = 0;
y.axpy(-m * dir.two_norm2(), x);
y.axpy((1 - m) * x.two_norm2(), dir);
y.axpy(-std::sin(m) * dir.two_norm2(), x);
y.axpy(std::cos(m) * x.two_norm2(), dir);
}
};
}
......
......@@ -35,18 +35,18 @@ int main() {
start[0] = 0;
start[1] = 1;
double const ret1 = functionTester(J, start, 3);
double const ret1 = functionTester(J, start, 5);
// Something random
start[0] = 279;
start[1] = -96;
double const ret2 = functionTester(J, start, 3);
assert(std::abs(ret1 - ret2) < 1e-5);
double const ret2 = functionTester(J, start, 5);
assert(std::abs(ret1 - ret2) < 1e-7);
start[0] = 0;
start[1] = 0;
double const ret3 = functionTester(J, start, 1);
assert(std::abs(ret1 - ret3) < 1e-5);
assert(std::abs(ret1 - ret3) < 1e-7);
}
......@@ -41,12 +41,12 @@ int main() {
start[0] = 279;
start[1] = -96;
double const ret2 = functionTester(J, start, 3);
assert(std::abs(ret1 - ret2) < 1e-5);
double const ret2 = functionTester(J, start, 5);
assert(std::abs(ret1 - ret2) < 1e-7);
start[0] = 0;
start[1] = 0;
double const ret3 = functionTester(J, start, 1);
assert(std::abs(ret1 - ret3) < 1e-5);
double const ret3 = functionTester(J, start, 2);
assert(std::abs(ret1 - ret3) < 1e-7);
}
......@@ -41,12 +41,12 @@ int main() {
start[0] = 279;
start[1] = -96;
double const ret2 = functionTester(J, start, 4);
assert(std::abs(ret1 - ret2) < 1e-8);
double const ret2 = functionTester(J, start, 5);
assert(std::abs(ret1 - ret2) < 1e-7);
start[0] = 0;
start[1] = 0;
double const ret3 = functionTester(J, start, 1);
assert(std::abs(ret2 - ret3) < 1e-5);
double const ret3 = functionTester(J, start, 2);
assert(std::abs(ret1 - ret3) < 1e-7);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment