1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923
|
// This file is part of ff3d - http://www.freefem.org/ff3d
// Copyright (C) 2001, 2002, 2003 Stphane Del Pino
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2, or (at your option)
// any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// $Id: UserFunction.hpp,v 1.7 2005/04/20 22:35:43 delpinux Exp $
#ifndef USER_FUNCTION_HPP
#define USER_FUNCTION_HPP
#include <string>
#include <vector>
#include <cmath>
#include <StreamCenter.hpp>
#include <TinyVector.hpp>
#include <ReferenceCounting.hpp>
#include <Vector.hpp>
#include <ErrorHandler.hpp>
class Mesh;
class Structured3DMesh;
/*!
\class UserFunction
This class is the base class for \em user \em functions definition.
\author Stphane Del Pino
*/
class UserFunction
{
protected:
//! Allows the definition of basic functions such as \f$ x, y\f$ or \f$ z\f$.
real_t (*f)(const real_t x, const real_t y, const real_t z);
public:
//! operator= : allow affectation of a C function.
const UserFunction& operator = (real_t(*func)(const real_t x,
const real_t y,
const real_t z))
{
f = func;
return *this;
}
/*! Unary minus for UserFunctions
\todo Make this function virtual.
*/
UserFunction operator- () const;
//! operator= : allow affectation of a UserFunction.
const UserFunction& operator = (const UserFunction& F)
{
f = F.f;
return *this;
}
//! Ealuates the function at position (\a x0, \a x1, \a x2).
inline real_t operator()(const real_t& x0,
const real_t& x1,
const real_t& x2) const
{
return this->operator()(TinyVector<3, real_t>(x0, x1, x2));
}
//! operator() : evaluate a UserFunction at position \a X.
virtual real_t operator()(const TinyVector<3>& X) const
{
return f(X[0],X[1],X[2]);
}
//! The default constructor does nothing (used for inheritence).
UserFunction()
{
;
}
//! Constructs a UserFunction using a C function.
UserFunction(real_t(*func)(const real_t x, const real_t y, const real_t z))
: f(func)
{
;
}
//! Copy Constructor.
UserFunction(const UserFunction& F)
: f(F.f)
{
;
}
//! Destructor.
virtual ~UserFunction()
{
;
}
};
class UnaryMinusUserFunction
: public UserFunction
{
private:
ConstReferenceCounting<UserFunction> __u;
public:
real_t operator()(const TinyVector<3>& X) const
{
return (-(*__u)(X));
}
UnaryMinusUserFunction(const UnaryMinusUserFunction& U)
: __u(U.__u)
{
;
}
UnaryMinusUserFunction(ConstReferenceCounting<UserFunction> U)
: __u(U)
{
;
}
~UnaryMinusUserFunction()
{
;
}
};
/*!
\class UserFunctionLanguage
\author Stphane Del Pino
*/
class FunctionExpression;
class UserFunctionLanguage
: public UserFunction
{
private:
ReferenceCounting<FunctionExpression> __function;
public:
FunctionExpression& functionExpression()
{
return *__function;
}
void gradient(TinyVector<3>& gradient,
const TinyVector<3>& X) const;
real_t operator()(const TinyVector<3>& X) const;
UserFunctionLanguage(UserFunctionLanguage& U);
UserFunctionLanguage(ReferenceCounting<FunctionExpression>);
~UserFunctionLanguage();
};
/*!
\class ConstUserFunction
This class allows to define \em contant functions.
\author Stphane Del Pino
*/
class ConstUserFunction
: public UserFunction
{
private:
//! The constant value.
const real_t d;
public:
//! operator() : evaluate a ConstUserFunction at position \a X.
real_t operator()(const TinyVector<3>& X) const
{
return d;
}
//! Constructs the ConstUserFunction using the value \a val.
ConstUserFunction(const real_t& val)
: d(val)
{
;
}
//! Destructor.
~ConstUserFunction()
{
;
}
};
/*!
\class AddUserFunction
This class allows to define \em sum of UserFunction.
\author Stphane Del Pino
*/
class AddUserFunction
: public UserFunction
{
private:
//! The first function of the sum.
ConstReferenceCounting<UserFunction> F;
//! The second function of the sum.
ConstReferenceCounting<UserFunction> G;
public:
//! operator(): Evaluate the function sum at position \a X.
real_t operator()(const TinyVector<3>& X) const
{
return (*F)(X) + (*G)(X);
}
//! Constructs the AddUserFunction using 2 UserFunction pointers.
AddUserFunction(const UserFunction* F1,
const UserFunction* F2)
: F(F1),
G(F2)
{
;
}
//! Destructor
~AddUserFunction()
{
;
}
};
/*!
\class SubUserFunction
This class allows to define \em difference of UserFunction.
\author Stphane Del Pino
*/
class SubUserFunction
: public UserFunction
{
private:
//! The first UserFunction of the difference.
ConstReferenceCounting<UserFunction> F;
//! The second UserFunction of the difference.
ConstReferenceCounting<UserFunction> G;
public:
//! operator(): Evaluate the difference of \a F and \a G at position \a X.
real_t operator()(const TinyVector<3>& X) const
{
return (*F)(X)-(*G)(X);
}
//! Constructs the SubUserFunction using 2 UserFunction pointers.
SubUserFunction(const UserFunction* F1,
const UserFunction* F2)
: F(F1),
G(F2)
{
;
}
//! Destructor.
~SubUserFunction()
{
;
}
};
/*!
\class MulUserFunction
This class allows to define \em multiplication of UserFunction.
\author Stphane Del Pino
*/
class MulUserFunction
: public UserFunction
{
private:
//! The first UserFunction of the multiplication.
ConstReferenceCounting<UserFunction> F;
//! The second UserFunction of the multiplication.
ConstReferenceCounting<UserFunction> G;
public:
//! Evaluation of \a F \a G at \a X.
real_t operator()(const TinyVector<3>& X) const {
return (*F)(X) * (*G)(X);
}
//! Constructs the MulUserFunction using 2 UserFunction pointers.
MulUserFunction(const UserFunction* F1,
const UserFunction* F2)
: F(F1),
G(F2)
{
;
}
//! Destructor.
~MulUserFunction()
{
;
}
};
/*!
\class DivUserFunction
This class allows to define \em division of UserFunction.
\author Stphane Del Pino
*/
class DivUserFunction
: public UserFunction
{
private:
//! The first UserFunction of the division.
ConstReferenceCounting<UserFunction> F;
//! The second UserFunction of the division.
ConstReferenceCounting<UserFunction> G;
public:
//! Evaluation of \f$ \frac{F}{G} \f$ at \a X.
real_t operator()(const TinyVector<3>& X) const
{
return (*F)(X)/(*G)(X);
}
//! Constructs the DivUserFunction using 2 UserFunction pointers.
DivUserFunction(const UserFunction* F1,
const UserFunction* F2)
: F(F1),
G(F2)
{
;
}
//! Destructor
~DivUserFunction()
{
;
}
};
/*!
\class CompUserFunction
This class allows to define the \em composition of a UserFunction by a C function.
\author Stphane Del Pino
*/
class CompUserFunction
: public UserFunction
{
private:
//! The C function.
real_t (*F)(const real_t x);
//! The UserFunction
ConstReferenceCounting<UserFunction> G;
public:
//! Evaluates \f$ F\circ G \f$ at \a X.
real_t operator()(const TinyVector<3>& X) const
{
return (*F)((*G)(X));
}
//! Constructs the CompUserFunction using a C function and a UserFunction.
CompUserFunction(real_t(*func1)(const real_t x),
const UserFunction* UG)
: F(func1),
G(UG)
{
;
}
//! Destructor.
~CompUserFunction()
{
;
}
};
/*!
\class PowerUserFunction
This class allows to define a function of the form \f$ f^g \f$.
It is the user responsability to check that it is well defined.
\author Stphane Del Pino
*/
class PowerUserFunction
: public UserFunction
{
private:
//! The first function.
ConstReferenceCounting<UserFunction> F;
//! The second function.
ConstReferenceCounting<UserFunction> G;
public:
//! Evaluation of \f$ F^G \f$ at point \a X.
real_t operator()(const TinyVector<3>& X) const
{
return std::pow((*F)(X),(*G)(X));
}
/*!
Constructs a PowerUserFunction using 2 UserFunction
\par example: \f$ x^y \f$
*/
PowerUserFunction(const UserFunction* UF,
const UserFunction* UG)
: F(UF),
G(UG)
{
;
}
//! Destructor.
~PowerUserFunction()
{
;
}
};
// Comparison functions
/*!
\class OneGTUserFunction
This class allows to define the \em characteristic function
of the set defined by \f$ f>g \f$
\author Stphane Del Pino
*/
class OneGTUserFunction
: public UserFunction
{
private:
//! The first UserFunction
ConstReferenceCounting<UserFunction> f;
//! The second UserFunction
ConstReferenceCounting<UserFunction> g;
public:
//! Evaluates \f$ 1_{f>g} \f$ at point \a X.
real_t operator()(const TinyVector<3>& X) const
{
return (real_t)((*f)(X)>(*g)(X));
}
//! Constructs a OneGTUserFunction using 2 UserFunction.
OneGTUserFunction(const UserFunction* UF, const UserFunction* UG)
: f(UF),
g(UG)
{
;
}
//! Destructor.
~OneGTUserFunction()
{
;
}
};
/*!
\class OneGEUserFunction
This class allows to define the \em characteristic function
of the set defined by \f$ f\geq g \f$
\author Stphane Del Pino
*/
class OneGEUserFunction
: public UserFunction
{
private:
//! the first UserFunction
ConstReferenceCounting<UserFunction> f;
//! the second UserFunction
ConstReferenceCounting<UserFunction> g;
public:
//! Evaluates \f$ 1_{f\geq g} \f$ at point \a X.
real_t operator()(const TinyVector<3>& X) const
{
return (real_t)((*f)(X)>=(*g)(X));
}
//! Constructs a OneGEUserFunction using 2 UserFunction.
OneGEUserFunction(const UserFunction* UF, const UserFunction* UG)
: f(UF),
g(UG)
{
;
}
//! Destructor.
~OneGEUserFunction()
{
;
}
};
/*!
\class OneLTUserFunction
This class allows to define the \em characteristic function
of the set defined by \f$ f < g \f$
\author Stphane Del Pino
*/
class OneLTUserFunction
: public UserFunction
{
private:
//! the first UserFunction
ConstReferenceCounting<UserFunction> f;
//! the second UserFunction
ConstReferenceCounting<UserFunction> g;
public:
//! Evaluates \f$ 1_{f < g} \f$ at point \a X.
real_t operator()(const TinyVector<3>& X) const {
return (real_t)((*f)(X)<(*g)(X));
}
//! Constructs OneLTUserFunction using 2 UserFunction.
OneLTUserFunction(const UserFunction* UF, const UserFunction* UG)
: f(UF),
g(UG)
{
;
}
//! Destructor
~OneLTUserFunction()
{
;
}
};
/*!
\class OneLEUserFunction
This class allows to define the \em characteristic function
of the set defined by \f$ f \leq g \f$
\author Stphane Del Pino
*/
class OneLEUserFunction
: public UserFunction
{
private:
//! the first UserFunction
ConstReferenceCounting<UserFunction> f;
//! the second UserFunction
ConstReferenceCounting<UserFunction> g;
public:
//! Evaluates \f$ 1_{f \leq g} \f$ at point \a X.
real_t operator() (const TinyVector<3>& X) const
{
return (real_t)((*f)(X)<=(*g)(X));
}
//! Constructs a OneLEUserFunction using 2 UserFunction
OneLEUserFunction(const UserFunction* UF, const UserFunction* UG)
: f(UF),
g(UG)
{
;
}
//! Destructor.
~OneLEUserFunction() {}
};
/*!
\class OneEQUserFunction
This class allows to define the \em characteristic function
of the set defined by \f$ f = g \f$
\author Stphane Del Pino
*/
class OneEQUserFunction
: public UserFunction
{
private:
//! the first UserFunction
ConstReferenceCounting<UserFunction> f;
//! the second UserFunction
ConstReferenceCounting<UserFunction> g;
public:
//! Evaluates \f$ 1_{f = g} \f$ at point \a X.
real_t operator() (const TinyVector<3>& X) const
{
return (real_t)(std::abs((*f)(X)-(*g)(X))<1E-6);
}
//! Constructs a OneEQUserFunction using 2 UserFunction.
OneEQUserFunction(const UserFunction* UF, const UserFunction* UG)
: f(UF),
g(UG)
{
;
}
//! Destructor.
~OneEQUserFunction()
{
;
}
};
/*!
\class OneNEUserFunction
This class allows to define the \em characteristic function
of the set defined by \f$ f \neq g \f$
\author Stphane Del Pino
*/
class OneNEUserFunction
: public UserFunction
{
private:
//! the first UserFunction
ConstReferenceCounting<UserFunction> f;
//! the second UserFunction
ConstReferenceCounting<UserFunction> g;
public:
//! Evaluates \f$ 1_{f \neq g} \f$ at point \a X.
real_t operator() (const TinyVector<3>& X) const
{
return (real_t)(std::abs((*f)(X)-(*g)(X))>=1E-6);
}
//! Constructs a OneNEUserFunction using 2 UserFunction.
OneNEUserFunction(const UserFunction* UF, const UserFunction* UG)
: f(UF),
g(UG)
{
;
}
//! Destructor.
~OneNEUserFunction()
{
;
}
};
/*!
\class OneANDUserFunction
Allows to define the boolean operation \p and for characteristic function.
here return 1 if \f$X \in {x, f(x)=1} \cap \{x, g(x)=1\} \f$, else returns 0.
\bug Should be called only for Boolean UserFunction (characteristic functions)
\author Stphane Del Pino
*/
class OneANDUserFunction
: public UserFunction
{
private:
//! the first UserFunction
ConstReferenceCounting<UserFunction> f;
//! the second UserFunction
ConstReferenceCounting<UserFunction> g;
public:
//! Evaluates \f$ \{x, f(x)=1\} \cap \{x, g(x)=1\} \f$ at point \a X.
real_t operator() (const TinyVector<3>& X) const
{
return (*f)(X)*(*g)(X);
}
//! Constructs OneANDUserFunction using 2 UserFunction.
OneANDUserFunction(const UserFunction* UF, const UserFunction* UG)
: f(UF),
g(UG)
{
;
}
// Destructor.
~OneANDUserFunction()
{
;
}
};
/*!
\class OneORUserFunction
Allows to define the boolean operation \p and for characteristic function.
here return 1 if \f$X \in {x, f(x)=1} \cup \{x, g(x)=1\} \f$, else returns 0.
\bug Should be called only for Boolean UserFunction (characteristic functions)
\author Stphane Del Pino
*/
class OneORUserFunction
: public UserFunction
{
private:
//! the first UserFunction
ConstReferenceCounting<UserFunction> f;
//! the second UserFunction
ConstReferenceCounting<UserFunction> g;
public:
//! Evaluates \f$ {x, f(x)=1} \cup \{x, g(x)=1\} \f$ at point \a X.
real_t operator() (const TinyVector<3>& X) const
{
const real_t fxyz = (*f)(X);
const real_t gxyz = (*g)(X);
return fxyz+gxyz - fxyz*gxyz; // has f and g values are 1 or 0
// result will be 1 or 0 !
}
//! Constructs OneORUserFunction using 2 UserFunction.
OneORUserFunction(const UserFunction* UF, const UserFunction* UG)
: f(UF),
g(UG)
{
;
}
//! Destructor.
~OneORUserFunction()
{
;
}
};
class FEM0UserFunction
: public UserFunction
{
private:
//! The Mesh on which lives the function.
ReferenceCounting<Mesh> __mesh;
//! The vector of cell values.
Vector<real_t>__values;
public:
//! Evaluates the FEM0UserFunction at point \a X.
real_t operator()(const TinyVector<3>& V) const;
//! Access to the value at the ith vertex of the mesh \a M.
inline real_t& operator[](const size_t& i)
{
return __values[i];
}
//! Read only Access to the value at the ith cell of the mesh \a M.
inline const real_t& operator[](const size_t& i) const
{
return __values[i];
}
//! Affects a \a Vector to the FEM0UserFunction.
void operator=(Vector<real_t>& u);
//! Read-only access to the mesh pointed by \a M.
const Mesh& mesh() const
{
return (*__mesh);
}
//! Constructs a FEM0UserFunction using a pointer on a Mesh and a UserFunction
FEM0UserFunction(ReferenceCounting<Mesh> pmesh, const UserFunction& F);
//! Constructs a FEMUserFunction using a pointer on a Mesh and a real_t
FEM0UserFunction(ReferenceCounting<Mesh> pmesh, const real_t d);
/*!
Constructs a FEMUserFunction using a pointer on a Mesh and a Vector of data.
\warning Will have to change this for the vectorial case.
*/
FEM0UserFunction(ReferenceCounting<Mesh> pmesh, const Vector<real_t>& F);
//! Copy Constructor.
FEM0UserFunction(const FEM0UserFunction& F);
//! Destructor.
~FEM0UserFunction();
};
class Scene;
class Object;
/*!
\class OneUserFunction
This class implemented characteristic function of Objects for a given reference:
\f$ 1_{\cup_i o_i} \f$.
\author Stphane Del Pino
*/
class OneUserFunction
: public UserFunction
{
private:
//! The list of objects for which
std::vector<Object*> o;
public:
//! Evalutes \f$ 1_{\cup_i o_i} \f$ at point \a X.
real_t operator()(const TinyVector<3>& X) const;
//! Constructs a OneUserFunction using the POV-Ray reference \a r.
OneUserFunction(TinyVector<3>& r);
//! Destructor
~OneUserFunction()
{
;
}
};
/*!
\class OneMeshUserFunction
Used to define the characteristic function of a Structured3DMesh.
\author Stphane Del Pino
*/
class OneMeshUserFunction
: public UserFunction
{
private:
//! The Structured3DMesh \a mesh.
ConstReferenceCounting<Structured3DMesh> __mesh;
public:
//! Evalutes the characteristic function of the \a mesh at point \a X
real_t operator()(const TinyVector<3>& X) const;
//! Constructs a OneMeshUserFunction using a \a mesh.
OneMeshUserFunction(ConstReferenceCounting<Structured3DMesh> mesh);
//! Destructor.
~OneMeshUserFunction();
};
/**
* @class OneDomainUserFunction
* @author Stephane Del Pino
* @date Sun Sep 21 15:05:18 2003
*
* @brief return 1 if argument vertex is in the domain 0 if not.
*
*
*/
class Domain;
class OneDomainUserFunction
: public UserFunction
{
private:
ConstReferenceCounting<Domain> __domain; /**< The domain */
public:
/**
*
* Returns 1 if \a x is inside the domain, else 0.
*
* @return 1 or 0
*/
real_t operator()(const TinyVector<3>& x) const;
/**
* Constructor
*
* @param domain the given domain
*
*/
OneDomainUserFunction(ConstReferenceCounting<Domain> domain);
/**
* Destructor
*/
~OneDomainUserFunction();
};
namespace UF {
static ConstUserFunction zero(0);
}
#endif // USER_FUNCTION_HPP
|