LORENE
binaire_constr.C
1 /*
2  * Methods of class Binaire for estimating the error in the Hamiltionian
3  * and momentum constraints
4  *
5  * (see file binaire.h for documentation).
6  */
7 
8 /*
9  * Copyright (c) 2000-2001 Eric Gourgoulhon
10  *
11  * This file is part of LORENE.
12  *
13  * LORENE is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 2 of the License, or
16  * (at your option) any later version.
17  *
18  * LORENE is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with LORENE; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26  *
27  */
28 
29 
30 
31 
32 /*
33  * $Id: binaire_constr.C,v 1.4 2016/12/05 16:17:47 j_novak Exp $
34  * $Log: binaire_constr.C,v $
35  * Revision 1.4 2016/12/05 16:17:47 j_novak
36  * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
37  *
38  * Revision 1.3 2014/10/13 08:52:44 j_novak
39  * Lorene classes and functions now belong to the namespace Lorene.
40  *
41  * Revision 1.2 2004/03/25 10:28:59 j_novak
42  * All LORENE's units are now defined in the namespace Unites (in file unites.h).
43  *
44  * Revision 1.1.1.1 2001/11/20 15:19:30 e_gourgoulhon
45  * LORENE
46  *
47  * Revision 2.1 2000/03/13 17:05:34 eric
48  * *** empty log message ***
49  *
50  * Revision 2.0 2000/03/13 14:26:08 eric
51  * *** empty log message ***
52  *
53  *
54  * $Header: /cvsroot/Lorene/C++/Source/Binaire/binaire_constr.C,v 1.4 2016/12/05 16:17:47 j_novak Exp $
55  *
56  */
57 
58 // Headers C
59 #include "math.h"
60 
61 // Headers Lorene
62 #include "binaire.h"
63 #include "unites.h"
64 
65 
66 
67  //----------------------------------------------//
68  // Hamiltonian constraint //
69  //----------------------------------------------//
70 
71 namespace Lorene {
72 double Binaire::ham_constr() const {
73 
74  using namespace Unites ;
75 
76  if (p_ham_constr == 0x0) { // A new computation is required
77 
78 
79  Tenseur lap_alpha1( star1.get_mp() ) ;
80  Tenseur lap_alpha2( star2.get_mp() ) ;
81 
82  Tenseur source1( star1.get_mp() ) ;
83  Tenseur source2( star2.get_mp() ) ;
84 
85  Tenseur* p_lap_alpha[2] ;
86  Tenseur* p_source[2] ;
87  p_lap_alpha[0] = &lap_alpha1 ;
88  p_lap_alpha[1] = &lap_alpha2 ;
89  p_source[0] = &source1 ;
90  p_source[1] = &source2 ;
91 
92 
93  // Computation of the l.h.s. and r.h.s. of the Hamiltonian
94  // constraint in each star.
95  // -------------------------------------------------------
96 
97  double som = 0 ;
98 
99  for (int i=0; i<2; i++) {
100 
101  // Laplacian of alpha = ln(A)
102  // --------------------------
103 
104  Tenseur alpha_auto = et[i]->get_beta_auto()
105  - et[i]->get_logn_auto() ;
106 
107  *(p_lap_alpha[i]) = alpha_auto().laplacien() ;
108 
109  // Right-hand-side of the Hamiltonian constraint
110  // ---------------------------------------------
111 
112  const Tenseur& a_car = et[i]->get_a_car() ;
113  const Tenseur& ener_euler = et[i]->get_ener_euler() ;
114 
115  Tenseur d_alpha_auto = et[i]->get_d_beta_auto()
116  - et[i]->get_d_logn_auto() ;
117 
118  Tenseur d_alpha_comp = et[i]->get_d_beta_comp()
119  - et[i]->get_d_logn_comp() ;
120 
121  const Tenseur& akcar_auto = et[i]->get_akcar_auto() ;
122  const Tenseur& akcar_comp = et[i]->get_akcar_comp() ;
123 
124  *(p_source[i]) = - qpig * a_car * ener_euler
125  - 0.25 * ( akcar_auto + akcar_comp )
126  - 0.5 *
127  ( flat_scalar_prod(d_alpha_auto, d_alpha_auto)
128  + flat_scalar_prod(d_alpha_auto, d_alpha_comp)
129  ) ;
130 
131  // Relative difference
132  // -------------------
133  Tbl diff = diffrel( (*(p_lap_alpha[i]))(), (*(p_source[i]))() ) ;
134 
135  cout <<
136  "Binaire::ham_constr : relative difference Lap(alpha) <-> source : "
137  << endl << diff << endl ;
138 
139  som += max( abs(diff) ) ;
140 
141  }
142 
143 
144  // Total error
145  // -----------
146  p_ham_constr = new double ;
147 
148  *p_ham_constr = 0.5 * som ;
149 
150  }
151 
152  return *p_ham_constr ;
153 
154 }
155 
156 
157  //----------------------------------------------//
158  // Momentum constraint //
159  //----------------------------------------------//
160 
161 const Tbl& Binaire::mom_constr() const {
162 
163  using namespace Unites ;
164 
165  if (p_mom_constr == 0x0) { // A new computation is required
166 
167  Tenseur divk1( star1.get_mp(), 1, CON, ref_triad ) ;
168  Tenseur divk2( star2.get_mp(), 1, CON, ref_triad ) ;
169 
170  Tenseur source1( star1.get_mp(), 1, CON, ref_triad ) ;
171  Tenseur source2( star2.get_mp(), 1, CON, ref_triad ) ;
172 
173  Tenseur* p_divk[2] ;
174  Tenseur* p_source[2] ;
175  p_divk[0] = &divk1 ;
176  p_divk[1] = &divk2 ;
177  p_source[0] = &source1 ;
178  p_source[1] = &source2 ;
179 
180 
181  // Computation of the l.h.s. and r.h.s. of the momentum
182  // constraint in each star.
183  // -------------------------------------------------------
184 
185  double somx = 0 ;
186  double somy = 0 ;
187  double somz = 0 ;
188 
189  for (int i=0; i<2; i++) {
190 
191  // (flat space) divergence of K^{ij}
192  // ---------------------------------
193 
194  const Tenseur& a_car = et[i]->get_a_car() ;
195  Tenseur kij_auto = et[i]->get_tkij_auto() / a_car ;
196 
197  kij_auto.dec2_dzpuis() ; // dzpuis : 2 --> 0
198  // so that in the external domain, kij_auto
199  // contains now exactly K^{ij}
200 
201  // The gradient of K^{ij} is computed on the local triad:
202  kij_auto.change_triad( (et[i]->get_mp()).get_bvect_cart() ) ;
203 
204  *(p_divk[i]) = contract( kij_auto.gradient(), 0, 1) ;
205 
206  // Back to the Reference triad :
207  p_divk[i]->change_triad( ref_triad ) ;
208  kij_auto.change_triad( ref_triad ) ;
209 
210  // Right-hand-side of the momentum constraint
211  // ------------------------------------------
212 
213  const Tenseur& u_euler = et[i]->get_u_euler() ;
214  const Tenseur& ener_euler = et[i]->get_ener_euler() ;
215  const Tenseur& press = et[i]->get_press() ;
216 
217 
218  Tenseur d_alpha = et[i]->get_d_beta_auto()
219  - et[i]->get_d_logn_auto()
220  + et[i]->get_d_beta_comp()
221  - et[i]->get_d_logn_comp() ;
222 
223  *(p_source[i]) = 2 * qpig * (ener_euler + press) * u_euler
224  - 5 * contract(kij_auto, 1, d_alpha, 0) ;
225 
226  // Relative differences
227  // --------------------
228  Tbl diffx = diffrel( (*(p_divk[i]))(0), (*(p_source[i]))(0)) ;
229  Tbl diffy = diffrel( (*(p_divk[i]))(1), (*(p_source[i]))(1)) ;
230  Tbl diffz = diffrel( (*(p_divk[i]))(2), (*(p_source[i]))(2)) ;
231 
232  cout << "Binaire::mom_constr : norme div(K) : " << endl ;
233  cout << "X component : " << norme( (*(p_divk[i]))(0) ) << endl ;
234  cout << "Y component : " << norme( (*(p_divk[i]))(1) ) << endl ;
235  cout << "Z component : " << norme( (*(p_divk[i]))(2) ) << endl ;
236 
237  cout << "Binaire::mom_constr : norme source : " << endl ;
238  cout << "X component : " << norme( (*(p_source[i]))(0) ) << endl ;
239  cout << "Y component : " << norme( (*(p_source[i]))(1) ) << endl ;
240  cout << "Z component : " << norme( (*(p_source[i]))(2) ) << endl ;
241 
242 
243  cout <<
244  "Binaire::mom_constr : rel. diff. div(K) <-> source : "
245  << endl ;
246  cout << "X component : " << diffx << endl ;
247  cout << "Y component : " << diffy << endl ;
248  cout << "Z component : " << diffz << endl ;
249 
250 
251  somx += max( abs(diffx) ) ;
252  somy += max( abs(diffy) ) ;
253  somz += max( abs(diffz) ) ;
254  }
255 
256  // Total error
257  // -----------
258 
259  p_mom_constr = new Tbl(3) ;
261 
262  p_mom_constr->set(0) = 0.5 * somx ;
263  p_mom_constr->set(1) = 0.5 * somy ;
264  p_mom_constr->set(2) = 0.5 * somz ;
265 
266 
267  }
268 
269  return *p_mom_constr ;
270 
271 }
272 }
const Map & get_mp() const
Returns the mapping.
Definition: etoile.h:662
void dec2_dzpuis()
dzpuis -= 2 ;
Definition: tenseur.C:1146
const Tenseur & get_a_car() const
Returns the total conformal factor .
Definition: etoile.h:736
Etoile_bin star1
First star of the system.
Definition: binaire.h:118
Lorene prototypes.
Definition: app_hor.h:67
const Tenseur & get_akcar_comp() const
Returns the part of the scalar generated by shift_auto and shift_comp , i.e.
Definition: etoile.h:1213
Tbl * p_mom_constr
Relative error on the momentum constraint.
Definition: binaire.h:166
Standard units of space, time and mass.
const Tenseur_sym & get_tkij_auto() const
Returns the part of the extrinsic curvature tensor generated by shift_auto .
Definition: etoile.h:1195
double & set(int i)
Read/write of a particular element (index i) (1D case)
Definition: tbl.h:301
const Tenseur & get_d_beta_auto() const
Returns the gradient of beta_auto (Cartesian components with respect to ref_triad ) ...
Definition: etoile.h:1144
double * p_ham_constr
Relative error on the Hamiltonian constraint.
Definition: binaire.h:163
Tenseur flat_scalar_prod(const Tenseur &t1, const Tenseur &t2)
Scalar product of two Tenseur when the metric is : performs the contraction of the last index of t1 w...
const Base_vect_cart ref_triad
Cartesian triad of the absolute reference frame.
Definition: binaire.h:115
const Tenseur & get_logn_auto() const
Returns the logarithm of the part of the lapse N generated principaly by the star.
Definition: etoile.h:704
const Tenseur & get_d_logn_auto() const
Returns the gradient of logn_auto (Cartesian components with respect to ref_triad ) ...
Definition: etoile.h:1124
Tbl diffrel(const Cmp &a, const Cmp &b)
Relative difference between two Cmp (norme version).
Definition: cmp_math.C:507
const Tenseur & get_press() const
Returns the fluid pressure.
Definition: etoile.h:685
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
Definition: tbl.C:364
const Tbl & mom_constr() const
Estimates the relative error on the momentum constraint equation by comparing ${}_j K^{ij}$ with {equ...
Etoile_bin * et[2]
Array of the two stars (to perform loops on the stars): { et[0]} contains the address of { star1} and...
Definition: binaire.h:127
double ham_constr() const
Estimates the relative error on the Hamiltonian constraint equation by comparing $ A$ with {equation}...
void change_triad(const Base_vect &new_triad)
Sets a new vectorial basis (triad) of decomposition and modifies the components accordingly.
Definition: tenseur.C:684
Tbl norme(const Cmp &)
Sums of the absolute values of all the values of the Cmp in each domain.
Definition: cmp_math.C:484
Tbl max(const Cmp &)
Maximum values of a Cmp in each domain.
Definition: cmp_math.C:438
Tenseur contract(const Tenseur &, int id1, int id2)
Self contraction of two indices of a Tenseur .
const Tenseur & get_d_beta_comp() const
Returns the gradient of beta_comp (Cartesian components with respect to ref_triad ) ...
Definition: etoile.h:1149
const Tenseur & get_ener_euler() const
Returns the total energy density with respect to the Eulerian observer.
Definition: etoile.h:688
const Tenseur & get_d_logn_comp() const
Returns the gradient of logn_comp (Cartesian components with respect to ref_triad ) ...
Definition: etoile.h:1134
const Tenseur & get_akcar_auto() const
Returns the part of the scalar generated by shift_auto , i.e.
Definition: etoile.h:1207
Cmp abs(const Cmp &)
Absolute value.
Definition: cmp_math.C:413
Basic array class.
Definition: tbl.h:164
const Tenseur & get_u_euler() const
Returns the fluid 3-velocity with respect to the Eulerian observer.
Definition: etoile.h:697
Tensor handling *** DEPRECATED : use class Tensor instead ***.
Definition: tenseur.h:304
const Tenseur & get_beta_auto() const
Returns the logarithm of the part of the product AN generated principaly by the star.
Definition: etoile.h:727
const Tenseur & gradient() const
Returns the gradient of *this (Cartesian coordinates)
Definition: tenseur.C:1558
Etoile_bin star2
Second star of the system.
Definition: binaire.h:121