Calculettes pour l'hydraulique
form_courbe_remous.class.php
Aller à la documentation de ce fichier.
1 <?php
2 include_spip('hyd_inc/form_section.abstract.class');
3 
5 
6  // Définition du nombre de colonnes du formulaire
7  protected $nb_col = 2;
8 
9  function __construct() {
10 
11  $this->bFVC = false; // Ce n'est pas un formulaire avec les boutons fixe, varie, calcul
12 
13  $this->saisies['cond_lim'] = array(
14  'condition_limite',
15  array(
16  'rQ' =>array('debit_amont',2,'op'),
17  'rYaval' =>array('h_aval_imposee',0.4,'pn'),
18  'rYamont'=>array('h_amont_imposee',0.15,'pn')
19  ),
20  'fix'
21  );
22 
23  $this->saisies['param_calc'] = array(
24  'param_calcul',
25  array(
26  'rDx' =>array('pas_discret',5,'op'),
27  'rPrec' =>array('precision_calc',0.001,'op'),
28  'Methode' => array('choix_resolution','form_courbe_remous_methode','s')
29  ),
30  'fix'
31  );
32 
33  $this->saisies['val_a_cal'] = array(
34  'donnee_calc',
35  array(
36  'val_a_cal' => array('choix_donnee_calc','form_calcul_section_valacal','s')
37  ),
38  'fix'
39  );
40  parent::__construct(true);
41 
42  foreach($this->saisies as &$saisie) {
43  $saisie[2] = 'fix';
44  }
45  }
46 
47 
48  public function charger() {
49  $valeurs = parent::charger(true);
50  $valeurs = array_merge($valeurs,
51  array(
52  'choix_section' => 'FT',
53  'val_a_cal' => 'none',
54  'choix_champs_select' => array_merge(
55  array('none' => 'aucune'),
56  $this->champs_select_calc
57  )
58  )
59  );
60  if(self::DBG_CHARGER) spip_log($valeurs,'hydraulic',_LOG_DEBUG);
61  return $valeurs;
62  }
63 
64 
65  protected function calculer() {
66  $this->creer_section_param();
67 
68  // On transforme les champs du tableau des données du formulaire en variables
69  extract($this->data, EXTR_OVERWRITE|EXTR_REFS);
70 
71  include_spip('hyd_inc/courbe_remous');
72 
73  $oLog = &$this->oLog;
74 
75  // On calcule les données pour créer un cache et afficher le résultat
76  $this->oLog->Add(_T('hydraulic:largeur_berge').' = '.format_nombre($this->oSn->rLargeurBerge,$this->oP->iPrec).' m');
77  $this->oLog->Add(_T('hydraulic:h_critique').' = '.format_nombre($this->oSn->CalcGeo('Yc'),$this->oP->iPrec).' m');
78  $this->oLog->Add(_T('hydraulic:h_normale').' = '.format_nombre($this->oSn->CalcGeo('Yn'),$this->oP->iPrec).' m');
79 
80  // Calcul des courbes de remous
81  $aC = array(); // deux items (Flu et Tor) composé d'un vecteur avec key=X et value=Y
82 
83  // Calcul depuis l'aval
84  if($this->oSn->rHautCritique <= $rYaval) {
85  $this->oLog->Add(_T('hydraulic:calcul_fluvial'));
86  $oCRF = new cCourbeRemous($this->oLog, $this->oP, $this->oSn, $rDx);
87  $aC['Flu'] = $oCRF->calcul($rYaval, $rLong, $Methode);
88  }
89  else {
90  $this->oLog->Add(_T('hydraulic:pas_calcul_depuis_aval'), true);
91  }
92 
93  // Calcul depuis l'amont
94  if($this->oSn->rHautCritique >= $rYamont) {
95  $this->oLog->Add(_T('hydraulic:calcul_torrentiel'));
96  $oCRT = new cCourbeRemous($this->oLog, $this->oP, $this->oSn, -$rDx);
97  $aC['Tor'] = $oCRT->calcul($rYamont, $rLong, $Methode);
98  }
99  else {
100  $this->oLog->Add(_T('hydraulic:pas_calcul_depuis_amont'), true);
101  }
102  spip_log($aC,'hydraulic',_LOG_DEBUG);
103 
104  // Détection du ressaut hydraulique
105  $bDetectRessaut = true;
106  if($bDetectRessaut && isset($aC['Flu']) && isset($aC['Tor'])) {
107  if(count($aC['Flu']) > count($aC['Tor']) || (count($aC['Flu']) == count($aC['Tor']) && $this->oSn->Calc('Imp', end($aC['Flu'])) > $this->oSn->Calc('Imp', end($aC['Tor'])))) {
108  // La courbe fluviale va jusqu'au bout
109  $sCC = 'Flu';
110  $sCN = 'Tor';
111  $iSens = 1; // On cherche l'aval du ressaut
112  $sSens = _T('hydraulic:amont');
113  } else {
114  // La courbe torrentielle va jusqu'au bout
115  $sCC = 'Tor';
116  $sCN = 'Flu';
117  $iSens = -1; // On cherche l'amont du ressaut
118  $sSens = _T('hydraulic:aval');
119  }
120  $trX = array_reverse(array_keys($aC[$sCN])); // Parcours des sections de la ligne d'eau la plus courte
121  $bRessaut = false;
122  foreach($trX as $rX) {
123  // Calcul de l'abscisse de la section dans l'autre régime
124  $Yco = $this->oSn->Calc('Yco', $aC[$sCN][$rX]); // Y conjugué
125  $rLongRst = 5 * abs($aC[$sCN][$rX] - $Yco); // Longueur du ressaut
126  $xRst = $rX + round($iSens * $rLongRst / $rDx) * $rDx; // Abscisse où comparer Yconj et Y
127  $xRst = sprintf('%1.'.round($this->oP->iPrec).'f',$xRst);
128  //spip_log("\nrX=$rX xRst=$xRst Yco=$Yco",'hydraulic',_LOG_DEBUG);
129  if(isset($aC[$sCC][$xRst])) {
130  // Hauteur décalée de la longueur du ressaut (il faut gérer la pente du fond)
131  $Ydec = $aC[$sCC][$xRst] + $rLongRst * $this->oP->rIf * $iSens;
132  spip_log("\nrX=$rX xRst=$xRst Yco=$Yco Ydec=$Ydec",'hydraulic',_LOG_DEBUG);
133  if(($Yco - $Ydec) > 0) {
134  $this->oLog->Add(_T('hydraulic:ressaut_hydrau', array('Xmin'=>min($rX,$xRst), 'Xmax'=>max($rX,$xRst))));
135  spip_log("rX=$rX xRst=$xRst",'hydraulic',_LOG_DEBUG);
136  // Modification de la ligne d'eau CC
137  foreach(array_keys($aC[$sCN]) as $rXCC) {
138  if($iSens * ($rXCC - $rX) < 0) {
139  unset($aC[$sCC][$rXCC]);
140  } elseif($rXCC == $rX) {
141  $aC[$sCC][$rXCC] = $aC[$sCN][$rXCC];
142  break;
143  }
144  }
145  // Modification de la ligne d'eau CN
146  foreach($trX as $rXCN) {
147  if($iSens * ($rXCN - $xRst) > 0) {
148  unset($aC[$sCN][$rXCN]);
149  } elseif($rXCN == $xRst) {
150  $aC[$sCN][$rXCN] = $aC[$sCC][$rXCN];
151  break;
152  }
153  }
154  $bRessaut = true;
155  break;
156  }
157  }
158  }
159  if(!$bRessaut) {
160  // Le ressaut est en dehors du canal
161  $this->oLog->Add(_T('hydraulic:ressaut_dehors', array('Sens' => $sSens, 'X' => end($trX))));
162  $aC[$sCN] = array();
163  }
164  }
165 
166  // Définition des abscisses
167  $trX = array();
168  if(isset($aC['Flu'])) $trX = array_merge($trX, array_keys($aC['Flu']));
169  if(isset($aC['Tor'])) $trX = array_merge($trX, array_keys($aC['Tor']));
170  $trX = array_unique($trX, SORT_NUMERIC);
171  sort($trX, SORT_NUMERIC);
172 
173  // Calcul de la variable à calculer
174  $this->data['ValCal'] = $val_a_cal;
175  $tRes = array();
176  if($val_a_cal != 'none') {
177  foreach($trX as $rX) {
178  $rY = false;
179  if(isset($aC['Flu'][$rX]) && !isset($aC['Tor'][$rX])) {
180  $rY = $aC['Flu'][$rX];
181  }
182  if(isset($aC['Tor'][$rX])) {
183  if(!isset($aC['Flu'][$rX]) || (isset($aC['Flu'][$rX]) && $aC['Flu'][$rX]==$aC['Tor'][$rX])) {
184  $rY = $aC['Tor'][$rX];
185  }
186  }
187  if($rY !== false) {
188  if(!in_array($val_a_cal,array('Yn', 'Yc', 'Hsc'))){
189  $tRes[$rX] = $this->oSn->Calc($val_a_cal, $rY);
190  }
191  else{
192  $tRes[$rX] = $this->oSn->CalcGeo($val_a_cal, $rY);
193  }
194  }
195  }
196  }
197 
198  return array_merge(
199  $aC,
200  array(
201  'trX' => $trX,
202  'tRes' => $tRes
203  )
204  );
205  }
206 
207 
208  /** ************************************************************************
209  * Affichage des tableaux et graphiques des résultats des calculs
210  * @return Chaîne de caractère avec le code HTML à afficher
211  ***************************************************************************/
212  protected function afficher_result() {
213  // Code de langue du champ de la valeur calculée
214  if($this->data['ValCal'] != 'none') {
215  $sCodeLangValCal = $this->champs_select_calc[$this->data['ValCal']];
216  $sLibValCal = _T("hydraulic:$sCodeLangValCal");
217  } else {
218  $sLibValCal = '';
219  }
220 
221  // Gestion du graphique affichant la variable à calculer
222  if(in_array($this->data['ValCal'], array('Hs', 'Hsc', 'Yf', 'Yt', 'Yco')))
223  {
224  // Affichage d'une courbe supplémentaire sur le graphique courbe de remous
225  $choix_graph = 'courbe';
226  }
227  elseif(in_array($this->data['ValCal'], array('B', 'P', 'S', 'R', 'V', 'Fr', 'J', 'I-J', 'Imp', 'Tau0')))
228  {
229  // Affichage de la donnée sur un nouveau graphique
230  $choix_graph = 'graph';
231  }
232  else
233  {
234  // Pas de graph pour la hauteur normale et la hauteur critique qui sont déjà affichés par défaut
235  $choix_graph = 'none';
236  }
237 
238  //Construction d'un tableau des indices x combinant les abscisses des 2 lignes d'eau
239  $trX = $this->result['trX'];
240 
241  $echo = '';
242 
243  if(!empty($trX)) {
244  /***************************************************************************
245  * Affichage du graphique
246  ****************************************************************************/
247  include_spip('hyd_inc/graph.class');
248  $oGraph = new cGraph('', _T('hydraulic:abscisse'));
249  // Ligne d'eau globale
250  $LgnEau = array();
251  if(isset($this->result['Flu'])) {
252  $LgnEau = $this->result['Flu'];
253  }
254  spip_log($LgnEau,'hydraulic',_LOG_DEBUG);
255  if(isset($this->result['Tor'])) {
256  $LgnEau = array_merge($this->result['Tor'], $LgnEau);
257  }
258  spip_log($LgnEau,'hydraulic',_LOG_DEBUG);
259  if(!empty($LgnEau)) {
260  $oGraph->AddSerie(
261  '',
262  array_keys($LgnEau),
263  array_values($LgnEau),
264  '#F0F0FF70',
265  'lineWidth:0, fill:true, showLabel:false'
266  );
267  }
268  // Cote des berges
269  $oGraph->AddSerie(
270  'berge',
271  $trX,
272  $this->oP->rYB, // La cote des berges sera calculée à partir de la pente fournie dans GetGraph
273  '#C58f50',
274  'lineWidth:1'
275  );
276  // Cote du fond
277  $oGraph->AddSerie(
278  'fond',
279  $trX,
280  0, // La cote du fond sera calculée à partir de la pente fournie dans GetGraph
281  '#753f00',
282  'lineWidth:1, fill:true'
283  );
284  // Ligne d'eau fluviale
285  if(isset($this->result['Flu'])) {
286  $oGraph->AddSerie(
287  'ligne_eau_fluviale',
288  array_keys($this->result['Flu']),
289  array_values($this->result['Flu']),
290  '#0093bd',
291  'lineWidth:3, showMarker:true, markerOptions:{style:\'filledCircle\', size:8}'
292  );
293  }
294  // Ligne d'eau torrentielle
295  if(isset($this->result['Tor'])) {
296  $oGraph->AddSerie(
297  'ligne_eau_torrentielle',
298  array_keys($this->result['Tor']),
299  array_values($this->result['Tor']),
300  '#77a3cd',
301  'lineWidth:3, showMarker:true, markerOptions:{style:\'filledCircle\', size:8}'
302  );
303  }
304  // Hauteur critique
305  if(is_numeric($this->oSn->rHautCritique)) {
306  $oGraph->AddSerie(
307  'h_critique',
308  $trX,
309  $this->oSn->rHautCritique, // La cote du fond sera calculée à partir de la pente fournie dans GetGraph
310  '#ff0000',
311  'lineWidth:2'
312  );
313  }
314  // Hauteur normale
315  if(is_numeric($this->oSn->rHautNormale)) {
316  $oGraph->AddSerie(
317  'h_normale',
318  $trX,
319  $this->oSn->rHautNormale, // La cote du fond sera calculée à partir de la pente fournie dans GetGraph
320  '#a4c537',
321  'lineWidth:2'
322  );
323  }
324 
325  // Valeur calculée
326  if($choix_graph == 'courbe') {
327  $oGraph->AddSerie(
328  $sCodeLangValCal,
329  array_keys($this->result['tRes']),
330  array_values($this->result['tRes']),
331  '#C17AF0',
332  'lineWidth:3, showMarker:true, markerOptions:{style:\'filledCircle\', size:8}'
333  );
334  }
335 
336  // Décalage des données par rapport au fond
337  $oGraph->Decal(max(0,-$this->data['rIf']*$this->data['rLong']), $this->data['rIf'], $this->data['rLong']);
338 
339  // Récupération du graphique
340  $echo .= $oGraph->GetGraph('courbe_remous',400,600);
341 
342  // Affichage du graphique
343  if($choix_graph == 'graph') {
344  $echo .= $this->getGraph(
345  _T('hydraulic:abscisse'),
346  $sLibValCal,
347  array_keys($this->result['tRes']),
348  array_values($this->result['tRes'])
349  );
350  }
351  }
352 
353  // Journal de calcul
354  $echo .= $this->oLog->Result();
355 
356  if(!empty($trX)) {
357  /***************************************************************************
358  * Affichage du tableau de données
359  ****************************************************************************/
360  $echo.='<table class="spip">
361  <thead>
362  <tr class="row_first">
363  <th scope="col" colspan="1" rowspan="2">'._T('hydraulic:abscisse').'</th>
364  <th scope="col" colspan="2" rowspan="1">'._T('hydraulic:ligne_eau_fluviale').'</th>
365  <th scope="col" colspan="2" rowspan="1">'._T('hydraulic:ligne_eau_torrentielle').'</th>
366  </tr>
367  <tr class="row_first">
368  <th scope="col">'._T('hydraulic:tirant_eau').'</th>
369  <th scope="col">'.$sLibValCal.'</th>
370  <th scope="col">'._T('hydraulic:tirant_eau').'</th>
371  <th scope="col">'.$sLibValCal.'</th>
372  </tr>
373  </thead>
374  <tbody>';
375  $i=0;
376  foreach($trX as $rX) {
377  $i+=1;
378  $echo.='<tr class="align_right ';
379  $echo.=($i%2==0)?'row_even':'row_odd';
380  $echo.='"><td>'.format_nombre($rX,$this->oP->iPrec).'</td>';
381  if(isset($this->result['tRes'][$rX])) {
382  $sValCal = format_nombre($this->result['tRes'][$rX],$this->oP->iPrec);
383  } else {
384  $sValCal = '-';
385  }
386  if(isset($this->result['Flu'][$rX])) {
387  // On formalise les résultats, avec le nombre de chiffres aprés la virgule adéquat
388  $echo .= '<td>'.format_nombre($this->result['Flu'][$rX],$this->oP->iPrec).'</td>';
389  $echo .= "<td>$sValCal</td>";
390  }
391  else {
392  $echo .= '<td></td><td></td>';
393  }
394  if(isset($this->result['Tor'][$rX])) {
395  $echo .= '<td>'.format_nombre($this->result['Tor'][$rX],$this->oP->iPrec).'</td>';
396  $echo .= "<td>$sValCal</td>";
397  }
398  else {
399  $echo .= '<td></td><td></td>';
400  }
401  $echo .= '</tr>';
402  }
403  $echo.='</tbody>
404  </table>';
405  }
406  return $echo;
407  }
408 
409 
410  protected function get_champs_libelles() {
411  $lib = parent::get_champs_libelles();
412  foreach($this->champs_select_calc as $cle=>$champ) {
413  $lib[$cle] = _T('hydraulic:'.$champ);
414  }
415  return $lib;
416  }
417 }
418 ?>
Calcul d&#39;une courbe de remous.
afficher_result()
Affichage des tableaux et graphiques des résultats des calculs
getGraph($sLibVar, $LibCal, $tAbs, $tRes)
Affichage du graphique de la variable calculée.
Classe pour l&#39;affichage des graphiques.
Definition: graph.class.php:48
format_nombre($nombre, $dec)
Definition: cache.php:55
$oLog
Journal de calcul.