1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
/*******************************************************************************
*
* McStas, neutron ray-tracing package
* Copyright 1997-2002, All rights reserved
* Risoe National Laboratory, Roskilde, Denmark
* Institut Laue Langevin, Grenoble, France
*
* Component: Adapt_check
*
* %I
* Written by: Kristian Nielsen
* Date: 1999
* Origin: Risoe
*
* Optimization specifier for the Source_adapt component.
*
* %D
* This components works together with the Source_adapt component, and
* is used to define the criteria for selecting which neutrons are
* considered "good" in the adaptive algorithm. The name of the
* associated Source_adapt component in the instrument definition is
* given as parameter. The component is special in that its position
* does not matter; all neutrons that have not been absorbed prior to
* the component are considered "good".
*
* Example: Adapt_check(source_comp="MySource")
*
* %P
* source_comp: [string] The name of the Source_adapt component in the instrument definition.
*
* %E
*******************************************************************************/
DEFINE COMPONENT Adapt_check
SETTING PARAMETERS (string source_comp)
/* Neutron parameters: (x,y,z,vx,vy,vz,t,sx,sy,sz,p) */
DECLARE
%{
#ifndef ADAPT_TREE_LIB_H
#error Adapt_check : needs Source_adapt component and %include "adapt_tree-lib"
#endif
%}
TRACE
%{
double new_v, psi;
struct source_adapt *adpt = COMP_GETPAR3(Source_adapt, source_comp, adpt);
if(p == 0)
ABSORB;
psi = p/adpt->pi;
adpt->psi[adpt->idx] += psi;
adpt->psi_tot += psi/adpt->n[adpt->idx];
new_v = (1 - adpt->a_beta)*adpt->factor*adpt->psi[adpt->idx]/
(adpt->n[adpt->idx]*adpt->psi_tot) +
adpt->a_beta/adpt->num;
adapt_tree_add(adpt->atree, adpt->idx, new_v - adpt->atree->v[adpt->idx]);
%}
END
|