HelloWorld: pspa.php

File pspa.php, 9.9 KB (added by /C=FR/O=CNRS/OU=UMR8607/CN=Christian Arnault/emailAddress=arnault@…, 14 years ago)
Line 
1<?php
2
3include ('Faisceau.php');
4include ('Cavité.php');
5include ('Cible.php');
6
7class Paramètres
8{
9 var $script;
10 var $http;
11 var $name;
12 var $uri;
13
14 var $twiss = 1;
15 var $énergie = 2;
16
17 var $champ = 3;
18 var $longueur = 4;
19
20 var $largeur = 5;
21
22 var $épaisseur = 6;
23
24 function Paramètres ()
25 {
26 $this->http = "http" . ((!empty($_SERVER['HTTPS'])) ? "s" : "") . ":";
27 $this->name = "//" . $_SERVER['SERVER_NAME'];
28 $this->uri = $_SERVER['REQUEST_URI'];
29
30 $this->script = $this->http . $this->name . $this->uri;
31
32 $pos = strpos ($this->uri, "/pspa.php");
33 $this->base = $this->http . $this->name . substr ($this->uri, 0, $pos);
34 }
35};
36
37$Paramètres = new Paramètres ();
38
39class TRANSPORT
40{
41 function TRANSPORT ()
42 {
43 }
44
45 function run ($faisceau, $cavité)
46 {
47 global $Paramètres;
48
49 $string = '<pspa></pspa>';
50
51 $xml = new SimpleXMLElement($string);
52
53 $f = $xml->addChild ("faisceau");
54 $f->addAttribute ("twiss", $faisceau->twiss);
55 $f->addAttribute ("energie", $faisceau->énergie);
56 $c = $xml->addChild ("cavite");
57 $c->addAttribute ("longueur", $cavité->longueur);
58 $c->addAttribute ("champ", $cavité->champ);
59
60 $xml->asXML('transport.xml');
61
62 $sortie = new Faisceau ();
63
64 //$h = popen ("Transport.exe transport.data", "r");
65
66 $input = $Paramètres->base . "/Transport.php?data=transport.xml";
67 echo "Transport: input={$input}<br>";
68 $h = fopen ($input, "r");
69
70 if ($h)
71 {
72 echo "Transport ok<br>";
73 $s = '';
74 while (($buffer = fgets ($h)) !== false)
75 {
76 $buffer = trim ($buffer);
77 $s .= $buffer;
78 }
79 //echo htmlentities($s);
80 //echo "<br>";
81
82 $xml = new SimpleXMLElement($s);
83 //print_r ($xml);
84 //echo "<br>";
85
86 $f = $xml->faisceau;
87 $sortie->twiss = (double) $f['twiss'];
88 $sortie->énergie = (double) $f['energie'];
89
90 fclose ($h);
91 }
92 else
93 {
94 echo "impossible de lancer Transport<br>";
95 }
96
97 return ($sortie);
98 }
99};
100
101class EGS
102{
103 function EGS ()
104 {
105 }
106
107 function run ($cible, $faisceau)
108 {
109 global $Paramètres;
110
111 $string = '<pspa></pspa>';
112
113 $xml = new SimpleXMLElement($string);
114
115 $f = $xml->addChild ("faisceau");
116 $f->addAttribute ("twiss", $faisceau->twiss);
117 $f->addAttribute ("energie", $faisceau->énergie);
118 $c = $xml->addChild ("cible");
119 $c->addAttribute ("epaisseur", $cible->épaisseur);
120
121 $xml->asXML('egs.xml');
122
123 $sortie = array();
124 $f = new Faisceau ();
125
126 $first = true;
127
128 //$h = popen ("EGS.exe egs.data", "r");
129
130 $input = $Paramètres->base . "/EGS.php?data=egs.xml";
131 echo "EGS: input={$input}<br>";
132 $h = fopen ($input, "r");
133 if ($h)
134 {
135 echo "EGS ok<br>";
136 $s = '';
137 while (($buffer = fgets ($h)) !== false)
138 {
139 $buffer = trim ($buffer);
140 $s .= $buffer;
141 }
142 //echo htmlentities($s);
143 //echo "<br>";
144
145 $xml = new SimpleXMLElement($s);
146
147 foreach ($xml as $k => $v)
148 {
149 $nom = (string) $v;
150 $f = new Faisceau ($nom, (double) $v['twiss'], (double) $v['energie']);
151 $sortie[$f->nom] = $f;
152 }
153
154 fclose ($h);
155 }
156
157 return ($sortie);
158 }
159};
160
161
162
163class Control
164{
165 function header ()
166 {
167 echo "
168<html>
169<head>
170<style type='text/css'>
171</style>
172</head>
173";
174 }
175
176
177 function get_post ()
178 {
179 global $_POST;
180 global $Paramètres;
181
182 foreach ($_POST as $cle => $value)
183 {
184 $words = explode ('_', $cle);
185
186 $n = count ($words);
187
188 $classe = $words[0];
189 $champ = '';
190 if ($n > 1) $champ = str_replace ($classe . '_', '', $cle);
191
192 if (is_array ($value))
193 {
194 $str = "cle=($cle) _POST[{$classe}.{$champ}]=";
195 }
196 else
197 {
198 $Paramètres->$cle = $value;
199 }
200 }
201 }
202
203
204 function faisceau_entrée ()
205 {
206 global $Paramètres;
207
208 echo "
209 <tr>
210 <td>
211 <b><i>Définition du faisceau d'entrée</i></b>
212 </td>
213 <td>
214 Twiss
215 </td>
216 <td>
217 <input type='text' name='twiss' value='{$Paramètres->twiss}' size='6'>
218 </td>
219 <td>
220 Energie
221 </td>
222 <td>
223 <input type='text' name='énergie' value='{$Paramètres->énergie}' size='6'>
224MeV
225 </td>
226 </tr>
227";
228
229 }
230
231 function cavité ()
232 {
233 global $Paramètres;
234
235 echo "
236 <tr>
237 <td>
238 <b><i>Définition de la cavité</i></b>
239 </td>
240 <td>
241 Champ
242 </td>
243 <td>
244 <input type='text' name='champ' value='{$Paramètres->champ}' size='6'>
245MV/m
246 </td>
247 <td>
248 Longueur
249 </td>
250 <td>
251 <input type='text' name='longueur' value='{$Paramètres->longueur}' size='6'>
252m
253 </td>
254 </tr>
255";
256
257 }
258
259 function distribution ()
260 {
261 global $Paramètres;
262
263 echo "
264 <tr>
265 <td>
266 <b><i>Distribution des particules</i></b>
267 </td>
268 <td>
269 Largeur
270 </td>
271 <td>
272 <input type='text' name='largeur' value='{$Paramètres->largeur}' size='6'>
273m
274 </td>
275 </tr>
276";
277
278 }
279
280
281 function cible ()
282 {
283 global $Paramètres;
284
285 echo "
286 <tr>
287 <td>
288 <b><i>Définition de la cible</i></b>
289 </td>
290 <td>
291 Epaisseur
292 </td>
293 <td>
294 <input type='text' name='épaisseur' value='{$Paramètres->épaisseur}' size='6'>
295cm
296 </td>
297 </tr>
298";
299
300 }
301
302 function faisceaux_sortie ($électrons, $photons, $positrons)
303 {
304 global $Paramètres;
305
306 echo "
307<table>
308 <tr>
309 <td colspan='2'>
310 <center><hr></center>
311 </td>
312 <td>
313 <center><i>Sortie</i></center>
314 </td>
315 <td colspan='2'>
316 <center><hr></center>
317 </td>
318 </tr>
319 <tr>
320 <td>
321 <b><i>Electrons</i></b>
322 </td>
323 <td>
324 Twiss
325 </td>
326 <td>
327 {$électrons->twiss}
328 </td>
329 <td>
330 Energie
331 </td>
332 <td>
333 {$électrons->énergie} MeV
334 </td>
335 </tr>
336 <tr>
337 <td>
338 <b><i>Photons</i></b>
339 </td>
340 <td>
341 Twiss
342 </td>
343 <td>
344 {$photons->twiss}
345 </td>
346 <td>
347 Energie
348 </td>
349 <td>
350 {$photons->énergie} MeV
351 </td>
352 </tr>
353 <tr>
354 <td>
355 <b><i>Positrons</i></b>
356 </td>
357 <td>
358 Twiss
359 </td>
360 <td>
361 {$positrons->twiss}
362 </td>
363 <td>
364 Energie
365 </td>
366 <td>
367 {$positrons->énergie} MeV
368 </td>
369 </tr>
370</table>
371";
372
373 }
374
375 function step1 ($faisceaux = null)
376 {
377 global $Paramètres;
378
379 echo "
380<table>
381 <form enctype='multipart/form-data' action='{$Paramètres->script}' method='post'>
382 <tr>
383 <td colspan='5'>
384 <i>Step 1</i>
385 </td>
386 </tr>
387";
388
389 $this->faisceau_entrée ();
390 $this->cavité ();
391
392 echo "
393<tr>
394 <td>
395 <input name='largeur' value='{$Paramètres->largeur}' type='hidden' />
396 <input name='épaisseur' value='{$Paramètres->épaisseur}' type='hidden' />
397 <input type='submit' name='submit' value='Run'>
398 </td>
399</tr>
400";
401
402 echo "
403 </form>
404</table>
405";
406
407 echo "
408<tr>
409 <td colspan='5'>
410 <center><hr></center>
411 </td>
412</tr>
413";
414
415 echo "
416<tr>
417 <td colspan='5'>
418 <center>TRANSPORT</center>
419 </td>
420</tr>
421";
422
423 $faisceau = new Faisceau ("", $Paramètres->twiss, $Paramètres->énergie);
424 $cavité = new Cavité ($Paramètres->champ, $Paramètres->longueur);
425
426 $transport = new TRANSPORT ();
427 $faisceau_intermédiaire = $transport->run ($faisceau, $cavité);
428
429 //echo "twiss={$faisceau_intermédiaire->twiss}<br>";
430 //echo "énergie={$faisceau_intermédiaire->énergie}<br>";
431
432 echo "
433<tr>
434 <td colspan='5'>
435 <center><hr></center>
436 </td>
437</tr>
438";
439
440 $sortie = array ("électrons" => $faisceau_intermédiaire);
441
442 return ($sortie);
443 }
444
445 function step2 ($faisceaux)
446 {
447 global $Paramètres;
448
449 $faisceau = NULL;
450 foreach ($faisceaux as $k => $f)
451 {
452 $faisceau = $f;
453 }
454
455 echo "
456<table>
457 <form enctype='multipart/form-data' action='{$Paramètres->script}' method='post'>
458 <tr>
459 <td colspan='5'>
460 <i>Step 2</i>
461 </td>
462 </tr>
463";
464
465 $this->distribution ();
466 $this->cible ();
467
468 echo "
469<tr>
470 <td>
471 <input name='twiss' value='{$Paramètres->twiss}' type='hidden' />
472 <input name='énergie' value='{$Paramètres->énergie}' type='hidden' />
473 <input name='champ' value='{$Paramètres->champ}' type='hidden' />
474 <input name='longueur' value='{$Paramètres->longueur}' type='hidden' />
475 <input type='submit' name='submit' value='Run'>
476 </td>
477</tr>
478";
479
480 echo "
481 </form>
482</table>
483";
484
485 echo "
486<tr>
487 <td colspan='5'>
488 <center><hr></center>
489 </td>
490</tr>
491
492<tr>
493 <td colspan='5'>
494 <center>EGS</center>
495 </td>
496</tr>
497";
498
499 $cible = new Cible ($Paramètres->épaisseur);
500
501 $egs = new EGS ();
502 $sortie = $egs->run ($cible, $faisceau);
503
504 echo "
505<tr>
506 <td colspan='5'>
507 <center><hr></center>
508 </td>
509</tr>
510";
511
512 return ($sortie);
513 }
514
515 function init ()
516 {
517 global $Paramètres;
518
519 $this->get_post ();
520 $this->header ();
521 }
522
523 function run ()
524 {
525 global $Paramètres;
526
527/*
528 echo "
529<table>
530 <tr>
531 <td><center>
532 <b><i>Valeurs</i></b>
533 </center></td>
534 <td><center>
535 Twiss = {$Paramètres->twiss} Energie = {$Paramètres->énergie} Champ={$Paramètres->champ} Largeur = {$Paramètres->largeur}
536Epaisseur={$Paramètres->épaisseur}
537 </center></td>
538 </tr>
539</table>
540<hr>
541";
542*/
543
544 $steps = array ('Transport' => 'step1', 'EGS' => 'step2');
545
546 $this->init ();
547
548 $faisceaux = null;
549
550 foreach ($steps as $step => $action)
551 {
552 $faisceaux = $this->$action ($faisceaux);
553 }
554
555/*
556 foreach ($faisceaux as $n => $f)
557 {
558 echo "s[$n]={$f->nom}<br>";
559 }
560*/
561 $électrons = $faisceaux["electrons"];
562 $photons = $faisceaux["photons"];
563 $positrons = $faisceaux["positrons"];
564
565 $this->faisceaux_sortie ($électrons, $photons, $positrons);
566 }
567};
568
569$C = new Control ();
570
571$C->run ();
572
573
574?>