http = "http" . ((!empty($_SERVER['HTTPS'])) ? "s" : "") . ":";
$this->name = "//" . $_SERVER['SERVER_NAME'];
$this->uri = $_SERVER['REQUEST_URI'];
$this->script = $this->http . $this->name . $this->uri;
$pos = strpos ($this->uri, "/pspa.php");
$this->base = $this->http . $this->name . substr ($this->uri, 0, $pos);
}
};
$Paramètres = new Paramètres ();
class TRANSPORT
{
function TRANSPORT ()
{
}
function run ($faisceau, $cavité)
{
global $Paramètres;
$string = '';
$xml = new SimpleXMLElement($string);
$f = $xml->addChild ("faisceau");
$f->addAttribute ("twiss", $faisceau->twiss);
$f->addAttribute ("energie", $faisceau->énergie);
$c = $xml->addChild ("cavite");
$c->addAttribute ("longueur", $cavité->longueur);
$c->addAttribute ("champ", $cavité->champ);
$xml->asXML('transport.xml');
$sortie = new Faisceau ();
//$h = popen ("Transport.exe transport.data", "r");
$input = $Paramètres->base . "/Transport.php?data=transport.xml";
echo "Transport: input={$input}
";
$h = fopen ($input, "r");
if ($h)
{
echo "Transport ok
";
$s = '';
while (($buffer = fgets ($h)) !== false)
{
$buffer = trim ($buffer);
$s .= $buffer;
}
//echo htmlentities($s);
//echo "
";
$xml = new SimpleXMLElement($s);
//print_r ($xml);
//echo "
";
$f = $xml->faisceau;
$sortie->twiss = (double) $f['twiss'];
$sortie->énergie = (double) $f['energie'];
fclose ($h);
}
else
{
echo "impossible de lancer Transport
";
}
return ($sortie);
}
};
class EGS
{
function EGS ()
{
}
function run ($cible, $faisceau)
{
global $Paramètres;
$string = '';
$xml = new SimpleXMLElement($string);
$f = $xml->addChild ("faisceau");
$f->addAttribute ("twiss", $faisceau->twiss);
$f->addAttribute ("energie", $faisceau->énergie);
$c = $xml->addChild ("cible");
$c->addAttribute ("epaisseur", $cible->épaisseur);
$xml->asXML('egs.xml');
$sortie = array();
$f = new Faisceau ();
$first = true;
//$h = popen ("EGS.exe egs.data", "r");
$input = $Paramètres->base . "/EGS.php?data=egs.xml";
echo "EGS: input={$input}
";
$h = fopen ($input, "r");
if ($h)
{
echo "EGS ok
";
$s = '';
while (($buffer = fgets ($h)) !== false)
{
$buffer = trim ($buffer);
$s .= $buffer;
}
//echo htmlentities($s);
//echo "
";
$xml = new SimpleXMLElement($s);
foreach ($xml as $k => $v)
{
$nom = (string) $v;
$f = new Faisceau ($nom, (double) $v['twiss'], (double) $v['energie']);
$sortie[$f->nom] = $f;
}
fclose ($h);
}
return ($sortie);
}
};
class Control
{
function header ()
{
echo "
";
}
function get_post ()
{
global $_POST;
global $Paramètres;
foreach ($_POST as $cle => $value)
{
$words = explode ('_', $cle);
$n = count ($words);
$classe = $words[0];
$champ = '';
if ($n > 1) $champ = str_replace ($classe . '_', '', $cle);
if (is_array ($value))
{
$str = "cle=($cle) _POST[{$classe}.{$champ}]=";
}
else
{
$Paramètres->$cle = $value;
}
}
}
function faisceau_entrée ()
{
global $Paramètres;
echo "
Définition du faisceau d'entrée
|
Twiss
|
|
Energie
|
MeV
|
";
}
function cavité ()
{
global $Paramètres;
echo "
Définition de la cavité
|
Champ
|
MV/m
|
Longueur
|
m
|
";
}
function distribution ()
{
global $Paramètres;
echo "
Distribution des particules
|
Largeur
|
m
|
";
}
function cible ()
{
global $Paramètres;
echo "
Définition de la cible
|
Epaisseur
|
cm
|
";
}
function faisceaux_sortie ($électrons, $photons, $positrons)
{
global $Paramètres;
echo "
|
Sortie
|
|
Electrons
|
Twiss
|
{$électrons->twiss}
|
Energie
|
{$électrons->énergie} MeV
|
Photons
|
Twiss
|
{$photons->twiss}
|
Energie
|
{$photons->énergie} MeV
|
Positrons
|
Twiss
|
{$positrons->twiss}
|
Energie
|
{$positrons->énergie} MeV
|
";
}
function step1 ($faisceaux = null)
{
global $Paramètres;
echo "
";
echo "
|
";
echo "
TRANSPORT
|
";
$faisceau = new Faisceau ("", $Paramètres->twiss, $Paramètres->énergie);
$cavité = new Cavité ($Paramètres->champ, $Paramètres->longueur);
$transport = new TRANSPORT ();
$faisceau_intermédiaire = $transport->run ($faisceau, $cavité);
//echo "twiss={$faisceau_intermédiaire->twiss}
";
//echo "énergie={$faisceau_intermédiaire->énergie}
";
echo "
|
";
$sortie = array ("électrons" => $faisceau_intermédiaire);
return ($sortie);
}
function step2 ($faisceaux)
{
global $Paramètres;
$faisceau = NULL;
foreach ($faisceaux as $k => $f)
{
$faisceau = $f;
}
echo "
";
echo "
|
EGS
|
";
$cible = new Cible ($Paramètres->épaisseur);
$egs = new EGS ();
$sortie = $egs->run ($cible, $faisceau);
echo "
|
";
return ($sortie);
}
function init ()
{
global $Paramètres;
$this->get_post ();
$this->header ();
}
function run ()
{
global $Paramètres;
/*
echo "
Valeurs
|
Twiss = {$Paramètres->twiss} Energie = {$Paramètres->énergie} Champ={$Paramètres->champ} Largeur = {$Paramètres->largeur}
Epaisseur={$Paramètres->épaisseur}
|
";
*/
$steps = array ('Transport' => 'step1', 'EGS' => 'step2');
$this->init ();
$faisceaux = null;
foreach ($steps as $step => $action)
{
$faisceaux = $this->$action ($faisceaux);
}
/*
foreach ($faisceaux as $n => $f)
{
echo "s[$n]={$f->nom}
";
}
*/
$électrons = $faisceaux["electrons"];
$photons = $faisceaux["photons"];
$positrons = $faisceaux["positrons"];
$this->faisceaux_sortie ($électrons, $photons, $positrons);
}
};
$C = new Control ();
$C->run ();
?>