20 #include "headcpp.hpp"
22 #include "utilities.hpp"
23 #include "spheric.hpp"
25 #include "val_domain.hpp"
28 void coef_1d (
int, Array<double>&) ;
29 void coef_i_1d (
int, Array<double>&) ;
30 int der_1d (
int, Array<double>&) ;
34 Domain(num, ttype, nbr), alpha(r),center(cr) {
45 fread_be (&
alpha,
sizeof(
double), 1, fd) ;
50 Domain_nucleus::~Domain_nucleus() {}
55 fwrite_be (&
ndim,
sizeof(
int), 1, fd) ;
56 fwrite_be (&
type_base,
sizeof(
int), 1, fd) ;
58 fwrite_be (&
alpha,
sizeof(
double), 1, fd) ;
62 o <<
"Nucleus" << endl ;
63 o <<
"Rmax = " <<
alpha << endl ;
64 o <<
"Center = " <<
center << endl ;
79 cerr <<
"Unknown boundary case in Domain_nucleus::der_normal" << endl ;
87 for (
int i=0 ; i<3 ; i++)
88 assert (
coloc[i] != 0x0) ;
89 for (
int i=0 ; i<3 ; i++)
90 assert (
absol[i] == 0x0) ;
91 for (
int i=0 ; i<3 ; i++) {
93 absol[i]->allocate_conf() ;
103 while (index.
inc()) ;
110 for (
int i=0 ; i<3 ; i++)
111 assert (
coloc[i] != 0x0) ;
118 while (index.
inc()) ;
123 for (
int i=0 ; i<3 ; i++)
124 assert (
coloc[i] != 0x0) ;
125 for (
int i=0 ; i<3 ; i++)
126 assert (
cart[i] == 0x0) ;
127 for (
int i=0 ; i<3 ; i++) {
129 cart[i]->allocate_conf() ;
139 while (index.
inc()) ;
144 for (
int i=0 ; i<3 ; i++)
145 assert (
coloc[i] != 0x0) ;
146 for (
int i=0 ; i<3 ; i++)
148 for (
int i=0 ; i<3 ; i++) {
158 while (index.
inc()) ;
166 double x_loc = xx(1) -
center(1) ;
167 double y_loc = xx(2) -
center(2) ;
168 double z_loc = xx(3) -
center(3) ;
169 double air_loc = sqrt (x_loc*x_loc + y_loc*y_loc + z_loc*z_loc) ;
171 bool res = (air_loc/
alpha -1 <= prec) ?
true :
false ;
179 assert (
is_in(abs)) ;
182 double x_loc = abs(1) -
center(1) ;
183 double y_loc = abs(2) -
center(2) ;
184 double z_loc = abs(3) -
center(3) ;
185 double air = sqrt(x_loc*x_loc+y_loc*y_loc+z_loc*z_loc) ;
187 double rho = sqrt(x_loc*x_loc+y_loc*y_loc) ;
191 num.
set(2) = (z_loc>=0) ? 0 : M_PI ;
195 num.
set(2) = atan(rho/z_loc) ;
196 num.
set(3) = atan2 (y_loc, x_loc) ;
200 num.
set(2) = M_PI + num(2) ;
209 assert (bound==OUTER_BC) ;
210 assert (
is_in(abs, 1e-3)) ;
213 double x_loc = abs(1) -
center(1) ;
214 double y_loc = abs(2) -
center(2) ;
215 double z_loc = abs(3) -
center(3) ;
217 double rho = sqrt(x_loc*x_loc+y_loc*y_loc) ;
221 num.
set(2) = (z_loc>=0) ? 0 : M_PI ;
225 num.
set(2) = atan(rho/z_loc) ;
226 num.
set(3) = atan2 (y_loc, x_loc) ;
230 num.
set(2) = M_PI + num(2) ;
235 double coloc_leg_parity(
int,
int) ;
243 for (
int i=0 ; i<
ndim ; i++)
256 for (
int i=0 ; i<
ndim ; i++)
266 cerr <<
"Unknown type of basis in Domain_nucleus::do_coloc" << endl ;
284 m = (k%2==0) ? k/2 : (k-1)/2 ;
285 base.
bases_1d[1]->set(k) = (m%2==0) ? COS_EVEN : SIN_ODD ;
287 l = (m%2==0) ? 2*j : 2*j+1 ;
288 index.
set(0) = j ; index.
set(1) = k ;
289 base.
bases_1d[0]->set(index) = (l%2==0) ? CHEB_EVEN : CHEB_ODD ;
308 m = (k%2==0) ? k/2 : (k-1)/2 ;
309 base.
bases_1d[1]->set(k) = (m%2==0) ? COS_EVEN : SIN_ODD ;
311 l = (m%2==0) ? 2*j : 2*j+1 ;
312 index.
set(0) = j ; index.
set(1) = k ;
313 base.
bases_1d[0]->set(index) = (l%2==0) ? CHEB_EVEN : CHEB_ODD ;
321 m = (k%2==0) ? k/2 : (k-1)/2 ;
322 base.
bases_1d[1]->set(k) = (m%2==0) ? SIN_ODD : COS_EVEN ;
324 l = (m%2==0) ? 2*j : 2*j+1 ;
325 index.
set(0) = j ; index.
set(1) = k ;
326 base.
bases_1d[0]->set(index) = (l%2==0) ? CHEB_ODD : CHEB_EVEN ;
345 m = (k%2==0) ? k/2 : (k-1)/2 ;
346 base.
bases_1d[1]->set(k) = (m%2==0) ? COS_ODD : SIN_EVEN ;
348 l = (m%2==0) ? 2*j+1 : 2*j ;
349 index.
set(0) = j ; index.
set(1) = k ;
350 base.
bases_1d[0]->set(index) = (l%2==1) ? CHEB_ODD : CHEB_EVEN ;
367 m = (k%2==0) ? k/2 : (k-1)/2 ;
368 base.
bases_1d[1]->set(k) = (m%2==0) ? COS_EVEN : SIN_ODD ;
370 index.
set(0) = j ; index.
set(1) = k ;
371 base.
bases_1d[0]->set(index) = (m%2==0) ? CHEB_ODD : CHEB_EVEN ;
388 m = (k%2==0) ? k/2 : (k-1)/2 ;
389 base.
bases_1d[1]->set(k) = (m%2==0) ? SIN_ODD : COS_EVEN ;
391 index.
set(0) = j ; index.
set(1) = k ;
392 base.
bases_1d[0]->set(index) = (m%2==0) ? CHEB_ODD : CHEB_EVEN ;
409 m = (k%2==0) ? k/2 : (k-1)/2 ;
410 base.
bases_1d[1]->set(k) = (m%2==0) ? SIN_EVEN : COS_ODD;
412 index.
set(0) = j ; index.
set(1) = k ;
413 base.
bases_1d[0]->set(index) = (m%2==0) ? CHEB_ODD : CHEB_EVEN ;
431 m = (k%2==0) ? k/2 : (k-1)/2 ;
432 base.
bases_1d[1]->set(k) = (m%2==0) ? COS_EVEN : SIN_ODD ;
434 index.
set(0) = j ; index.
set(1) = k ;
435 base.
bases_1d[0]->set(index) = (m%2==0) ? CHEB_ODD : CHEB_EVEN ;
452 m = (k%2==0) ? k/2 : (k-1)/2 ;
453 base.
bases_1d[1]->set(k) = (m%2==0) ? SIN_EVEN : COS_ODD ;
455 index.
set(0) = j ; index.
set(1) = k ;
456 base.
bases_1d[0]->set(index) = (m%2==0) ? CHEB_ODD : CHEB_EVEN ;
473 m = (k%2==0) ? k/2 : (k-1)/2 ;
474 base.
bases_1d[1]->set(k) = (m%2==0) ? SIN_ODD : COS_EVEN;
476 index.
set(0) = j ; index.
set(1) = k ;
477 base.
bases_1d[0]->set(index) = (m%2==0) ? CHEB_ODD : CHEB_EVEN ;
494 m = (k%2==0) ? k/2 : (k-1)/2 ;
495 base.
bases_1d[1]->set(k) = (m%2==0) ? COS_EVEN : SIN_ODD ;
497 l = (m%2==0) ? 2*j : 2*j+1 ;
498 index.
set(0) = j ; index.
set(1) = k ;
499 base.
bases_1d[0]->set(index) = (l%2==0) ? CHEB_ODD : CHEB_EVEN ;
517 m = (k%2==0) ? k/2 : (k-1)/2 ;
518 base.
bases_1d[1]->set(k) = (m%2==0) ? COS_EVEN : SIN_ODD ;
520 l = (m%2==0) ? 2*j : 2*j+1 ;
521 index.
set(0) = j ; index.
set(1) = k ;
522 base.
bases_1d[0]->set(index) = (l%2==0) ? LEG_ODD : LEG_EVEN ;
540 m = (k%2==0) ? k/2 : (k-1)/2 ;
541 base.
bases_1d[1]->set(k) = (m%2==0) ? COS_EVEN : SIN_ODD ;
543 l = (m%2==0) ? 2*j : 2*j+1 ;
544 index.
set(0) = j ; index.
set(1) = k ;
545 base.
bases_1d[0]->set(index) = (l%2==0) ? LEG_EVEN : LEG_ODD ;
563 m = (k%2==0) ? k/2 : (k-1)/2 ;
564 base.
bases_1d[1]->set(k) = (m%2==0) ? COS_ODD : SIN_EVEN ;
566 l = (m%2==0) ? 2*j+1 : 2*j ;
567 index.
set(0) = j ; index.
set(1) = k ;
568 base.
bases_1d[0]->set(index) = (l%2==1) ? LEG_ODD : LEG_EVEN ;
585 m = (k%2==0) ? k/2 : (k-1)/2 ;
586 base.
bases_1d[1]->set(k) = (m%2==0) ? COS_EVEN : SIN_ODD ;
588 l = (m%2==0) ? 2*j : 2*j+1 ;
589 index.
set(0) = j ; index.
set(1) = k ;
590 base.
bases_1d[0]->set(index) = (l%2==0) ? LEG_ODD : LEG_EVEN ;
607 m = (k%2==0) ? k/2 : (k-1)/2 ;
608 base.
bases_1d[1]->set(k) = (m%2==0) ? SIN_EVEN : COS_ODD ;
610 l = (m%2==0) ? 2*j : 2*j+1 ;
611 index.
set(0) = j ; index.
set(1) = k ;
612 base.
bases_1d[0]->set(index) = (l%2==0) ? LEG_ODD : LEG_EVEN ;
629 m = (k%2==0) ? k/2 : (k-1)/2 ;
630 base.
bases_1d[1]->set(k) = (m%2==0) ? SIN_ODD : COS_EVEN;
632 l = (m%2==0) ? 2*j : 2*j+1 ;
633 index.
set(0) = j ; index.
set(1) = k ;
634 base.
bases_1d[0]->set(index) = (l%2==0) ? LEG_ODD : LEG_EVEN ;
651 m = (k%2==0) ? k/2 : (k-1)/2 ;
652 base.
bases_1d[1]->set(k) = (m%2==0) ? COS_EVEN : SIN_ODD ;
654 l = (m%2==0) ? 2*j : 2*j+1 ;
655 index.
set(0) = j ; index.
set(1) = k ;
656 base.
bases_1d[0]->set(index) = (l%2==0) ? LEG_ODD : LEG_EVEN ;
673 m = (k%2==0) ? k/2 : (k-1)/2 ;
674 base.
bases_1d[1]->set(k) = (m%2==0) ? SIN_ODD : COS_EVEN ;
676 l = (m%2==0) ? 2*j : 2*j+1 ;
677 index.
set(0) = j ; index.
set(1) = k ;
678 base.
bases_1d[0]->set(index) = (l%2==0) ? LEG_ODD : LEG_EVEN ;
695 m = (k%2==0) ? k/2 : (k-1)/2 ;
696 base.
bases_1d[1]->set(k) = (m%2==0) ? SIN_EVEN : COS_ODD;
698 l = (m%2==0) ? 2*j : 2*j+1 ;
699 index.
set(0) = j ; index.
set(1) = k ;
700 base.
bases_1d[0]->set(index) = (l%2==0) ? LEG_ODD : LEG_EVEN ;
730 bool res_def = true ;
762 switch ((*a.
bases_1d[1])(index_1)) {
764 switch ((*b.
bases_1d[1])(index_1)) {
766 res.
bases_1d[1]->set(index_1) = (index_1(0)%4<2) ? COS_EVEN : SIN_ODD ;
769 res.
bases_1d[1]->set(index_1) = (index_1(0)%4<2) ? COS_ODD : SIN_EVEN ;
772 res.
bases_1d[1]->set(index_1) = (index_1(0)%4<2) ? SIN_EVEN : COS_ODD ;
775 res.
bases_1d[1]->set(index_1) = (index_1(0)%4<2) ? SIN_ODD : COS_EVEN ;
783 switch ((*b.
bases_1d[1])(index_1)) {
785 res.
bases_1d[1]->set(index_1) = (index_1(0)%4<2) ? COS_ODD : SIN_EVEN ;
788 res.
bases_1d[1]->set(index_1) = (index_1(0)%4<2) ? COS_EVEN : SIN_ODD ;
791 res.
bases_1d[1]->set(index_1) = (index_1(0)%4<2) ? SIN_ODD : COS_EVEN ;
794 res.
bases_1d[1]->set(index_1) = (index_1(0)%4<2) ? SIN_EVEN : COS_ODD ;
802 switch ((*b.
bases_1d[1])(index_1)) {
804 res.
bases_1d[1]->set(index_1) = (index_1(0)%4<2) ? SIN_EVEN : COS_ODD ;
807 res.
bases_1d[1]->set(index_1) = (index_1(0)%4<2) ? SIN_ODD : COS_EVEN ;
810 res.
bases_1d[1]->set(index_1) = (index_1(0)%4<2) ? COS_EVEN : SIN_ODD ;
813 res.
bases_1d[1]->set(index_1) = (index_1(0)%4<2) ? COS_ODD : SIN_EVEN ;
821 switch ((*b.
bases_1d[1])(index_1)) {
823 res.
bases_1d[1]->set(index_1) = (index_1(0)%4<2) ? SIN_ODD : COS_EVEN ;
826 res.
bases_1d[1]->set(index_1) = (index_1(0)%4<2) ? SIN_EVEN : COS_ODD ;
829 res.
bases_1d[1]->set(index_1) = (index_1(0)%4<2) ? COS_ODD : SIN_EVEN ;
832 res.
bases_1d[1]->set(index_1) = (index_1(0)%4<2) ? COS_EVEN : SIN_ODD ;
844 while (index_1.
inc()) ;
851 switch ((*a.
bases_1d[0])(index_0)) {
853 switch ((*b.
bases_1d[0])(index_0)) {
855 res.
bases_1d[0]->set(index_0) = (index_0(1)%4<2) ? CHEB_EVEN : CHEB_ODD ;
858 res.
bases_1d[0]->set(index_0) = (index_0(1)%4<2) ? CHEB_ODD : CHEB_EVEN ;
866 switch ((*b.
bases_1d[0])(index_0)) {
868 res.
bases_1d[0]->set(index_0) = (index_0(1)%4<2) ? CHEB_ODD : CHEB_EVEN ;
871 res.
bases_1d[0]->set(index_0) = (index_0(1)%4<2) ? CHEB_EVEN : CHEB_ODD ;
879 switch ((*b.
bases_1d[0])(index_0)) {
881 res.
bases_1d[0]->set(index_0) = (index_0(1)%4<2) ? LEG_EVEN : LEG_ODD ;
884 res.
bases_1d[0]->set(index_0) = (index_0(1)%4<2) ? LEG_ODD : LEG_EVEN ;
892 switch ((*b.
bases_1d[0])(index_0)) {
894 res.
bases_1d[0]->set(index_0) = (index_0(1)%4<2) ? LEG_ODD : LEG_EVEN ;
897 res.
bases_1d[0]->set(index_0) = (index_0(1)%4<2) ? LEG_EVEN : LEG_ODD ;
909 while (index_0.
inc()) ;
912 for (
int dim=0 ; dim<a.
ndim ; dim++)
923 if (strcmp(p,
"R ")==0)
925 if (strcmp(p,
"T ")==0)
927 if (strcmp(p,
"P ")==0)
934 if (bound != OUTER_BC)
936 cerr <<
"Domain_nucleus::integ only defined for r=rmax yet..." << endl ;
940 int baset((*so.base.bases_1d[1])(0));
941 if (baset != COS_EVEN)
947 Index pos(get_nbr_coefs());
949 for (
int j(0) ; j < nbr_coefs(1) ; ++j)
952 double fact_tet(2.0/(1.0 - 4.0*j*j));
954 for (
int i(0) ; i < nbr_coefs(0) ; ++i)
957 res += fact_tet*(*so.cf)(pos);
Class for storing the basis of decompositions of a field.
Bases_container bases_1d
Arrays containing the various basis of decomposition.
void allocate(const Dim_array &nbr_coefs)
Allocates the various arrays, for a given number of coefficients.
bool def
true if the Base_spectral is defined and false otherwise.
int ndim
Number of dimensions.
Class for storing the dimensions of an array.
int get_ndim() const
Returns the number of dimensions.
int & set(int i)
Read/write of the size of a given dimension.
void save(FILE *) const
Save function.
Class for a spherical domain containing the origin and a symmetry with respect to the plane .
virtual void do_radius() const
Computes the generalized radius.
Point center
Absolute coordinates of the center.
virtual Val_domain der_normal(const Val_domain &, int) const
Normal derivative with respect to a given surface.
virtual bool is_in(const Point &xx, double prec=1e-13) const
Check whether a point lies inside Domain.
virtual void do_cart() const
Computes the Cartesian coordinates.
virtual void set_cheb_r_base(Base_spectral &) const
Gives the base using odd Chebyshev polynomials$ for the radius.
virtual Val_domain div_x(const Val_domain &) const
Division by .
virtual ostream & print(ostream &o) const
Delegate function to virtualize the << operator.
virtual void set_legendre_base_t_spher(Base_spectral &) const
Gives the base using Legendre polynomials, for the component of a vector.
virtual void set_legendre_base_p_spher(Base_spectral &) const
Gives the base using Legendre polynomials, for the component of a vector.
virtual double integ(const Val_domain &so, int bound) const
Surface integral on a given boundary.
virtual void set_legendre_base(Base_spectral &so) const
Sets the base to the standard one for Legendre polynomials.
virtual const Point absol_to_num_bound(const Point &, int) const
Computes the numerical coordinates from the physical ones for a point lying on a boundary.
virtual void do_cart_surr() const
Computes the Cartesian coordinates over the radius.
virtual void set_cheb_base_t_spher(Base_spectral &) const
Gives the base using Chebyshev polynomials, for the component of a vector.
virtual void set_anti_cheb_base(Base_spectral &so) const
Sets the base to the standard one for Chebyshev polynomials for functions antisymetric in The bases ...
virtual void set_cheb_base(Base_spectral &so) const
Sets the base to the standard one for Chebyshev polynomials.
virtual Base_spectral mult(const Base_spectral &, const Base_spectral &) const
Method for the multiplication of two Base_spectral.
virtual void set_legendre_base_t_mtz(Base_spectral &) const
Gives the base using Legendre polynomials, for the component of a vector in the MTZ context.
virtual void set_cheb_base_with_m(Base_spectral &so, int m) const
Gives the standard base using Chebyshev polynomials.
virtual void set_cheb_base_r_spher(Base_spectral &) const
Gives the base using Chebyshev polynomials, for the radial component of a vector.
virtual void set_legendre_base_r_spher(Base_spectral &) const
Gives the base using Legendre polynomials, for the radial component of a vector.
virtual Val_domain mult_sin_theta(const Val_domain &) const
Multiplication by .
virtual int give_place_var(char *) const
Translates a name of a coordinate into its corresponding numerical name.
Domain_nucleus(int num, int ttype, double radius, const Point &cr, const Dim_array &nbr)
Standard constructor :
virtual void save(FILE *) const
Saving function.
virtual void set_cheb_base_p_spher(Base_spectral &) const
Gives the base using Chebyshev polynomials, for the component of a vector.
virtual Val_domain mult_cos_theta(const Val_domain &) const
Multiplication by .
virtual void set_legendre_base_r_mtz(Base_spectral &) const
Gives the base using Legendre polynomials, for the radial component of a vector in the MTZ context.
virtual const Point absol_to_num(const Point &xxx) const
Computes the numerical coordinates from the physical ones.
virtual Val_domain mult_sin_phi(const Val_domain &) const
Multiplication by .
virtual void set_legendre_r_base(Base_spectral &) const
Gives the base using odd Legendre polynomials$ for the radius.
virtual void do_absol() const
Computes the absolute coordinates.
double alpha
Relates the numerical to the physical radii.
virtual void do_coloc()
Computes the colocation points.
virtual void set_cheb_base_t_mtz(Base_spectral &) const
Gives the base using Chebyshev polynomials, for the component of a vector in the MTZ setting.
virtual Val_domain mult_cos_phi(const Val_domain &) const
Multiplication by .
virtual void set_legendre_base_p_mtz(Base_spectral &) const
Gives the base using Legendre polynomials, for the component of a vector in the MTZ context.
virtual void do_der_abs_from_der_var(const Val_domain *const *const der_var, Val_domain **const der_abs) const
Computes the derivative with respect to the absolute Cartesian coordinates from the derivative with r...
virtual void set_cheb_base_p_mtz(Base_spectral &) const
Gives the base using Chebyshev polynomials, for the component of a vector in the MTZ setting.
virtual void set_cheb_base_r_mtz(Base_spectral &) const
Gives the base using Chebyshev polynomials, for the radial component of a vector in the MTZ setting.
virtual void set_anti_legendre_base(Base_spectral &so) const
Sets the base to the standard one for Legendre polynomials for functions antisymetric in The bases a...
Abstract class that implements the fonctionnalities common to all the type of domains.
virtual void del_deriv()
Destroys the derivated members (like coloc, cart and radius), when changing the type of colocation po...
Val_domain * radius
The generalized radius.
Memory_mapped_array< Val_domain * > cart
Cartesian coordinates.
Memory_mapped_array< Val_domain * > absol
Asbolute coordinates (if defined ; usually Cartesian-like)
int ndim
Number of dimensions.
Memory_mapped_array< Val_domain * > cart_surr
Cartesian coordinates divided by the radius.
Dim_array nbr_coefs
Number of coefficients.
Dim_array nbr_points
Number of colocation points.
int type_base
Type of colocation point :
Memory_mapped_array< Array< double > * > coloc
Colocation points in each dimension (stored in ndim 1d- arrays)
Class that gives the position inside a multi-dimensional Array.
int & set(int i)
Read/write of the position in a given dimension.
bool inc(int increm, int var=0)
Increments the position of the Index.
The class Point is used to store the coordinates of a point.
void save(FILE *) const
Saving function.
const int & get_ndim() const
Returns the number of dimensions.
double & set(int i)
Read/write of a coordinate.
Class for storing the basis of decompositions of a field and its values on both the configuration and...
Val_domain mult_sin_phi() const
Multiplication by .
Val_domain mult_sin_theta() const
Multiplication by .
Val_domain mult_cos_phi() const
Multiplication by .
double & set(const Index &pos)
Read/write the value of the field in the configuration space.
Val_domain div_sin_theta() const
Division by .
Val_domain mult_cos_theta() const
Multiplication by .
Val_domain der_var(int i) const
Computes the derivative with respect to a numerical coordinate.
void allocate_conf()
Allocates the values in the configuration space and destroys the values in the coefficients space.