00001 #ifndef MKE_H
00002 #define MKE_H
00003
00004
00005
00202 #include <stdio.h>
00203
00204 #include "polynom.h"
00205
00206 typedef unsigned int uint;
00207
00213 namespace phelm {
00214
00224 struct Point {
00225 double x;
00226 double y;
00227
00229 Point(): x(0), y(0) {}
00235 Point(double x1, double y1): x(x1), y(y1) {}
00240 Point(double *x1): x(x1[0]), y(x1[1]) {}
00241
00247 Point operator / (double k)
00248 {
00249 return Point(x / k, y / k);
00250 }
00251
00257 Point operator * (double k)
00258 {
00259 return Point(x * k, y * k);
00260 }
00261 };
00262
00270 inline Point operator + (const Point & p1, const Point & p2)
00271 {
00272 return Point(p1.x + p2.x, p1.y + p2.y);
00273 }
00274
00279 struct MeshPoint {
00285 std::vector < Point > p;
00286
00290 MeshPoint() {}
00291
00297 MeshPoint(double x, double y) {
00298 add(Point(x, y));
00299 }
00300
00305 MeshPoint(double *x) {
00306 add(Point(x));
00307 }
00308
00313 void add(const Point & p1) {
00314 p.push_back(p1);
00315 }
00316
00322 double x(int zone = 0) const {
00323 return p[zone].x;
00324 }
00325
00331 double y(int zone = 0) const {
00332 return p[zone].y;
00333 }
00334 };
00335
00339 struct Triangle {
00340 int p[3];
00341 int z;
00342 std::vector < Polynom > phik;
00343 double x[3];
00344 double y[3];
00345
00353 Triangle(int p1, int p2, int p3, int zone = 0)
00354 {
00355 p[0] = p1;
00356 p[1] = p2;
00357 p[2] = p3;
00358 z = zone;
00359 }
00360
00367 double X(int i, const std::vector < MeshPoint > & ps) const
00368 {
00369 return ps[p[i]].x(z);
00370 }
00371
00378 double Y(int i, const std::vector < MeshPoint > & ps) const
00379 {
00380 return ps[p[i]].y(z);
00381 }
00382
00387 void prepare(const std::vector < MeshPoint > & ps)
00388 {
00389 std::vector < Polynom > & r = phik;
00390 r.reserve(3);
00391
00392
00393 r.push_back((P2X - X(1, ps)) * (Y(2, ps) - Y(1, ps))
00394 - (P2Y - Y(1, ps)) * (X(2, ps) - X(1, ps)));
00395
00396 r.push_back((P2X - X(0, ps)) * (Y(2, ps) - Y(0, ps))
00397 - (P2Y - Y(0, ps)) * (X(2, ps) - X(0, ps)));
00398
00399 r.push_back((P2X - X(0, ps)) * (Y(1, ps) - Y(0, ps))
00400 - (P2Y - Y(0, ps)) * (X(1, ps) - X(0, ps)));
00401
00402 for (uint i = 0; i < 3; ++i)
00403 {
00404 r[i] /= r[i].apply(X(i, ps), Y(i, ps));
00405 }
00406
00407 x[0] = X(0, ps); y[0] = Y(0, ps);
00408 x[1] = X(1, ps); y[1] = Y(1, ps);
00409 x[2] = X(2, ps); y[2] = Y(2, ps);
00410 }
00411
00416 const std::vector < Polynom > & elem1() const
00417 {
00418 return phik;
00419 }
00420
00426 const Polynom & elem1(int p1) const
00427 {
00428 if (p1 == p[0]) {
00429 return phik[0];
00430 } else if (p1 == p[1]) {
00431 return phik[1];
00432 } else {
00433 return phik[2];
00434 }
00435 }
00436 };
00437
00441 struct Mesh {
00442 typedef std::vector < Triangle > triangles_t;
00443 typedef std::vector < MeshPoint > points_t;
00444 typedef std::vector < int > points_flags_t;
00445
00446 triangles_t tr;
00447 points_t ps;
00448
00454 points_flags_t ps_flags;
00455
00459 std::vector < std::vector < int > > adj;
00463 std::vector < int > inner;
00467 std::vector < int > outer;
00471 std::vector < int > p2io;
00472
00478 bool load(FILE * f);
00479
00483 void prepare();
00484
00488 void info();
00489 };
00490
00492
00502 typedef double (* x_t)(double u, double v);
00503
00514 void print_function(FILE * to, double * ans, const Mesh & m,
00515 x_t x = 0, x_t y = 0, x_t z = 0);
00516
00527 void print_function(const char * fname, double * ans, const Mesh & m,
00528 x_t x = 0, x_t y = 0, x_t z = 0);
00529
00540 void print_inner_function(FILE * to, double * ans, const Mesh & m,
00541 x_t x = 0, x_t y = 0, x_t z = 0);
00542
00553 void print_inner_function(const char * to, double * ans, const Mesh & m,
00554 x_t x = 0, x_t y = 0, x_t z = 0);
00555
00557
00576 double generic_scalar_cb(const Polynom & phi_i, const Polynom & phi_j,
00577 const Triangle & trk, const Mesh & m, int i1, int j1,
00578 int i2, int j2, void * user_data);
00579
00592 double sphere_scalar_cb(const Polynom & phi_i, const Polynom & phi_j,
00593 const Triangle & trk, const Mesh & m,
00594 int i1, int j1, int i2, int j2, void * user_data);
00595
00596 class Matrix;
00597
00607 double fast_scalar(const double * u, const double * v,
00608 const Mesh & m, Matrix & mat);
00609
00618 double fast_norm(const double * u, const Mesh & m, Matrix & mat);
00619
00629 double fast_dist(const double * u, const double * v,
00630 const Mesh & m, Matrix & mat);
00631
00633
00646 typedef double (* f_xy_t)(double x, double y);
00647
00655 typedef double (* f_xyt_t)(double x, double y, double t);
00656
00664 void p2u(double * u, const double * p, const double * bnd, const Mesh & m);
00665
00672 void u2p(double * p, const double * u, const Mesh & m);
00673
00680 void proj(double * F, const Mesh & mesh, f_xy_t f);
00681
00688 void proj_bnd(double * F, const Mesh & m, f_xy_t f);
00689
00696 void proj_bnd(double * F, const double * F1, const Mesh & m);
00697
00704 void set_bnd(double * F, const double * bnd, const Mesh & m);
00705
00713 void proj(double * F, const Mesh & mesh, f_xyt_t f, double t);
00714
00722 void proj_bnd(double * F, const Mesh & m, f_xyt_t f, double t);
00723
00725
00726 }
00727
00728 #include "phelm_generators.h"
00729
00730 #endif
00731