LORENE
separation.C
1 /*
2  * Copyright (c) 2001 Philippe Grandclement
3  *
4  * This file is part of LORENE.
5  *
6  * LORENE is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * LORENE is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with LORENE; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  */
21 
22 
23 
24 
25 /*
26  * $Id: separation.C,v 1.5 2016/12/05 16:17:45 j_novak Exp $
27  * $Log: separation.C,v $
28  * Revision 1.5 2016/12/05 16:17:45 j_novak
29  * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
30  *
31  * Revision 1.4 2014/10/13 08:52:41 j_novak
32  * Lorene classes and functions now belong to the namespace Lorene.
33  *
34  * Revision 1.3 2014/10/06 15:12:59 j_novak
35  * Modified #include directives to use c++ syntax.
36  *
37  * Revision 1.2 2003/10/03 15:58:44 j_novak
38  * Cleaning of some headers
39  *
40  * Revision 1.1.1.1 2001/11/20 15:19:28 e_gourgoulhon
41  * LORENE
42  *
43  * Revision 2.6 2001/04/02 12:16:20 phil
44  * *** empty log message ***
45  *
46  * Revision 2.5 2001/03/30 13:48:17 phil
47  * on appelle raccord externe
48  *
49  * Revision 2.4 2001/03/22 10:40:30 phil
50  * modification prototypage
51  *
52  * Revision 2.3 2001/03/02 10:19:05 phil
53  * modification parametrage pour affichage
54  *
55  * Revision 2.2 2001/02/28 13:39:34 phil
56  * modif cas etat_zero
57  *
58  * Revision 2.1 2001/02/28 13:23:00 phil
59  * modif etat initial
60  *
61  * Revision 2.0 2001/02/28 11:24:34 phil
62  * *** empty log message ***
63  *
64  *
65  * $Header: /cvsroot/Lorene/C++/Source/Bhole_binaire/separation.C,v 1.5 2016/12/05 16:17:45 j_novak Exp $
66  *
67  */
68 
69 //standard
70 #include <cstdlib>
71 
72 // Lorene
73 #include "cmp.h"
74 #include "proto.h"
75 
76 namespace Lorene {
77 void separation (const Cmp& c1, const Cmp& c2, Cmp& res1, Cmp& res2, int decrois,
78  int puiss, int lmax, double precision, const double relax, const int itemax, const int flag) {
79 
80  assert (c1.get_etat() != ETATNONDEF) ;
81  assert (c2.get_etat() != ETATNONDEF) ;
82 
83  if ((c1.get_etat() == ETATZERO) && (c2.get_etat() == ETATZERO)) {
84  res1.set_etat_zero() ;
85  res2.set_etat_zero() ;
86  return ;
87  }
88  else {
89 
90  res1 = c1 ;
91  if (res1.get_etat() == ETATZERO) {
92  res1.annule_hard() ;
93  res1.std_base_scal() ;
94  }
95 
96  res1.raccord_externe (decrois, puiss, lmax) ;
97  for (int i=0 ; i<decrois ; i++)
98  res1.dec_dzpuis() ;
99 
100  res2 = c2 ;
101  if (res2.get_etat() == ETATZERO) {
102  res2.annule_hard() ;
103  res2.std_base_scal() ;
104  }
105  res2.raccord_externe (decrois, puiss, lmax) ;
106  for (int i=0 ; i<decrois ; i++)
107  res2.dec_dzpuis() ;
108 
109  int indic = 1 ;
110  int conte = 0 ;
111  // On commence la boucle pour separer :
112  while (indic == 1) {
113  Cmp old_un (res1) ;
114  Cmp old_deux (res2) ;
115 
116  // On fait les modifications :
117  Mtbl xa_mtbl_un (c1.get_mp()->xa) ;
118  Mtbl ya_mtbl_un (c1.get_mp()->ya) ;
119  Mtbl za_mtbl_un (c1.get_mp()->za) ;
120 
121  Mtbl xa_mtbl_deux (c2.get_mp()->xa) ;
122  Mtbl ya_mtbl_deux (c2.get_mp()->ya) ;
123  Mtbl za_mtbl_deux (c2.get_mp()->za) ;
124 
125  double xabs, yabs, zabs, air, theta, phi ;
126  int np, nt, nr ;
127 
128  // On modifie le Cmp 1
129  int nz_un = c1.get_mp()->get_mg()->get_nzone() ;
130  for (int l=1 ; l<nz_un-1 ; l++) {
131 
132  np = c1.get_mp()->get_mg()->get_np(l) ;
133  nt = c1.get_mp()->get_mg()->get_nt(l) ;
134  nr = c1.get_mp()->get_mg()->get_nr(l) ;
135 
136  for (int k=0 ; k<np ; k++)
137  for (int j=0 ; j<nt ; j++)
138  for (int i=0 ; i<nr ; i++) {
139  xabs = xa_mtbl_un (l, k, j, i) ;
140  yabs = ya_mtbl_un (l, k, j, i) ;
141  zabs = za_mtbl_un (l, k, j, i) ;
142 
143  c2.get_mp()->convert_absolute(xabs, yabs, zabs, air, theta, phi) ;
144  res1.set(l, k, j, i) =
145  (1-relax)*res1.set(l, k, j, i) +
146  relax*(c1(l, k, j, i) - old_deux.val_point(air, theta, phi)) ;
147  }
148  }
149 
150  // On modifie le trou 2
151  int nz_deux = c2.get_mp()->get_mg()->get_nzone() ;
152  for (int l=1 ; l<nz_deux-1 ; l++) {
153 
154  np = c2.get_mp()->get_mg()->get_np(l) ;
155  nt = c2.get_mp()->get_mg()->get_nt(l) ;
156  nr = c2.get_mp()->get_mg()->get_nr(l) ;
157 
158  for (int k=0 ; k<np ; k++)
159  for (int j=0 ; j<nt ; j++)
160  for (int i=0 ; i<nr ; i++) {
161 
162  xabs = xa_mtbl_deux (l, k, j, i) ;
163  yabs = ya_mtbl_deux (l, k, j, i) ;
164  zabs = za_mtbl_deux (l, k, j, i) ;
165 
166  c1.get_mp()->convert_absolute(xabs, yabs, zabs, air, theta, phi) ;
167  res2.set(l, k, j, i) =
168  (1-relax)*res2.set(l, k, j, i) +
169  relax*(c2(l, k, j, i) - old_un.val_point(air, theta, phi)) ;
170  }
171  }
172 
173  // les coefficients ne sont plus a jour :
174  res1.va.set_etat_c_qcq() ;
175  res2.va.set_etat_c_qcq() ;
176  // On raccord dans la zec :
177  res1.raccord_externe (decrois, puiss, lmax) ;
178  for (int i=0 ; i<decrois ; i++)
179  res1.dec_dzpuis() ;
180 
181  res1.va.coef_i() ;
182  res2.raccord_externe (decrois, puiss, lmax) ;
183  for (int i=0 ; i<decrois ; i++)
184  res2.dec_dzpuis() ;
185  res2.va.coef_i() ;
186 
187  // On regarde si on a converge :
188 
189  double erreur = 0 ;
190 
191  Tbl diff_un (diffrelmax(res1, old_un)) ;
192  for (int i=1 ; i<nz_un-1 ; i++)
193  if (diff_un(i)>erreur)
194  erreur = diff_un(i) ;
195 
196  Tbl diff_deux (diffrelmax(res2, old_deux)) ;
197  for (int i=1 ; i<nz_deux-1 ; i++)
198  if (diff_deux(i)>erreur)
199  erreur = diff_deux(i) ;
200 
201  if (flag == 1)
202  cout << "Pas " << conte << " : erreur = " << erreur << endl ;
203  if (erreur<=precision)
204  indic = -1 ;
205 
206  conte ++ ;
207  if (conte > itemax)
208  indic = -1 ;
209  }
210  }
211 }
212 }
Lorene prototypes.
Definition: app_hor.h:67
Tbl diffrelmax(const Cmp &a, const Cmp &b)
Relative difference between two Cmp (max version).
Definition: cmp_math.C:542