From 8b4d5c0ea96b150227c47c3851b76e59933b97f9 Mon Sep 17 00:00:00 2001 From: Peter Willendrup Date: Tue, 17 Feb 2026 19:23:14 +0100 Subject: [PATCH] Apply formatter to sasmodels --- .../sasmodels/SasView_adsorbed_layer.comp | 178 +++++++------- mcstas-comps/sasmodels/SasView_barbell.comp | 188 +++++++-------- .../sasmodels/SasView_barbell_aniso.comp | 205 ++++++++-------- .../sasmodels/SasView_bcc_paracrystal.comp | 178 +++++++------- .../SasView_bcc_paracrystal_aniso.comp | 203 ++++++++-------- .../sasmodels/SasView_binary_hard_sphere.comp | 182 +++++++------- .../sasmodels/SasView_broad_peak.comp | 178 +++++++------- .../sasmodels/SasView_capped_cylinder.comp | 188 +++++++-------- .../SasView_capped_cylinder_aniso.comp | 205 ++++++++-------- .../sasmodels/SasView_core_multi_shell.comp | 184 +++++++------- .../sasmodels/SasView_core_shell_bicelle.comp | 192 +++++++-------- .../SasView_core_shell_bicelle_aniso.comp | 209 ++++++++-------- ...SasView_core_shell_bicelle_elliptical.comp | 193 +++++++-------- ...w_core_shell_bicelle_elliptical_aniso.comp | 216 ++++++++--------- ...e_shell_bicelle_elliptical_belt_rough.comp | 193 +++++++-------- ...l_bicelle_elliptical_belt_rough_aniso.comp | 216 ++++++++--------- .../SasView_core_shell_cylinder.comp | 188 +++++++-------- .../SasView_core_shell_cylinder_aniso.comp | 205 ++++++++-------- .../SasView_core_shell_ellipsoid.comp | 184 +++++++------- .../SasView_core_shell_ellipsoid_aniso.comp | 201 ++++++++-------- .../SasView_core_shell_parallelepiped.comp | 201 ++++++++-------- ...sView_core_shell_parallelepiped_aniso.comp | 224 ++++++++---------- .../sasmodels/SasView_core_shell_sphere.comp | 184 +++++++------- .../sasmodels/SasView_correlation_length.comp | 178 +++++++------- mcstas-comps/sasmodels/SasView_cylinder.comp | 184 +++++++------- .../sasmodels/SasView_cylinder_aniso.comp | 201 ++++++++-------- mcstas-comps/sasmodels/SasView_dab.comp | 178 +++++++------- mcstas-comps/sasmodels/SasView_ellipsoid.comp | 184 +++++++------- .../sasmodels/SasView_ellipsoid_aniso.comp | 201 ++++++++-------- .../SasView_elliptical_cylinder.comp | 184 +++++++------- .../SasView_elliptical_cylinder_aniso.comp | 207 ++++++++-------- .../sasmodels/SasView_fcc_paracrystal.comp | 178 +++++++------- .../SasView_fcc_paracrystal_aniso.comp | 203 ++++++++-------- .../sasmodels/SasView_flexible_cylinder.comp | 186 +++++++-------- .../SasView_flexible_cylinder_elliptical.comp | 186 +++++++-------- mcstas-comps/sasmodels/SasView_fractal.comp | 182 +++++++------- .../sasmodels/SasView_fractal_core_shell.comp | 186 +++++++-------- .../sasmodels/SasView_fuzzy_sphere.comp | 180 +++++++------- .../sasmodels/SasView_gauss_lorentz_gel.comp | 182 +++++++------- .../sasmodels/SasView_gaussian_peak.comp | 169 ++++++------- mcstas-comps/sasmodels/SasView_gel_fit.comp | 182 +++++++------- mcstas-comps/sasmodels/SasView_guinier.comp | 178 +++++++------- .../sasmodels/SasView_guinier_porod.comp | 178 +++++++------- .../sasmodels/SasView_hardsphere.comp | 178 +++++++------- .../sasmodels/SasView_hayter_msa.comp | 182 +++++++------- .../sasmodels/SasView_hollow_cylinder.comp | 188 +++++++-------- .../SasView_hollow_cylinder_aniso.comp | 205 ++++++++-------- .../SasView_hollow_rectangular_prism.comp | 184 +++++++------- ...asView_hollow_rectangular_prism_aniso.comp | 207 ++++++++-------- ...w_hollow_rectangular_prism_thin_walls.comp | 180 +++++++------- .../sasmodels/SasView_lamellar_hg.comp | 182 +++++++------- .../SasView_lamellar_hg_stack_caille.comp | 182 +++++++------- .../SasView_lamellar_stack_caille.comp | 178 +++++++------- .../SasView_lamellar_stack_paracrystal.comp | 178 +++++++------- mcstas-comps/sasmodels/SasView_line.comp | 169 ++++++------- .../sasmodels/SasView_linear_pearls.comp | 178 +++++++------- mcstas-comps/sasmodels/SasView_lorentz.comp | 178 +++++++------- .../sasmodels/SasView_mass_fractal.comp | 182 +++++++------- .../SasView_mass_surface_fractal.comp | 182 +++++++------- .../sasmodels/SasView_mono_gauss_coil.comp | 178 +++++++------- .../sasmodels/SasView_multilayer_vesicle.comp | 188 +++++++-------- mcstas-comps/sasmodels/SasView_onion.comp | 184 +++++++------- .../sasmodels/SasView_parallelepiped.comp | 188 +++++++-------- .../SasView_parallelepiped_aniso.comp | 211 ++++++++--------- .../sasmodels/SasView_peak_lorentz.comp | 169 ++++++------- .../sasmodels/SasView_pearl_necklace.comp | 182 +++++++------- .../sasmodels/SasView_poly_gauss_coil.comp | 178 +++++++------- .../SasView_polymer_excl_volume.comp | 178 +++++++------- .../sasmodels/SasView_polymer_micelle.comp | 182 +++++++------- mcstas-comps/sasmodels/SasView_porod.comp | 169 ++++++------- mcstas-comps/sasmodels/SasView_power_law.comp | 169 ++++++------- mcstas-comps/sasmodels/SasView_pringle.comp | 182 +++++++------- mcstas-comps/sasmodels/SasView_raspberry.comp | 182 +++++++------- .../sasmodels/SasView_rectangular_prism.comp | 180 +++++++------- .../SasView_rectangular_prism_aniso.comp | 203 ++++++++-------- mcstas-comps/sasmodels/SasView_rpa.comp | 169 ++++++------- .../sasmodels/SasView_sc_paracrystal.comp | 178 +++++++------- .../SasView_sc_paracrystal_aniso.comp | 203 ++++++++-------- mcstas-comps/sasmodels/SasView_sphere.comp | 180 +++++++------- mcstas-comps/sasmodels/SasView_spinodal.comp | 169 ++++++------- .../sasmodels/SasView_squarewell.comp | 178 +++++++------- .../sasmodels/SasView_stacked_disks.comp | 186 +++++++-------- .../SasView_stacked_disks_aniso.comp | 205 ++++++++-------- .../sasmodels/SasView_star_polymer.comp | 178 +++++++------- .../sasmodels/SasView_stickyhardsphere.comp | 178 +++++++------- mcstas-comps/sasmodels/SasView_superball.comp | 180 +++++++------- .../sasmodels/SasView_superball_aniso.comp | 203 ++++++++-------- .../sasmodels/SasView_surface_fractal.comp | 182 +++++++------- .../sasmodels/SasView_teubner_strey.comp | 169 ++++++------- .../sasmodels/SasView_triaxial_ellipsoid.comp | 188 +++++++-------- .../SasView_triaxial_ellipsoid_aniso.comp | 211 ++++++++--------- .../sasmodels/SasView_two_lorentzian.comp | 182 +++++++------- .../sasmodels/SasView_two_power_law.comp | 169 ++++++------- mcstas-comps/sasmodels/SasView_vesicle.comp | 184 +++++++------- 94 files changed, 8041 insertions(+), 9509 deletions(-) diff --git a/mcstas-comps/sasmodels/SasView_adsorbed_layer.comp b/mcstas-comps/sasmodels/SasView_adsorbed_layer.comp index ec89b1568a..c4e36a2734 100644 --- a/mcstas-comps/sasmodels/SasView_adsorbed_layer.comp +++ b/mcstas-comps/sasmodels/SasView_adsorbed_layer.comp @@ -139,114 +139,108 @@ double Iq_adsorbed_layer( INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_radius=radius; - if ( pd_radius!=0.0 ){ - trace_radius = (randnorm()*pd_radius+1.0)*radius; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_radius = radius; + if (pd_radius != 0.0) { + trace_radius = (randnorm () * pd_radius + 1.0) * radius; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - Iq_out = Iq_adsorbed_layer(q, second_moment, adsorbed_amount, density_shell, trace_radius, volfraction, sld_shell, sld_solvent); - + Iq_out = Iq_adsorbed_layer (q, second_moment, adsorbed_amount, density_shell, trace_radius, volfraction, sld_shell, sld_solvent); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -254,40 +248,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_barbell.comp b/mcstas-comps/sasmodels/SasView_barbell.comp index 02cc11c30e..184ffd578e 100644 --- a/mcstas-comps/sasmodels/SasView_barbell.comp +++ b/mcstas-comps/sasmodels/SasView_barbell.comp @@ -799,120 +799,114 @@ Iqac_barbell(double qab, double qc, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_radius_bell=radius_bell; - double trace_radius=radius; - double trace_length=length; - if ( pd_radius_bell!=0.0 || pd_radius!=0.0 || pd_length!=0.0 ){ - trace_radius_bell = (randnorm()*pd_radius_bell+1.0)*radius_bell; - trace_radius = (randnorm()*pd_radius+1.0)*radius; - trace_length = (randnorm()*pd_length+1.0)*length; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_radius_bell = radius_bell; + double trace_radius = radius; + double trace_length = length; + if (pd_radius_bell != 0.0 || pd_radius != 0.0 || pd_length != 0.0) { + trace_radius_bell = (randnorm () * pd_radius_bell + 1.0) * radius_bell; + trace_radius = (randnorm () * pd_radius + 1.0) * radius; + trace_length = (randnorm () * pd_length + 1.0) * length; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - double F1=0.0, F2=0.0; - Fq_barbell(q, &F1, &F2, sld, sld_solvent, trace_radius_bell, trace_radius, trace_length); + double F1 = 0.0, F2 = 0.0; + Fq_barbell (q, &F1, &F2, sld, sld_solvent, trace_radius_bell, trace_radius, trace_length); Iq_out = F2; - float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -920,40 +914,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_barbell_aniso.comp b/mcstas-comps/sasmodels/SasView_barbell_aniso.comp index d405cfa571..503429302b 100644 --- a/mcstas-comps/sasmodels/SasView_barbell_aniso.comp +++ b/mcstas-comps/sasmodels/SasView_barbell_aniso.comp @@ -805,131 +805,126 @@ Iqac_barbell(double qab, double qc, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_radius_bell=radius_bell; - double trace_radius=radius; - double trace_length=length; - if ( pd_radius_bell!=0.0 || pd_radius!=0.0 || pd_length!=0.0 ){ - trace_radius_bell = (randnorm()*pd_radius_bell+1.0)*radius_bell; - trace_radius = (randnorm()*pd_radius+1.0)*radius; - trace_length = (randnorm()*pd_length+1.0)*length; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_radius_bell = radius_bell; + double trace_radius = radius; + double trace_length = length; + if (pd_radius_bell != 0.0 || pd_radius != 0.0 || pd_length != 0.0) { + trace_radius_bell = (randnorm () * pd_radius_bell + 1.0) * radius_bell; + trace_radius = (randnorm () * pd_radius + 1.0) * radius; + trace_length = (randnorm () * pd_length + 1.0) * length; } - - double trace_theta=theta, dtheta=0.0; - double trace_phi=phi, dphi=0.0; - if ( pd_theta!=0.0 || pd_phi!=0.0 ){ - trace_theta = ((rand01()-0.5)*pd_theta + 1.0)*theta; - dtheta = trace_theta-theta; - trace_phi = ((rand01()-0.5)*pd_phi + 1.0)*phi; - dphi = trace_phi-phi; + double trace_theta = theta, dtheta = 0.0; + double trace_phi = phi, dphi = 0.0; + if (pd_theta != 0.0 || pd_phi != 0.0) { + trace_theta = ((rand01 () - 0.5) * pd_theta + 1.0) * theta; + dtheta = trace_theta - theta; + trace_phi = ((rand01 () - 0.5) * pd_phi + 1.0) * phi; + dphi = trace_phi - phi; } - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - double qab=0.0, qc=0.0; + double qab = 0.0, qc = 0.0; QACRotation rotation; - qac_rotation(&rotation, trace_theta, trace_phi, dtheta, dphi); - qac_apply(&rotation, qx, qy, &qab, &qc); - Iq_out = Iqac_barbell(qab, qc, sld, sld_solvent, trace_radius_bell, trace_radius, trace_length ); - + qac_rotation (&rotation, trace_theta, trace_phi, dtheta, dphi); + qac_apply (&rotation, qx, qy, &qab, &qc); + Iq_out = Iqac_barbell (qab, qc, sld, sld_solvent, trace_radius_bell, trace_radius, trace_length); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -937,40 +932,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_bcc_paracrystal.comp b/mcstas-comps/sasmodels/SasView_bcc_paracrystal.comp index 61f75eeb47..df46354ad8 100644 --- a/mcstas-comps/sasmodels/SasView_bcc_paracrystal.comp +++ b/mcstas-comps/sasmodels/SasView_bcc_paracrystal.comp @@ -657,114 +657,108 @@ static double Iqabc_bcc_paracrystal(double qa, double qb, double qc, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_radius=radius; - if ( pd_radius!=0.0 ){ - trace_radius = (randnorm()*pd_radius+1.0)*radius; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_radius = radius; + if (pd_radius != 0.0) { + trace_radius = (randnorm () * pd_radius + 1.0) * radius; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - Iq_out = Iq_bcc_paracrystal(q, dnn, d_factor, trace_radius, sld, sld_solvent); - + Iq_out = Iq_bcc_paracrystal (q, dnn, d_factor, trace_radius, sld, sld_solvent); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -772,40 +766,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_bcc_paracrystal_aniso.comp b/mcstas-comps/sasmodels/SasView_bcc_paracrystal_aniso.comp index e47802f960..69c9a91052 100644 --- a/mcstas-comps/sasmodels/SasView_bcc_paracrystal_aniso.comp +++ b/mcstas-comps/sasmodels/SasView_bcc_paracrystal_aniso.comp @@ -666,130 +666,125 @@ static double Iqabc_bcc_paracrystal(double qa, double qb, double qc, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_radius=radius; - if ( pd_radius!=0.0 ){ - trace_radius = (randnorm()*pd_radius+1.0)*radius; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_radius = radius; + if (pd_radius != 0.0) { + trace_radius = (randnorm () * pd_radius + 1.0) * radius; } - - double trace_theta=theta, dtheta=0.0; - double trace_phi=phi, dphi=0.0; - double trace_Psi=Psi, dPsi=0.0; - if ( pd_theta!=0.0 || pd_phi!=0.0 || pd_Psi!=0.0 ){ - trace_theta = ((rand01()-0.5)*pd_theta + 1.0)*theta; - dtheta = trace_theta-theta; - trace_phi = ((rand01()-0.5)*pd_phi + 1.0)*phi; - dphi = trace_phi-phi; - trace_Psi = ((rand01()-0.5)*pd_Psi + 1.0)*Psi; - dPsi = trace_Psi-Psi; + double trace_theta = theta, dtheta = 0.0; + double trace_phi = phi, dphi = 0.0; + double trace_Psi = Psi, dPsi = 0.0; + if (pd_theta != 0.0 || pd_phi != 0.0 || pd_Psi != 0.0) { + trace_theta = ((rand01 () - 0.5) * pd_theta + 1.0) * theta; + dtheta = trace_theta - theta; + trace_phi = ((rand01 () - 0.5) * pd_phi + 1.0) * phi; + dphi = trace_phi - phi; + trace_Psi = ((rand01 () - 0.5) * pd_Psi + 1.0) * Psi; + dPsi = trace_Psi - Psi; } - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - double qa=0.0, qb=0.0, qc=0.0; + double qa = 0.0, qb = 0.0, qc = 0.0; QABCRotation rotation; - qabc_rotation(&rotation, trace_theta, trace_phi, trace_Psi, dtheta, dphi, dPsi); - qabc_apply(&rotation, qx, qy, &qa, &qb, &qc); - Iq_out = Iqabc_bcc_paracrystal(qa, qb, qc, dnn, d_factor, trace_radius, sld, sld_solvent ); - + qabc_rotation (&rotation, trace_theta, trace_phi, trace_Psi, dtheta, dphi, dPsi); + qabc_apply (&rotation, qx, qy, &qa, &qb, &qc); + Iq_out = Iqabc_bcc_paracrystal (qa, qb, qc, dnn, d_factor, trace_radius, sld, sld_solvent); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -797,40 +792,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_binary_hard_sphere.comp b/mcstas-comps/sasmodels/SasView_binary_hard_sphere.comp index 54a07e4459..3693ed4923 100644 --- a/mcstas-comps/sasmodels/SasView_binary_hard_sphere.comp +++ b/mcstas-comps/sasmodels/SasView_binary_hard_sphere.comp @@ -339,116 +339,110 @@ void calculate_psfs(double qval, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_radius_lg=radius_lg; - double trace_radius_sm=radius_sm; - if ( pd_radius_lg!=0.0 || pd_radius_sm!=0.0 ){ - trace_radius_lg = (randnorm()*pd_radius_lg+1.0)*radius_lg; - trace_radius_sm = (randnorm()*pd_radius_sm+1.0)*radius_sm; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_radius_lg = radius_lg; + double trace_radius_sm = radius_sm; + if (pd_radius_lg != 0.0 || pd_radius_sm != 0.0) { + trace_radius_lg = (randnorm () * pd_radius_lg + 1.0) * radius_lg; + trace_radius_sm = (randnorm () * pd_radius_sm + 1.0) * radius_sm; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - Iq_out = Iq_binary_hard_sphere(q, trace_radius_lg, trace_radius_sm, volfraction_lg, volfraction_sm, sld_lg, sld_sm, sld_solvent); - + Iq_out = Iq_binary_hard_sphere (q, trace_radius_lg, trace_radius_sm, volfraction_lg, volfraction_sm, sld_lg, sld_sm, sld_solvent); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -456,40 +450,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_broad_peak.comp b/mcstas-comps/sasmodels/SasView_broad_peak.comp index 7bad216bc5..5d34f6586b 100644 --- a/mcstas-comps/sasmodels/SasView_broad_peak.comp +++ b/mcstas-comps/sasmodels/SasView_broad_peak.comp @@ -126,114 +126,108 @@ double Iq_broad_peak(double q, double porod_scale, double porod_exp, double peak INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_correlation_length=correlation_length; - if ( pd_correlation_length!=0.0 ){ - trace_correlation_length = (randnorm()*pd_correlation_length+1.0)*correlation_length; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_correlation_length = correlation_length; + if (pd_correlation_length != 0.0) { + trace_correlation_length = (randnorm () * pd_correlation_length + 1.0) * correlation_length; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - Iq_out = Iq_broad_peak(q, porod_scale, porod_exp, peak_scale, trace_correlation_length, peak_pos, width_exp, shape_exp); - + Iq_out = Iq_broad_peak (q, porod_scale, porod_exp, peak_scale, trace_correlation_length, peak_pos, width_exp, shape_exp); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -241,40 +235,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_capped_cylinder.comp b/mcstas-comps/sasmodels/SasView_capped_cylinder.comp index c39227441f..84c2f82c7c 100644 --- a/mcstas-comps/sasmodels/SasView_capped_cylinder.comp +++ b/mcstas-comps/sasmodels/SasView_capped_cylinder.comp @@ -804,120 +804,114 @@ Iqac_capped_cylinder(double qab, double qc, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_radius=radius; - double trace_radius_cap=radius_cap; - double trace_length=length; - if ( pd_radius!=0.0 || pd_radius_cap!=0.0 || pd_length!=0.0 ){ - trace_radius = (randnorm()*pd_radius+1.0)*radius; - trace_radius_cap = (randnorm()*pd_radius_cap+1.0)*radius_cap; - trace_length = (randnorm()*pd_length+1.0)*length; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_radius = radius; + double trace_radius_cap = radius_cap; + double trace_length = length; + if (pd_radius != 0.0 || pd_radius_cap != 0.0 || pd_length != 0.0) { + trace_radius = (randnorm () * pd_radius + 1.0) * radius; + trace_radius_cap = (randnorm () * pd_radius_cap + 1.0) * radius_cap; + trace_length = (randnorm () * pd_length + 1.0) * length; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - double F1=0.0, F2=0.0; - Fq_capped_cylinder(q, &F1, &F2, sld, sld_solvent, trace_radius, trace_radius_cap, trace_length); + double F1 = 0.0, F2 = 0.0; + Fq_capped_cylinder (q, &F1, &F2, sld, sld_solvent, trace_radius, trace_radius_cap, trace_length); Iq_out = F2; - float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -925,40 +919,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_capped_cylinder_aniso.comp b/mcstas-comps/sasmodels/SasView_capped_cylinder_aniso.comp index ea963c23bf..612ee3f2c6 100644 --- a/mcstas-comps/sasmodels/SasView_capped_cylinder_aniso.comp +++ b/mcstas-comps/sasmodels/SasView_capped_cylinder_aniso.comp @@ -810,131 +810,126 @@ Iqac_capped_cylinder(double qab, double qc, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_radius=radius; - double trace_radius_cap=radius_cap; - double trace_length=length; - if ( pd_radius!=0.0 || pd_radius_cap!=0.0 || pd_length!=0.0 ){ - trace_radius = (randnorm()*pd_radius+1.0)*radius; - trace_radius_cap = (randnorm()*pd_radius_cap+1.0)*radius_cap; - trace_length = (randnorm()*pd_length+1.0)*length; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_radius = radius; + double trace_radius_cap = radius_cap; + double trace_length = length; + if (pd_radius != 0.0 || pd_radius_cap != 0.0 || pd_length != 0.0) { + trace_radius = (randnorm () * pd_radius + 1.0) * radius; + trace_radius_cap = (randnorm () * pd_radius_cap + 1.0) * radius_cap; + trace_length = (randnorm () * pd_length + 1.0) * length; } - - double trace_theta=theta, dtheta=0.0; - double trace_phi=phi, dphi=0.0; - if ( pd_theta!=0.0 || pd_phi!=0.0 ){ - trace_theta = ((rand01()-0.5)*pd_theta + 1.0)*theta; - dtheta = trace_theta-theta; - trace_phi = ((rand01()-0.5)*pd_phi + 1.0)*phi; - dphi = trace_phi-phi; + double trace_theta = theta, dtheta = 0.0; + double trace_phi = phi, dphi = 0.0; + if (pd_theta != 0.0 || pd_phi != 0.0) { + trace_theta = ((rand01 () - 0.5) * pd_theta + 1.0) * theta; + dtheta = trace_theta - theta; + trace_phi = ((rand01 () - 0.5) * pd_phi + 1.0) * phi; + dphi = trace_phi - phi; } - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - double qab=0.0, qc=0.0; + double qab = 0.0, qc = 0.0; QACRotation rotation; - qac_rotation(&rotation, trace_theta, trace_phi, dtheta, dphi); - qac_apply(&rotation, qx, qy, &qab, &qc); - Iq_out = Iqac_capped_cylinder(qab, qc, sld, sld_solvent, trace_radius, trace_radius_cap, trace_length ); - + qac_rotation (&rotation, trace_theta, trace_phi, dtheta, dphi); + qac_apply (&rotation, qx, qy, &qab, &qc); + Iq_out = Iqac_capped_cylinder (qab, qc, sld, sld_solvent, trace_radius, trace_radius_cap, trace_length); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -942,40 +937,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_core_multi_shell.comp b/mcstas-comps/sasmodels/SasView_core_multi_shell.comp index 77fa8ded3b..1ecd7baa01 100644 --- a/mcstas-comps/sasmodels/SasView_core_multi_shell.comp +++ b/mcstas-comps/sasmodels/SasView_core_multi_shell.comp @@ -233,118 +233,112 @@ Fq_core_multi_shell(double q, double *F1, double *F2, double core_sld, double co INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_radius=radius; - double trace_thickness[n]=thickness[n]; - if ( pd_radius!=0.0 || pd_thickness[n]!=0.0 ){ - trace_radius = (randnorm()*pd_radius+1.0)*radius; - trace_thickness[n] = (randnorm()*pd_thickness[n]+1.0)*thickness[n]; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_radius = radius; + double trace_thickness[n] = thickness[n]; + if (pd_radius != 0.0 || pd_thickness[n] != 0.0) { + trace_radius = (randnorm () * pd_radius + 1.0) * radius; + trace_thickness[n] = (randnorm () * pd_thickness[n] + 1.0) * thickness[n]; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - double F1=0.0, F2=0.0; - Fq_core_multi_shell(q, &F1, &F2, sld_core, trace_radius, sld_solvent, n, sld[n], trace_thickness[n]); + double F1 = 0.0, F2 = 0.0; + Fq_core_multi_shell (q, &F1, &F2, sld_core, trace_radius, sld_solvent, n, sld[n], trace_thickness[n]); Iq_out = F2; - float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -352,40 +346,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_core_shell_bicelle.comp b/mcstas-comps/sasmodels/SasView_core_shell_bicelle.comp index 2814461048..9aa62f6546 100644 --- a/mcstas-comps/sasmodels/SasView_core_shell_bicelle.comp +++ b/mcstas-comps/sasmodels/SasView_core_shell_bicelle.comp @@ -823,122 +823,116 @@ Iqac_core_shell_bicelle(double qab, double qc, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_radius=radius; - double trace_thick_rim=thick_rim; - double trace_thick_face=thick_face; - double trace_length=length; - if ( pd_radius!=0.0 || pd_thick_rim!=0.0 || pd_thick_face!=0.0 || pd_length!=0.0 ){ - trace_radius = (randnorm()*pd_radius+1.0)*radius; - trace_thick_rim = (randnorm()*pd_thick_rim+1.0)*thick_rim; - trace_thick_face = (randnorm()*pd_thick_face+1.0)*thick_face; - trace_length = (randnorm()*pd_length+1.0)*length; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_radius = radius; + double trace_thick_rim = thick_rim; + double trace_thick_face = thick_face; + double trace_length = length; + if (pd_radius != 0.0 || pd_thick_rim != 0.0 || pd_thick_face != 0.0 || pd_length != 0.0) { + trace_radius = (randnorm () * pd_radius + 1.0) * radius; + trace_thick_rim = (randnorm () * pd_thick_rim + 1.0) * thick_rim; + trace_thick_face = (randnorm () * pd_thick_face + 1.0) * thick_face; + trace_length = (randnorm () * pd_length + 1.0) * length; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - double F1=0.0, F2=0.0; - Fq_core_shell_bicelle(q, &F1, &F2, trace_radius, trace_thick_rim, trace_thick_face, trace_length, sld_core, sld_face, sld_rim, sld_solvent); + double F1 = 0.0, F2 = 0.0; + Fq_core_shell_bicelle (q, &F1, &F2, trace_radius, trace_thick_rim, trace_thick_face, trace_length, sld_core, sld_face, sld_rim, sld_solvent); Iq_out = F2; - float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -946,40 +940,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_core_shell_bicelle_aniso.comp b/mcstas-comps/sasmodels/SasView_core_shell_bicelle_aniso.comp index 649c4937b0..244b725b2e 100644 --- a/mcstas-comps/sasmodels/SasView_core_shell_bicelle_aniso.comp +++ b/mcstas-comps/sasmodels/SasView_core_shell_bicelle_aniso.comp @@ -829,133 +829,128 @@ Iqac_core_shell_bicelle(double qab, double qc, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_radius=radius; - double trace_thick_rim=thick_rim; - double trace_thick_face=thick_face; - double trace_length=length; - if ( pd_radius!=0.0 || pd_thick_rim!=0.0 || pd_thick_face!=0.0 || pd_length!=0.0 ){ - trace_radius = (randnorm()*pd_radius+1.0)*radius; - trace_thick_rim = (randnorm()*pd_thick_rim+1.0)*thick_rim; - trace_thick_face = (randnorm()*pd_thick_face+1.0)*thick_face; - trace_length = (randnorm()*pd_length+1.0)*length; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_radius = radius; + double trace_thick_rim = thick_rim; + double trace_thick_face = thick_face; + double trace_length = length; + if (pd_radius != 0.0 || pd_thick_rim != 0.0 || pd_thick_face != 0.0 || pd_length != 0.0) { + trace_radius = (randnorm () * pd_radius + 1.0) * radius; + trace_thick_rim = (randnorm () * pd_thick_rim + 1.0) * thick_rim; + trace_thick_face = (randnorm () * pd_thick_face + 1.0) * thick_face; + trace_length = (randnorm () * pd_length + 1.0) * length; } - - double trace_theta=theta, dtheta=0.0; - double trace_phi=phi, dphi=0.0; - if ( pd_theta!=0.0 || pd_phi!=0.0 ){ - trace_theta = ((rand01()-0.5)*pd_theta + 1.0)*theta; - dtheta = trace_theta-theta; - trace_phi = ((rand01()-0.5)*pd_phi + 1.0)*phi; - dphi = trace_phi-phi; + double trace_theta = theta, dtheta = 0.0; + double trace_phi = phi, dphi = 0.0; + if (pd_theta != 0.0 || pd_phi != 0.0) { + trace_theta = ((rand01 () - 0.5) * pd_theta + 1.0) * theta; + dtheta = trace_theta - theta; + trace_phi = ((rand01 () - 0.5) * pd_phi + 1.0) * phi; + dphi = trace_phi - phi; } - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - double qab=0.0, qc=0.0; + double qab = 0.0, qc = 0.0; QACRotation rotation; - qac_rotation(&rotation, trace_theta, trace_phi, dtheta, dphi); - qac_apply(&rotation, qx, qy, &qab, &qc); - Iq_out = Iqac_core_shell_bicelle(qab, qc, trace_radius, trace_thick_rim, trace_thick_face, trace_length, sld_core, sld_face, sld_rim, sld_solvent ); - + qac_rotation (&rotation, trace_theta, trace_phi, dtheta, dphi); + qac_apply (&rotation, qx, qy, &qab, &qc); + Iq_out = Iqac_core_shell_bicelle (qab, qc, trace_radius, trace_thick_rim, trace_thick_face, trace_length, sld_core, sld_face, sld_rim, sld_solvent); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -963,40 +958,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_core_shell_bicelle_elliptical.comp b/mcstas-comps/sasmodels/SasView_core_shell_bicelle_elliptical.comp index d6b14ca430..a72f2bd20c 100644 --- a/mcstas-comps/sasmodels/SasView_core_shell_bicelle_elliptical.comp +++ b/mcstas-comps/sasmodels/SasView_core_shell_bicelle_elliptical.comp @@ -850,122 +850,117 @@ Iqabc_core_shell_bicelle_elliptical(double qa, double qb, double qc, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_radius=radius; - double trace_thick_rim=thick_rim; - double trace_thick_face=thick_face; - double trace_length=length; - if ( pd_radius!=0.0 || pd_thick_rim!=0.0 || pd_thick_face!=0.0 || pd_length!=0.0 ){ - trace_radius = (randnorm()*pd_radius+1.0)*radius; - trace_thick_rim = (randnorm()*pd_thick_rim+1.0)*thick_rim; - trace_thick_face = (randnorm()*pd_thick_face+1.0)*thick_face; - trace_length = (randnorm()*pd_length+1.0)*length; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_radius = radius; + double trace_thick_rim = thick_rim; + double trace_thick_face = thick_face; + double trace_length = length; + if (pd_radius != 0.0 || pd_thick_rim != 0.0 || pd_thick_face != 0.0 || pd_length != 0.0) { + trace_radius = (randnorm () * pd_radius + 1.0) * radius; + trace_thick_rim = (randnorm () * pd_thick_rim + 1.0) * thick_rim; + trace_thick_face = (randnorm () * pd_thick_face + 1.0) * thick_face; + trace_length = (randnorm () * pd_length + 1.0) * length; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - double F1=0.0, F2=0.0; - Fq_core_shell_bicelle_elliptical(q, &F1, &F2, trace_radius, x_core, trace_thick_rim, trace_thick_face, trace_length, sld_core, sld_face, sld_rim, sld_solvent); + double F1 = 0.0, F2 = 0.0; + Fq_core_shell_bicelle_elliptical (q, &F1, &F2, trace_radius, x_core, trace_thick_rim, trace_thick_face, trace_length, sld_core, sld_face, sld_rim, + sld_solvent); Iq_out = F2; - float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -973,40 +968,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_core_shell_bicelle_elliptical_aniso.comp b/mcstas-comps/sasmodels/SasView_core_shell_bicelle_elliptical_aniso.comp index 732c362cbb..953f7e8202 100644 --- a/mcstas-comps/sasmodels/SasView_core_shell_bicelle_elliptical_aniso.comp +++ b/mcstas-comps/sasmodels/SasView_core_shell_bicelle_elliptical_aniso.comp @@ -859,136 +859,132 @@ Iqabc_core_shell_bicelle_elliptical(double qa, double qb, double qc, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_radius=radius; - double trace_thick_rim=thick_rim; - double trace_thick_face=thick_face; - double trace_length=length; - if ( pd_radius!=0.0 || pd_thick_rim!=0.0 || pd_thick_face!=0.0 || pd_length!=0.0 ){ - trace_radius = (randnorm()*pd_radius+1.0)*radius; - trace_thick_rim = (randnorm()*pd_thick_rim+1.0)*thick_rim; - trace_thick_face = (randnorm()*pd_thick_face+1.0)*thick_face; - trace_length = (randnorm()*pd_length+1.0)*length; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_radius = radius; + double trace_thick_rim = thick_rim; + double trace_thick_face = thick_face; + double trace_length = length; + if (pd_radius != 0.0 || pd_thick_rim != 0.0 || pd_thick_face != 0.0 || pd_length != 0.0) { + trace_radius = (randnorm () * pd_radius + 1.0) * radius; + trace_thick_rim = (randnorm () * pd_thick_rim + 1.0) * thick_rim; + trace_thick_face = (randnorm () * pd_thick_face + 1.0) * thick_face; + trace_length = (randnorm () * pd_length + 1.0) * length; } - - double trace_theta=theta, dtheta=0.0; - double trace_phi=phi, dphi=0.0; - double trace_Psi=Psi, dPsi=0.0; - if ( pd_theta!=0.0 || pd_phi!=0.0 || pd_Psi!=0.0 ){ - trace_theta = ((rand01()-0.5)*pd_theta + 1.0)*theta; - dtheta = trace_theta-theta; - trace_phi = ((rand01()-0.5)*pd_phi + 1.0)*phi; - dphi = trace_phi-phi; - trace_Psi = ((rand01()-0.5)*pd_Psi + 1.0)*Psi; - dPsi = trace_Psi-Psi; + double trace_theta = theta, dtheta = 0.0; + double trace_phi = phi, dphi = 0.0; + double trace_Psi = Psi, dPsi = 0.0; + if (pd_theta != 0.0 || pd_phi != 0.0 || pd_Psi != 0.0) { + trace_theta = ((rand01 () - 0.5) * pd_theta + 1.0) * theta; + dtheta = trace_theta - theta; + trace_phi = ((rand01 () - 0.5) * pd_phi + 1.0) * phi; + dphi = trace_phi - phi; + trace_Psi = ((rand01 () - 0.5) * pd_Psi + 1.0) * Psi; + dPsi = trace_Psi - Psi; } - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - double qa=0.0, qb=0.0, qc=0.0; + double qa = 0.0, qb = 0.0, qc = 0.0; QABCRotation rotation; - qabc_rotation(&rotation, trace_theta, trace_phi, trace_Psi, dtheta, dphi, dPsi); - qabc_apply(&rotation, qx, qy, &qa, &qb, &qc); - Iq_out = Iqabc_core_shell_bicelle_elliptical(qa, qb, qc, trace_radius, x_core, trace_thick_rim, trace_thick_face, trace_length, sld_core, sld_face, sld_rim, sld_solvent ); - + qabc_rotation (&rotation, trace_theta, trace_phi, trace_Psi, dtheta, dphi, dPsi); + qabc_apply (&rotation, qx, qy, &qa, &qb, &qc); + Iq_out = Iqabc_core_shell_bicelle_elliptical (qa, qb, qc, trace_radius, x_core, trace_thick_rim, trace_thick_face, trace_length, sld_core, sld_face, sld_rim, + sld_solvent); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -996,40 +992,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_core_shell_bicelle_elliptical_belt_rough.comp b/mcstas-comps/sasmodels/SasView_core_shell_bicelle_elliptical_belt_rough.comp index 7e556a68e2..08f184a2e7 100644 --- a/mcstas-comps/sasmodels/SasView_core_shell_bicelle_elliptical_belt_rough.comp +++ b/mcstas-comps/sasmodels/SasView_core_shell_bicelle_elliptical_belt_rough.comp @@ -869,122 +869,117 @@ Iqabc_core_shell_bicelle_elliptical_belt_rough(double qa, double qb, double qc, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_radius=radius; - double trace_thick_rim=thick_rim; - double trace_thick_face=thick_face; - double trace_length=length; - if ( pd_radius!=0.0 || pd_thick_rim!=0.0 || pd_thick_face!=0.0 || pd_length!=0.0 ){ - trace_radius = (randnorm()*pd_radius+1.0)*radius; - trace_thick_rim = (randnorm()*pd_thick_rim+1.0)*thick_rim; - trace_thick_face = (randnorm()*pd_thick_face+1.0)*thick_face; - trace_length = (randnorm()*pd_length+1.0)*length; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_radius = radius; + double trace_thick_rim = thick_rim; + double trace_thick_face = thick_face; + double trace_length = length; + if (pd_radius != 0.0 || pd_thick_rim != 0.0 || pd_thick_face != 0.0 || pd_length != 0.0) { + trace_radius = (randnorm () * pd_radius + 1.0) * radius; + trace_thick_rim = (randnorm () * pd_thick_rim + 1.0) * thick_rim; + trace_thick_face = (randnorm () * pd_thick_face + 1.0) * thick_face; + trace_length = (randnorm () * pd_length + 1.0) * length; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - double F1=0.0, F2=0.0; - Fq_core_shell_bicelle_elliptical_belt_rough(q, &F1, &F2, trace_radius, x_core, trace_thick_rim, trace_thick_face, trace_length, sld_core, sld_face, sld_rim, sld_solvent, sigma); + double F1 = 0.0, F2 = 0.0; + Fq_core_shell_bicelle_elliptical_belt_rough (q, &F1, &F2, trace_radius, x_core, trace_thick_rim, trace_thick_face, trace_length, sld_core, sld_face, sld_rim, + sld_solvent, sigma); Iq_out = F2; - float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -992,40 +987,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_core_shell_bicelle_elliptical_belt_rough_aniso.comp b/mcstas-comps/sasmodels/SasView_core_shell_bicelle_elliptical_belt_rough_aniso.comp index e5b46b716c..e16cd073e5 100644 --- a/mcstas-comps/sasmodels/SasView_core_shell_bicelle_elliptical_belt_rough_aniso.comp +++ b/mcstas-comps/sasmodels/SasView_core_shell_bicelle_elliptical_belt_rough_aniso.comp @@ -878,136 +878,132 @@ Iqabc_core_shell_bicelle_elliptical_belt_rough(double qa, double qb, double qc, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_radius=radius; - double trace_thick_rim=thick_rim; - double trace_thick_face=thick_face; - double trace_length=length; - if ( pd_radius!=0.0 || pd_thick_rim!=0.0 || pd_thick_face!=0.0 || pd_length!=0.0 ){ - trace_radius = (randnorm()*pd_radius+1.0)*radius; - trace_thick_rim = (randnorm()*pd_thick_rim+1.0)*thick_rim; - trace_thick_face = (randnorm()*pd_thick_face+1.0)*thick_face; - trace_length = (randnorm()*pd_length+1.0)*length; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_radius = radius; + double trace_thick_rim = thick_rim; + double trace_thick_face = thick_face; + double trace_length = length; + if (pd_radius != 0.0 || pd_thick_rim != 0.0 || pd_thick_face != 0.0 || pd_length != 0.0) { + trace_radius = (randnorm () * pd_radius + 1.0) * radius; + trace_thick_rim = (randnorm () * pd_thick_rim + 1.0) * thick_rim; + trace_thick_face = (randnorm () * pd_thick_face + 1.0) * thick_face; + trace_length = (randnorm () * pd_length + 1.0) * length; } - - double trace_theta=theta, dtheta=0.0; - double trace_phi=phi, dphi=0.0; - double trace_Psi=Psi, dPsi=0.0; - if ( pd_theta!=0.0 || pd_phi!=0.0 || pd_Psi!=0.0 ){ - trace_theta = ((rand01()-0.5)*pd_theta + 1.0)*theta; - dtheta = trace_theta-theta; - trace_phi = ((rand01()-0.5)*pd_phi + 1.0)*phi; - dphi = trace_phi-phi; - trace_Psi = ((rand01()-0.5)*pd_Psi + 1.0)*Psi; - dPsi = trace_Psi-Psi; + double trace_theta = theta, dtheta = 0.0; + double trace_phi = phi, dphi = 0.0; + double trace_Psi = Psi, dPsi = 0.0; + if (pd_theta != 0.0 || pd_phi != 0.0 || pd_Psi != 0.0) { + trace_theta = ((rand01 () - 0.5) * pd_theta + 1.0) * theta; + dtheta = trace_theta - theta; + trace_phi = ((rand01 () - 0.5) * pd_phi + 1.0) * phi; + dphi = trace_phi - phi; + trace_Psi = ((rand01 () - 0.5) * pd_Psi + 1.0) * Psi; + dPsi = trace_Psi - Psi; } - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - double qa=0.0, qb=0.0, qc=0.0; + double qa = 0.0, qb = 0.0, qc = 0.0; QABCRotation rotation; - qabc_rotation(&rotation, trace_theta, trace_phi, trace_Psi, dtheta, dphi, dPsi); - qabc_apply(&rotation, qx, qy, &qa, &qb, &qc); - Iq_out = Iqabc_core_shell_bicelle_elliptical_belt_rough(qa, qb, qc, trace_radius, x_core, trace_thick_rim, trace_thick_face, trace_length, sld_core, sld_face, sld_rim, sld_solvent, sigma ); - + qabc_rotation (&rotation, trace_theta, trace_phi, trace_Psi, dtheta, dphi, dPsi); + qabc_apply (&rotation, qx, qy, &qa, &qb, &qc); + Iq_out = Iqabc_core_shell_bicelle_elliptical_belt_rough (qa, qb, qc, trace_radius, x_core, trace_thick_rim, trace_thick_face, trace_length, sld_core, + sld_face, sld_rim, sld_solvent, sigma); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -1015,40 +1011,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_core_shell_cylinder.comp b/mcstas-comps/sasmodels/SasView_core_shell_cylinder.comp index dc2c5938eb..ecc2ebd0d2 100644 --- a/mcstas-comps/sasmodels/SasView_core_shell_cylinder.comp +++ b/mcstas-comps/sasmodels/SasView_core_shell_cylinder.comp @@ -769,120 +769,114 @@ Iqac_core_shell_cylinder(double qab, double qc, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_radius=radius; - double trace_thickness=thickness; - double trace_length=length; - if ( pd_radius!=0.0 || pd_thickness!=0.0 || pd_length!=0.0 ){ - trace_radius = (randnorm()*pd_radius+1.0)*radius; - trace_thickness = (randnorm()*pd_thickness+1.0)*thickness; - trace_length = (randnorm()*pd_length+1.0)*length; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_radius = radius; + double trace_thickness = thickness; + double trace_length = length; + if (pd_radius != 0.0 || pd_thickness != 0.0 || pd_length != 0.0) { + trace_radius = (randnorm () * pd_radius + 1.0) * radius; + trace_thickness = (randnorm () * pd_thickness + 1.0) * thickness; + trace_length = (randnorm () * pd_length + 1.0) * length; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - double F1=0.0, F2=0.0; - Fq_core_shell_cylinder(q, &F1, &F2, sld_core, sld_shell, sld_solvent, trace_radius, trace_thickness, trace_length); + double F1 = 0.0, F2 = 0.0; + Fq_core_shell_cylinder (q, &F1, &F2, sld_core, sld_shell, sld_solvent, trace_radius, trace_thickness, trace_length); Iq_out = F2; - float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -890,40 +884,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_core_shell_cylinder_aniso.comp b/mcstas-comps/sasmodels/SasView_core_shell_cylinder_aniso.comp index b05981fafa..52b992bf4f 100644 --- a/mcstas-comps/sasmodels/SasView_core_shell_cylinder_aniso.comp +++ b/mcstas-comps/sasmodels/SasView_core_shell_cylinder_aniso.comp @@ -775,131 +775,126 @@ Iqac_core_shell_cylinder(double qab, double qc, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_radius=radius; - double trace_thickness=thickness; - double trace_length=length; - if ( pd_radius!=0.0 || pd_thickness!=0.0 || pd_length!=0.0 ){ - trace_radius = (randnorm()*pd_radius+1.0)*radius; - trace_thickness = (randnorm()*pd_thickness+1.0)*thickness; - trace_length = (randnorm()*pd_length+1.0)*length; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_radius = radius; + double trace_thickness = thickness; + double trace_length = length; + if (pd_radius != 0.0 || pd_thickness != 0.0 || pd_length != 0.0) { + trace_radius = (randnorm () * pd_radius + 1.0) * radius; + trace_thickness = (randnorm () * pd_thickness + 1.0) * thickness; + trace_length = (randnorm () * pd_length + 1.0) * length; } - - double trace_theta=theta, dtheta=0.0; - double trace_phi=phi, dphi=0.0; - if ( pd_theta!=0.0 || pd_phi!=0.0 ){ - trace_theta = ((rand01()-0.5)*pd_theta + 1.0)*theta; - dtheta = trace_theta-theta; - trace_phi = ((rand01()-0.5)*pd_phi + 1.0)*phi; - dphi = trace_phi-phi; + double trace_theta = theta, dtheta = 0.0; + double trace_phi = phi, dphi = 0.0; + if (pd_theta != 0.0 || pd_phi != 0.0) { + trace_theta = ((rand01 () - 0.5) * pd_theta + 1.0) * theta; + dtheta = trace_theta - theta; + trace_phi = ((rand01 () - 0.5) * pd_phi + 1.0) * phi; + dphi = trace_phi - phi; } - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - double qab=0.0, qc=0.0; + double qab = 0.0, qc = 0.0; QACRotation rotation; - qac_rotation(&rotation, trace_theta, trace_phi, dtheta, dphi); - qac_apply(&rotation, qx, qy, &qab, &qc); - Iq_out = Iqac_core_shell_cylinder(qab, qc, sld_core, sld_shell, sld_solvent, trace_radius, trace_thickness, trace_length ); - + qac_rotation (&rotation, trace_theta, trace_phi, dtheta, dphi); + qac_apply (&rotation, qx, qy, &qab, &qc); + Iq_out = Iqac_core_shell_cylinder (qab, qc, sld_core, sld_shell, sld_solvent, trace_radius, trace_thickness, trace_length); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -907,40 +902,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_core_shell_ellipsoid.comp b/mcstas-comps/sasmodels/SasView_core_shell_ellipsoid.comp index c88e1962ea..7a4ec1600d 100644 --- a/mcstas-comps/sasmodels/SasView_core_shell_ellipsoid.comp +++ b/mcstas-comps/sasmodels/SasView_core_shell_ellipsoid.comp @@ -515,118 +515,112 @@ Iqac_core_shell_ellipsoid(double qab, double qc, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_radius_equat_core=radius_equat_core; - double trace_thick_shell=thick_shell; - if ( pd_radius_equat_core!=0.0 || pd_thick_shell!=0.0 ){ - trace_radius_equat_core = (randnorm()*pd_radius_equat_core+1.0)*radius_equat_core; - trace_thick_shell = (randnorm()*pd_thick_shell+1.0)*thick_shell; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_radius_equat_core = radius_equat_core; + double trace_thick_shell = thick_shell; + if (pd_radius_equat_core != 0.0 || pd_thick_shell != 0.0) { + trace_radius_equat_core = (randnorm () * pd_radius_equat_core + 1.0) * radius_equat_core; + trace_thick_shell = (randnorm () * pd_thick_shell + 1.0) * thick_shell; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - double F1=0.0, F2=0.0; - Fq_core_shell_ellipsoid(q, &F1, &F2, trace_radius_equat_core, x_core, trace_thick_shell, x_polar_shell, sld_core, sld_shell, sld_solvent); + double F1 = 0.0, F2 = 0.0; + Fq_core_shell_ellipsoid (q, &F1, &F2, trace_radius_equat_core, x_core, trace_thick_shell, x_polar_shell, sld_core, sld_shell, sld_solvent); Iq_out = F2; - float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -634,40 +628,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_core_shell_ellipsoid_aniso.comp b/mcstas-comps/sasmodels/SasView_core_shell_ellipsoid_aniso.comp index 1574494eeb..16998ce258 100644 --- a/mcstas-comps/sasmodels/SasView_core_shell_ellipsoid_aniso.comp +++ b/mcstas-comps/sasmodels/SasView_core_shell_ellipsoid_aniso.comp @@ -521,129 +521,124 @@ Iqac_core_shell_ellipsoid(double qab, double qc, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_radius_equat_core=radius_equat_core; - double trace_thick_shell=thick_shell; - if ( pd_radius_equat_core!=0.0 || pd_thick_shell!=0.0 ){ - trace_radius_equat_core = (randnorm()*pd_radius_equat_core+1.0)*radius_equat_core; - trace_thick_shell = (randnorm()*pd_thick_shell+1.0)*thick_shell; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_radius_equat_core = radius_equat_core; + double trace_thick_shell = thick_shell; + if (pd_radius_equat_core != 0.0 || pd_thick_shell != 0.0) { + trace_radius_equat_core = (randnorm () * pd_radius_equat_core + 1.0) * radius_equat_core; + trace_thick_shell = (randnorm () * pd_thick_shell + 1.0) * thick_shell; } - - double trace_theta=theta, dtheta=0.0; - double trace_phi=phi, dphi=0.0; - if ( pd_theta!=0.0 || pd_phi!=0.0 ){ - trace_theta = ((rand01()-0.5)*pd_theta + 1.0)*theta; - dtheta = trace_theta-theta; - trace_phi = ((rand01()-0.5)*pd_phi + 1.0)*phi; - dphi = trace_phi-phi; + double trace_theta = theta, dtheta = 0.0; + double trace_phi = phi, dphi = 0.0; + if (pd_theta != 0.0 || pd_phi != 0.0) { + trace_theta = ((rand01 () - 0.5) * pd_theta + 1.0) * theta; + dtheta = trace_theta - theta; + trace_phi = ((rand01 () - 0.5) * pd_phi + 1.0) * phi; + dphi = trace_phi - phi; } - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - double qab=0.0, qc=0.0; + double qab = 0.0, qc = 0.0; QACRotation rotation; - qac_rotation(&rotation, trace_theta, trace_phi, dtheta, dphi); - qac_apply(&rotation, qx, qy, &qab, &qc); - Iq_out = Iqac_core_shell_ellipsoid(qab, qc, trace_radius_equat_core, x_core, trace_thick_shell, x_polar_shell, sld_core, sld_shell, sld_solvent ); - + qac_rotation (&rotation, trace_theta, trace_phi, dtheta, dphi); + qac_apply (&rotation, qx, qy, &qab, &qc); + Iq_out = Iqac_core_shell_ellipsoid (qab, qc, trace_radius_equat_core, x_core, trace_thick_shell, x_polar_shell, sld_core, sld_shell, sld_solvent); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -651,40 +646,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_core_shell_parallelepiped.comp b/mcstas-comps/sasmodels/SasView_core_shell_parallelepiped.comp index b3739eb1c7..d93b8b5455 100644 --- a/mcstas-comps/sasmodels/SasView_core_shell_parallelepiped.comp +++ b/mcstas-comps/sasmodels/SasView_core_shell_parallelepiped.comp @@ -539,126 +539,121 @@ Iqabc_core_shell_parallelepiped(double qa, double qb, double qc, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_length_a=length_a; - double trace_length_b=length_b; - double trace_length_c=length_c; - double trace_thick_rim_a=thick_rim_a; - double trace_thick_rim_b=thick_rim_b; - double trace_thick_rim_c=thick_rim_c; - if ( pd_length_a!=0.0 || pd_length_b!=0.0 || pd_length_c!=0.0 || pd_thick_rim_a!=0.0 || pd_thick_rim_b!=0.0 || pd_thick_rim_c!=0.0 ){ - trace_length_a = (randnorm()*pd_length_a+1.0)*length_a; - trace_length_b = (randnorm()*pd_length_b+1.0)*length_b; - trace_length_c = (randnorm()*pd_length_c+1.0)*length_c; - trace_thick_rim_a = (randnorm()*pd_thick_rim_a+1.0)*thick_rim_a; - trace_thick_rim_b = (randnorm()*pd_thick_rim_b+1.0)*thick_rim_b; - trace_thick_rim_c = (randnorm()*pd_thick_rim_c+1.0)*thick_rim_c; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_length_a = length_a; + double trace_length_b = length_b; + double trace_length_c = length_c; + double trace_thick_rim_a = thick_rim_a; + double trace_thick_rim_b = thick_rim_b; + double trace_thick_rim_c = thick_rim_c; + if (pd_length_a != 0.0 || pd_length_b != 0.0 || pd_length_c != 0.0 || pd_thick_rim_a != 0.0 || pd_thick_rim_b != 0.0 || pd_thick_rim_c != 0.0) { + trace_length_a = (randnorm () * pd_length_a + 1.0) * length_a; + trace_length_b = (randnorm () * pd_length_b + 1.0) * length_b; + trace_length_c = (randnorm () * pd_length_c + 1.0) * length_c; + trace_thick_rim_a = (randnorm () * pd_thick_rim_a + 1.0) * thick_rim_a; + trace_thick_rim_b = (randnorm () * pd_thick_rim_b + 1.0) * thick_rim_b; + trace_thick_rim_c = (randnorm () * pd_thick_rim_c + 1.0) * thick_rim_c; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - double F1=0.0, F2=0.0; - Fq_core_shell_parallelepiped(q, &F1, &F2, sld_core, sld_a, sld_b, sld_c, sld_solvent, trace_length_a, trace_length_b, trace_length_c, trace_thick_rim_a, trace_thick_rim_b, trace_thick_rim_c); + double F1 = 0.0, F2 = 0.0; + Fq_core_shell_parallelepiped (q, &F1, &F2, sld_core, sld_a, sld_b, sld_c, sld_solvent, trace_length_a, trace_length_b, trace_length_c, trace_thick_rim_a, + trace_thick_rim_b, trace_thick_rim_c); Iq_out = F2; - float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -666,40 +661,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_core_shell_parallelepiped_aniso.comp b/mcstas-comps/sasmodels/SasView_core_shell_parallelepiped_aniso.comp index 2ff7c4c0ab..1e7b1566f1 100644 --- a/mcstas-comps/sasmodels/SasView_core_shell_parallelepiped_aniso.comp +++ b/mcstas-comps/sasmodels/SasView_core_shell_parallelepiped_aniso.comp @@ -548,140 +548,136 @@ Iqabc_core_shell_parallelepiped(double qa, double qb, double qc, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_length_a=length_a; - double trace_length_b=length_b; - double trace_length_c=length_c; - double trace_thick_rim_a=thick_rim_a; - double trace_thick_rim_b=thick_rim_b; - double trace_thick_rim_c=thick_rim_c; - if ( pd_length_a!=0.0 || pd_length_b!=0.0 || pd_length_c!=0.0 || pd_thick_rim_a!=0.0 || pd_thick_rim_b!=0.0 || pd_thick_rim_c!=0.0 ){ - trace_length_a = (randnorm()*pd_length_a+1.0)*length_a; - trace_length_b = (randnorm()*pd_length_b+1.0)*length_b; - trace_length_c = (randnorm()*pd_length_c+1.0)*length_c; - trace_thick_rim_a = (randnorm()*pd_thick_rim_a+1.0)*thick_rim_a; - trace_thick_rim_b = (randnorm()*pd_thick_rim_b+1.0)*thick_rim_b; - trace_thick_rim_c = (randnorm()*pd_thick_rim_c+1.0)*thick_rim_c; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_length_a = length_a; + double trace_length_b = length_b; + double trace_length_c = length_c; + double trace_thick_rim_a = thick_rim_a; + double trace_thick_rim_b = thick_rim_b; + double trace_thick_rim_c = thick_rim_c; + if (pd_length_a != 0.0 || pd_length_b != 0.0 || pd_length_c != 0.0 || pd_thick_rim_a != 0.0 || pd_thick_rim_b != 0.0 || pd_thick_rim_c != 0.0) { + trace_length_a = (randnorm () * pd_length_a + 1.0) * length_a; + trace_length_b = (randnorm () * pd_length_b + 1.0) * length_b; + trace_length_c = (randnorm () * pd_length_c + 1.0) * length_c; + trace_thick_rim_a = (randnorm () * pd_thick_rim_a + 1.0) * thick_rim_a; + trace_thick_rim_b = (randnorm () * pd_thick_rim_b + 1.0) * thick_rim_b; + trace_thick_rim_c = (randnorm () * pd_thick_rim_c + 1.0) * thick_rim_c; } - - double trace_theta=theta, dtheta=0.0; - double trace_phi=phi, dphi=0.0; - double trace_Psi=Psi, dPsi=0.0; - if ( pd_theta!=0.0 || pd_phi!=0.0 || pd_Psi!=0.0 ){ - trace_theta = ((rand01()-0.5)*pd_theta + 1.0)*theta; - dtheta = trace_theta-theta; - trace_phi = ((rand01()-0.5)*pd_phi + 1.0)*phi; - dphi = trace_phi-phi; - trace_Psi = ((rand01()-0.5)*pd_Psi + 1.0)*Psi; - dPsi = trace_Psi-Psi; + double trace_theta = theta, dtheta = 0.0; + double trace_phi = phi, dphi = 0.0; + double trace_Psi = Psi, dPsi = 0.0; + if (pd_theta != 0.0 || pd_phi != 0.0 || pd_Psi != 0.0) { + trace_theta = ((rand01 () - 0.5) * pd_theta + 1.0) * theta; + dtheta = trace_theta - theta; + trace_phi = ((rand01 () - 0.5) * pd_phi + 1.0) * phi; + dphi = trace_phi - phi; + trace_Psi = ((rand01 () - 0.5) * pd_Psi + 1.0) * Psi; + dPsi = trace_Psi - Psi; } - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - double qa=0.0, qb=0.0, qc=0.0; + double qa = 0.0, qb = 0.0, qc = 0.0; QABCRotation rotation; - qabc_rotation(&rotation, trace_theta, trace_phi, trace_Psi, dtheta, dphi, dPsi); - qabc_apply(&rotation, qx, qy, &qa, &qb, &qc); - Iq_out = Iqabc_core_shell_parallelepiped(qa, qb, qc, sld_core, sld_a, sld_b, sld_c, sld_solvent, trace_length_a, trace_length_b, trace_length_c, trace_thick_rim_a, trace_thick_rim_b, trace_thick_rim_c ); - + qabc_rotation (&rotation, trace_theta, trace_phi, trace_Psi, dtheta, dphi, dPsi); + qabc_apply (&rotation, qx, qy, &qa, &qb, &qc); + Iq_out = Iqabc_core_shell_parallelepiped (qa, qb, qc, sld_core, sld_a, sld_b, sld_c, sld_solvent, trace_length_a, trace_length_b, trace_length_c, + trace_thick_rim_a, trace_thick_rim_b, trace_thick_rim_c); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -689,40 +685,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_core_shell_sphere.comp b/mcstas-comps/sasmodels/SasView_core_shell_sphere.comp index 608743271f..274700f3d2 100644 --- a/mcstas-comps/sasmodels/SasView_core_shell_sphere.comp +++ b/mcstas-comps/sasmodels/SasView_core_shell_sphere.comp @@ -259,118 +259,112 @@ Fq_core_shell_sphere(double q, double *F1, double *F2, double radius, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_radius=radius; - double trace_thickness=thickness; - if ( pd_radius!=0.0 || pd_thickness!=0.0 ){ - trace_radius = (randnorm()*pd_radius+1.0)*radius; - trace_thickness = (randnorm()*pd_thickness+1.0)*thickness; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_radius = radius; + double trace_thickness = thickness; + if (pd_radius != 0.0 || pd_thickness != 0.0) { + trace_radius = (randnorm () * pd_radius + 1.0) * radius; + trace_thickness = (randnorm () * pd_thickness + 1.0) * thickness; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - double F1=0.0, F2=0.0; - Fq_core_shell_sphere(q, &F1, &F2, trace_radius, trace_thickness, sld_core, sld_shell, sld_solvent); + double F1 = 0.0, F2 = 0.0; + Fq_core_shell_sphere (q, &F1, &F2, trace_radius, trace_thickness, sld_core, sld_shell, sld_solvent); Iq_out = F2; - float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -378,40 +372,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_correlation_length.comp b/mcstas-comps/sasmodels/SasView_correlation_length.comp index c4c2a18a3c..7e5aab8be5 100644 --- a/mcstas-comps/sasmodels/SasView_correlation_length.comp +++ b/mcstas-comps/sasmodels/SasView_correlation_length.comp @@ -121,114 +121,108 @@ double Iq_correlation_length(double q, double lorentz_scale, double porod_scale, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_cor_length=cor_length; - if ( pd_cor_length!=0.0 ){ - trace_cor_length = (randnorm()*pd_cor_length+1.0)*cor_length; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_cor_length = cor_length; + if (pd_cor_length != 0.0) { + trace_cor_length = (randnorm () * pd_cor_length + 1.0) * cor_length; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - Iq_out = Iq_correlation_length(q, lorentz_scale, porod_scale, trace_cor_length, porod_exp, lorentz_exp); - + Iq_out = Iq_correlation_length (q, lorentz_scale, porod_scale, trace_cor_length, porod_exp, lorentz_exp); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -236,40 +230,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_cylinder.comp b/mcstas-comps/sasmodels/SasView_cylinder.comp index c0e93045e5..83b2664c8d 100644 --- a/mcstas-comps/sasmodels/SasView_cylinder.comp +++ b/mcstas-comps/sasmodels/SasView_cylinder.comp @@ -744,118 +744,112 @@ Iqac_cylinder(double qab, double qc, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_radius=radius; - double trace_length=length; - if ( pd_radius!=0.0 || pd_length!=0.0 ){ - trace_radius = (randnorm()*pd_radius+1.0)*radius; - trace_length = (randnorm()*pd_length+1.0)*length; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_radius = radius; + double trace_length = length; + if (pd_radius != 0.0 || pd_length != 0.0) { + trace_radius = (randnorm () * pd_radius + 1.0) * radius; + trace_length = (randnorm () * pd_length + 1.0) * length; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - double F1=0.0, F2=0.0; - Fq_cylinder(q, &F1, &F2, sld, sld_solvent, trace_radius, trace_length); + double F1 = 0.0, F2 = 0.0; + Fq_cylinder (q, &F1, &F2, sld, sld_solvent, trace_radius, trace_length); Iq_out = F2; - float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -863,40 +857,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_cylinder_aniso.comp b/mcstas-comps/sasmodels/SasView_cylinder_aniso.comp index feac8ddf1d..2a54018b6e 100644 --- a/mcstas-comps/sasmodels/SasView_cylinder_aniso.comp +++ b/mcstas-comps/sasmodels/SasView_cylinder_aniso.comp @@ -750,129 +750,124 @@ Iqac_cylinder(double qab, double qc, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_radius=radius; - double trace_length=length; - if ( pd_radius!=0.0 || pd_length!=0.0 ){ - trace_radius = (randnorm()*pd_radius+1.0)*radius; - trace_length = (randnorm()*pd_length+1.0)*length; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_radius = radius; + double trace_length = length; + if (pd_radius != 0.0 || pd_length != 0.0) { + trace_radius = (randnorm () * pd_radius + 1.0) * radius; + trace_length = (randnorm () * pd_length + 1.0) * length; } - - double trace_theta=theta, dtheta=0.0; - double trace_phi=phi, dphi=0.0; - if ( pd_theta!=0.0 || pd_phi!=0.0 ){ - trace_theta = ((rand01()-0.5)*pd_theta + 1.0)*theta; - dtheta = trace_theta-theta; - trace_phi = ((rand01()-0.5)*pd_phi + 1.0)*phi; - dphi = trace_phi-phi; + double trace_theta = theta, dtheta = 0.0; + double trace_phi = phi, dphi = 0.0; + if (pd_theta != 0.0 || pd_phi != 0.0) { + trace_theta = ((rand01 () - 0.5) * pd_theta + 1.0) * theta; + dtheta = trace_theta - theta; + trace_phi = ((rand01 () - 0.5) * pd_phi + 1.0) * phi; + dphi = trace_phi - phi; } - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - double qab=0.0, qc=0.0; + double qab = 0.0, qc = 0.0; QACRotation rotation; - qac_rotation(&rotation, trace_theta, trace_phi, dtheta, dphi); - qac_apply(&rotation, qx, qy, &qab, &qc); - Iq_out = Iqac_cylinder(qab, qc, sld, sld_solvent, trace_radius, trace_length ); - + qac_rotation (&rotation, trace_theta, trace_phi, dtheta, dphi); + qac_apply (&rotation, qx, qy, &qab, &qc); + Iq_out = Iqac_cylinder (qab, qc, sld, sld_solvent, trace_radius, trace_length); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -880,40 +875,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_dab.comp b/mcstas-comps/sasmodels/SasView_dab.comp index 796dcaec66..57aa0ef2bc 100644 --- a/mcstas-comps/sasmodels/SasView_dab.comp +++ b/mcstas-comps/sasmodels/SasView_dab.comp @@ -104,114 +104,108 @@ double Iq_dab(double q, double cor_length) INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_cor_length=cor_length; - if ( pd_cor_length!=0.0 ){ - trace_cor_length = (randnorm()*pd_cor_length+1.0)*cor_length; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_cor_length = cor_length; + if (pd_cor_length != 0.0) { + trace_cor_length = (randnorm () * pd_cor_length + 1.0) * cor_length; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - Iq_out = Iq_dab(q, trace_cor_length); - + Iq_out = Iq_dab (q, trace_cor_length); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -219,40 +213,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_ellipsoid.comp b/mcstas-comps/sasmodels/SasView_ellipsoid.comp index ebd58cedb6..3a694301fb 100644 --- a/mcstas-comps/sasmodels/SasView_ellipsoid.comp +++ b/mcstas-comps/sasmodels/SasView_ellipsoid.comp @@ -454,118 +454,112 @@ Iqac_ellipsoid(double qab, double qc, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_radius_polar=radius_polar; - double trace_radius_equatorial=radius_equatorial; - if ( pd_radius_polar!=0.0 || pd_radius_equatorial!=0.0 ){ - trace_radius_polar = (randnorm()*pd_radius_polar+1.0)*radius_polar; - trace_radius_equatorial = (randnorm()*pd_radius_equatorial+1.0)*radius_equatorial; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_radius_polar = radius_polar; + double trace_radius_equatorial = radius_equatorial; + if (pd_radius_polar != 0.0 || pd_radius_equatorial != 0.0) { + trace_radius_polar = (randnorm () * pd_radius_polar + 1.0) * radius_polar; + trace_radius_equatorial = (randnorm () * pd_radius_equatorial + 1.0) * radius_equatorial; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - double F1=0.0, F2=0.0; - Fq_ellipsoid(q, &F1, &F2, sld, sld_solvent, trace_radius_polar, trace_radius_equatorial); + double F1 = 0.0, F2 = 0.0; + Fq_ellipsoid (q, &F1, &F2, sld, sld_solvent, trace_radius_polar, trace_radius_equatorial); Iq_out = F2; - float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -573,40 +567,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_ellipsoid_aniso.comp b/mcstas-comps/sasmodels/SasView_ellipsoid_aniso.comp index ca077f4186..a67fe64e2f 100644 --- a/mcstas-comps/sasmodels/SasView_ellipsoid_aniso.comp +++ b/mcstas-comps/sasmodels/SasView_ellipsoid_aniso.comp @@ -460,129 +460,124 @@ Iqac_ellipsoid(double qab, double qc, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_radius_polar=radius_polar; - double trace_radius_equatorial=radius_equatorial; - if ( pd_radius_polar!=0.0 || pd_radius_equatorial!=0.0 ){ - trace_radius_polar = (randnorm()*pd_radius_polar+1.0)*radius_polar; - trace_radius_equatorial = (randnorm()*pd_radius_equatorial+1.0)*radius_equatorial; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_radius_polar = radius_polar; + double trace_radius_equatorial = radius_equatorial; + if (pd_radius_polar != 0.0 || pd_radius_equatorial != 0.0) { + trace_radius_polar = (randnorm () * pd_radius_polar + 1.0) * radius_polar; + trace_radius_equatorial = (randnorm () * pd_radius_equatorial + 1.0) * radius_equatorial; } - - double trace_theta=theta, dtheta=0.0; - double trace_phi=phi, dphi=0.0; - if ( pd_theta!=0.0 || pd_phi!=0.0 ){ - trace_theta = ((rand01()-0.5)*pd_theta + 1.0)*theta; - dtheta = trace_theta-theta; - trace_phi = ((rand01()-0.5)*pd_phi + 1.0)*phi; - dphi = trace_phi-phi; + double trace_theta = theta, dtheta = 0.0; + double trace_phi = phi, dphi = 0.0; + if (pd_theta != 0.0 || pd_phi != 0.0) { + trace_theta = ((rand01 () - 0.5) * pd_theta + 1.0) * theta; + dtheta = trace_theta - theta; + trace_phi = ((rand01 () - 0.5) * pd_phi + 1.0) * phi; + dphi = trace_phi - phi; } - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - double qab=0.0, qc=0.0; + double qab = 0.0, qc = 0.0; QACRotation rotation; - qac_rotation(&rotation, trace_theta, trace_phi, dtheta, dphi); - qac_apply(&rotation, qx, qy, &qab, &qc); - Iq_out = Iqac_ellipsoid(qab, qc, sld, sld_solvent, trace_radius_polar, trace_radius_equatorial ); - + qac_rotation (&rotation, trace_theta, trace_phi, dtheta, dphi); + qac_apply (&rotation, qx, qy, &qab, &qc); + Iq_out = Iqac_ellipsoid (qab, qc, sld, sld_solvent, trace_radius_polar, trace_radius_equatorial); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -590,40 +585,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_elliptical_cylinder.comp b/mcstas-comps/sasmodels/SasView_elliptical_cylinder.comp index 2b975ba9bd..e7550a2eb0 100644 --- a/mcstas-comps/sasmodels/SasView_elliptical_cylinder.comp +++ b/mcstas-comps/sasmodels/SasView_elliptical_cylinder.comp @@ -785,118 +785,112 @@ Iqabc_elliptical_cylinder(double qa, double qb, double qc, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_radius_minor=radius_minor; - double trace_length=length; - if ( pd_radius_minor!=0.0 || pd_length!=0.0 ){ - trace_radius_minor = (randnorm()*pd_radius_minor+1.0)*radius_minor; - trace_length = (randnorm()*pd_length+1.0)*length; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_radius_minor = radius_minor; + double trace_length = length; + if (pd_radius_minor != 0.0 || pd_length != 0.0) { + trace_radius_minor = (randnorm () * pd_radius_minor + 1.0) * radius_minor; + trace_length = (randnorm () * pd_length + 1.0) * length; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - double F1=0.0, F2=0.0; - Fq_elliptical_cylinder(q, &F1, &F2, trace_radius_minor, r_ratio, trace_length, sld, sld_solvent); + double F1 = 0.0, F2 = 0.0; + Fq_elliptical_cylinder (q, &F1, &F2, trace_radius_minor, r_ratio, trace_length, sld, sld_solvent); Iq_out = F2; - float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -904,40 +898,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_elliptical_cylinder_aniso.comp b/mcstas-comps/sasmodels/SasView_elliptical_cylinder_aniso.comp index 5a1e5d54f9..1d60cc435d 100644 --- a/mcstas-comps/sasmodels/SasView_elliptical_cylinder_aniso.comp +++ b/mcstas-comps/sasmodels/SasView_elliptical_cylinder_aniso.comp @@ -794,132 +794,127 @@ Iqabc_elliptical_cylinder(double qa, double qb, double qc, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_radius_minor=radius_minor; - double trace_length=length; - if ( pd_radius_minor!=0.0 || pd_length!=0.0 ){ - trace_radius_minor = (randnorm()*pd_radius_minor+1.0)*radius_minor; - trace_length = (randnorm()*pd_length+1.0)*length; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_radius_minor = radius_minor; + double trace_length = length; + if (pd_radius_minor != 0.0 || pd_length != 0.0) { + trace_radius_minor = (randnorm () * pd_radius_minor + 1.0) * radius_minor; + trace_length = (randnorm () * pd_length + 1.0) * length; } - - double trace_theta=theta, dtheta=0.0; - double trace_phi=phi, dphi=0.0; - double trace_Psi=Psi, dPsi=0.0; - if ( pd_theta!=0.0 || pd_phi!=0.0 || pd_Psi!=0.0 ){ - trace_theta = ((rand01()-0.5)*pd_theta + 1.0)*theta; - dtheta = trace_theta-theta; - trace_phi = ((rand01()-0.5)*pd_phi + 1.0)*phi; - dphi = trace_phi-phi; - trace_Psi = ((rand01()-0.5)*pd_Psi + 1.0)*Psi; - dPsi = trace_Psi-Psi; + double trace_theta = theta, dtheta = 0.0; + double trace_phi = phi, dphi = 0.0; + double trace_Psi = Psi, dPsi = 0.0; + if (pd_theta != 0.0 || pd_phi != 0.0 || pd_Psi != 0.0) { + trace_theta = ((rand01 () - 0.5) * pd_theta + 1.0) * theta; + dtheta = trace_theta - theta; + trace_phi = ((rand01 () - 0.5) * pd_phi + 1.0) * phi; + dphi = trace_phi - phi; + trace_Psi = ((rand01 () - 0.5) * pd_Psi + 1.0) * Psi; + dPsi = trace_Psi - Psi; } - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - double qa=0.0, qb=0.0, qc=0.0; + double qa = 0.0, qb = 0.0, qc = 0.0; QABCRotation rotation; - qabc_rotation(&rotation, trace_theta, trace_phi, trace_Psi, dtheta, dphi, dPsi); - qabc_apply(&rotation, qx, qy, &qa, &qb, &qc); - Iq_out = Iqabc_elliptical_cylinder(qa, qb, qc, trace_radius_minor, r_ratio, trace_length, sld, sld_solvent ); - + qabc_rotation (&rotation, trace_theta, trace_phi, trace_Psi, dtheta, dphi, dPsi); + qabc_apply (&rotation, qx, qy, &qa, &qb, &qc); + Iq_out = Iqabc_elliptical_cylinder (qa, qb, qc, trace_radius_minor, r_ratio, trace_length, sld, sld_solvent); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -927,40 +922,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_fcc_paracrystal.comp b/mcstas-comps/sasmodels/SasView_fcc_paracrystal.comp index c5e7f6d64a..abefc75e28 100644 --- a/mcstas-comps/sasmodels/SasView_fcc_paracrystal.comp +++ b/mcstas-comps/sasmodels/SasView_fcc_paracrystal.comp @@ -623,114 +623,108 @@ static double Iqabc_fcc_paracrystal(double qa, double qb, double qc, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_radius=radius; - if ( pd_radius!=0.0 ){ - trace_radius = (randnorm()*pd_radius+1.0)*radius; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_radius = radius; + if (pd_radius != 0.0) { + trace_radius = (randnorm () * pd_radius + 1.0) * radius; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - Iq_out = Iq_fcc_paracrystal(q, dnn, d_factor, trace_radius, sld, sld_solvent); - + Iq_out = Iq_fcc_paracrystal (q, dnn, d_factor, trace_radius, sld, sld_solvent); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -738,40 +732,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_fcc_paracrystal_aniso.comp b/mcstas-comps/sasmodels/SasView_fcc_paracrystal_aniso.comp index e7ccadbc29..86fe552629 100644 --- a/mcstas-comps/sasmodels/SasView_fcc_paracrystal_aniso.comp +++ b/mcstas-comps/sasmodels/SasView_fcc_paracrystal_aniso.comp @@ -632,130 +632,125 @@ static double Iqabc_fcc_paracrystal(double qa, double qb, double qc, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_radius=radius; - if ( pd_radius!=0.0 ){ - trace_radius = (randnorm()*pd_radius+1.0)*radius; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_radius = radius; + if (pd_radius != 0.0) { + trace_radius = (randnorm () * pd_radius + 1.0) * radius; } - - double trace_theta=theta, dtheta=0.0; - double trace_phi=phi, dphi=0.0; - double trace_Psi=Psi, dPsi=0.0; - if ( pd_theta!=0.0 || pd_phi!=0.0 || pd_Psi!=0.0 ){ - trace_theta = ((rand01()-0.5)*pd_theta + 1.0)*theta; - dtheta = trace_theta-theta; - trace_phi = ((rand01()-0.5)*pd_phi + 1.0)*phi; - dphi = trace_phi-phi; - trace_Psi = ((rand01()-0.5)*pd_Psi + 1.0)*Psi; - dPsi = trace_Psi-Psi; + double trace_theta = theta, dtheta = 0.0; + double trace_phi = phi, dphi = 0.0; + double trace_Psi = Psi, dPsi = 0.0; + if (pd_theta != 0.0 || pd_phi != 0.0 || pd_Psi != 0.0) { + trace_theta = ((rand01 () - 0.5) * pd_theta + 1.0) * theta; + dtheta = trace_theta - theta; + trace_phi = ((rand01 () - 0.5) * pd_phi + 1.0) * phi; + dphi = trace_phi - phi; + trace_Psi = ((rand01 () - 0.5) * pd_Psi + 1.0) * Psi; + dPsi = trace_Psi - Psi; } - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - double qa=0.0, qb=0.0, qc=0.0; + double qa = 0.0, qb = 0.0, qc = 0.0; QABCRotation rotation; - qabc_rotation(&rotation, trace_theta, trace_phi, trace_Psi, dtheta, dphi, dPsi); - qabc_apply(&rotation, qx, qy, &qa, &qb, &qc); - Iq_out = Iqabc_fcc_paracrystal(qa, qb, qc, dnn, d_factor, trace_radius, sld, sld_solvent ); - + qabc_rotation (&rotation, trace_theta, trace_phi, trace_Psi, dtheta, dphi, dPsi); + qabc_apply (&rotation, qx, qy, &qa, &qb, &qc); + Iq_out = Iqabc_fcc_paracrystal (qa, qb, qc, dnn, d_factor, trace_radius, sld, sld_solvent); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -763,40 +758,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_flexible_cylinder.comp b/mcstas-comps/sasmodels/SasView_flexible_cylinder.comp index 7fcf806a2e..acd9bded01 100644 --- a/mcstas-comps/sasmodels/SasView_flexible_cylinder.comp +++ b/mcstas-comps/sasmodels/SasView_flexible_cylinder.comp @@ -730,118 +730,112 @@ Iq_flexible_cylinder(double q, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_length=length; - double trace_kuhn_length=kuhn_length; - double trace_radius=radius; - if ( pd_length!=0.0 || pd_kuhn_length!=0.0 || pd_radius!=0.0 ){ - trace_length = (randnorm()*pd_length+1.0)*length; - trace_kuhn_length = (randnorm()*pd_kuhn_length+1.0)*kuhn_length; - trace_radius = (randnorm()*pd_radius+1.0)*radius; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_length = length; + double trace_kuhn_length = kuhn_length; + double trace_radius = radius; + if (pd_length != 0.0 || pd_kuhn_length != 0.0 || pd_radius != 0.0) { + trace_length = (randnorm () * pd_length + 1.0) * length; + trace_kuhn_length = (randnorm () * pd_kuhn_length + 1.0) * kuhn_length; + trace_radius = (randnorm () * pd_radius + 1.0) * radius; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - Iq_out = Iq_flexible_cylinder(q, trace_length, trace_kuhn_length, trace_radius, sld, sld_solvent); - + Iq_out = Iq_flexible_cylinder (q, trace_length, trace_kuhn_length, trace_radius, sld, sld_solvent); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -849,40 +843,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_flexible_cylinder_elliptical.comp b/mcstas-comps/sasmodels/SasView_flexible_cylinder_elliptical.comp index 92498026f5..382ffee442 100644 --- a/mcstas-comps/sasmodels/SasView_flexible_cylinder_elliptical.comp +++ b/mcstas-comps/sasmodels/SasView_flexible_cylinder_elliptical.comp @@ -965,118 +965,112 @@ double Iq_flexible_cylinder_elliptical(double q, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_length=length; - double trace_kuhn_length=kuhn_length; - double trace_radius=radius; - if ( pd_length!=0.0 || pd_kuhn_length!=0.0 || pd_radius!=0.0 ){ - trace_length = (randnorm()*pd_length+1.0)*length; - trace_kuhn_length = (randnorm()*pd_kuhn_length+1.0)*kuhn_length; - trace_radius = (randnorm()*pd_radius+1.0)*radius; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_length = length; + double trace_kuhn_length = kuhn_length; + double trace_radius = radius; + if (pd_length != 0.0 || pd_kuhn_length != 0.0 || pd_radius != 0.0) { + trace_length = (randnorm () * pd_length + 1.0) * length; + trace_kuhn_length = (randnorm () * pd_kuhn_length + 1.0) * kuhn_length; + trace_radius = (randnorm () * pd_radius + 1.0) * radius; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - Iq_out = Iq_flexible_cylinder_elliptical(q, trace_length, trace_kuhn_length, trace_radius, axis_ratio, sld, sld_solvent); - + Iq_out = Iq_flexible_cylinder_elliptical (q, trace_length, trace_kuhn_length, trace_radius, axis_ratio, sld, sld_solvent); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -1084,40 +1078,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_fractal.comp b/mcstas-comps/sasmodels/SasView_fractal.comp index 5c6fca5ee3..60a00277a7 100644 --- a/mcstas-comps/sasmodels/SasView_fractal.comp +++ b/mcstas-comps/sasmodels/SasView_fractal.comp @@ -409,116 +409,110 @@ Iq_fractal(double q, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_radius=radius; - double trace_cor_length=cor_length; - if ( pd_radius!=0.0 || pd_cor_length!=0.0 ){ - trace_radius = (randnorm()*pd_radius+1.0)*radius; - trace_cor_length = (randnorm()*pd_cor_length+1.0)*cor_length; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_radius = radius; + double trace_cor_length = cor_length; + if (pd_radius != 0.0 || pd_cor_length != 0.0) { + trace_radius = (randnorm () * pd_radius + 1.0) * radius; + trace_cor_length = (randnorm () * pd_cor_length + 1.0) * cor_length; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - Iq_out = Iq_fractal(q, volfraction, trace_radius, fractal_dim, trace_cor_length, sld_block, sld_solvent); - + Iq_out = Iq_fractal (q, volfraction, trace_radius, fractal_dim, trace_cor_length, sld_block, sld_solvent); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -526,40 +520,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_fractal_core_shell.comp b/mcstas-comps/sasmodels/SasView_fractal_core_shell.comp index 1aae2484e2..7971e9f6b2 100644 --- a/mcstas-comps/sasmodels/SasView_fractal_core_shell.comp +++ b/mcstas-comps/sasmodels/SasView_fractal_core_shell.comp @@ -467,118 +467,112 @@ Iq_fractal_core_shell(double q, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_radius=radius; - double trace_thickness=thickness; - double trace_cor_length=cor_length; - if ( pd_radius!=0.0 || pd_thickness!=0.0 || pd_cor_length!=0.0 ){ - trace_radius = (randnorm()*pd_radius+1.0)*radius; - trace_thickness = (randnorm()*pd_thickness+1.0)*thickness; - trace_cor_length = (randnorm()*pd_cor_length+1.0)*cor_length; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_radius = radius; + double trace_thickness = thickness; + double trace_cor_length = cor_length; + if (pd_radius != 0.0 || pd_thickness != 0.0 || pd_cor_length != 0.0) { + trace_radius = (randnorm () * pd_radius + 1.0) * radius; + trace_thickness = (randnorm () * pd_thickness + 1.0) * thickness; + trace_cor_length = (randnorm () * pd_cor_length + 1.0) * cor_length; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - Iq_out = Iq_fractal_core_shell(q, trace_radius, trace_thickness, sld_core, sld_shell, sld_solvent, volfraction, fractal_dim, trace_cor_length); - + Iq_out = Iq_fractal_core_shell (q, trace_radius, trace_thickness, sld_core, sld_shell, sld_solvent, volfraction, fractal_dim, trace_cor_length); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -586,40 +580,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_fuzzy_sphere.comp b/mcstas-comps/sasmodels/SasView_fuzzy_sphere.comp index 43cb607acd..6ec22a1cff 100644 --- a/mcstas-comps/sasmodels/SasView_fuzzy_sphere.comp +++ b/mcstas-comps/sasmodels/SasView_fuzzy_sphere.comp @@ -199,116 +199,110 @@ static void Fq_fuzzy_sphere(double q, double *F1, double *F2, double sld, double INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_radius=radius; - if ( pd_radius!=0.0 ){ - trace_radius = (randnorm()*pd_radius+1.0)*radius; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_radius = radius; + if (pd_radius != 0.0) { + trace_radius = (randnorm () * pd_radius + 1.0) * radius; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - double F1=0.0, F2=0.0; - Fq_fuzzy_sphere(q, &F1, &F2, sld, sld_solvent, trace_radius, fuzziness); + double F1 = 0.0, F2 = 0.0; + Fq_fuzzy_sphere (q, &F1, &F2, sld, sld_solvent, trace_radius, fuzziness); Iq_out = F2; - float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -316,40 +310,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_gauss_lorentz_gel.comp b/mcstas-comps/sasmodels/SasView_gauss_lorentz_gel.comp index 941660b528..97d8b8f39b 100644 --- a/mcstas-comps/sasmodels/SasView_gauss_lorentz_gel.comp +++ b/mcstas-comps/sasmodels/SasView_gauss_lorentz_gel.comp @@ -121,116 +121,110 @@ double Iq_gauss_lorentz_gel(double q, double gauss_scale, double cor_length_stat INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_cor_length_static=cor_length_static; - double trace_cor_length_dynamic=cor_length_dynamic; - if ( pd_cor_length_static!=0.0 || pd_cor_length_dynamic!=0.0 ){ - trace_cor_length_static = (randnorm()*pd_cor_length_static+1.0)*cor_length_static; - trace_cor_length_dynamic = (randnorm()*pd_cor_length_dynamic+1.0)*cor_length_dynamic; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_cor_length_static = cor_length_static; + double trace_cor_length_dynamic = cor_length_dynamic; + if (pd_cor_length_static != 0.0 || pd_cor_length_dynamic != 0.0) { + trace_cor_length_static = (randnorm () * pd_cor_length_static + 1.0) * cor_length_static; + trace_cor_length_dynamic = (randnorm () * pd_cor_length_dynamic + 1.0) * cor_length_dynamic; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - Iq_out = Iq_gauss_lorentz_gel(q, gauss_scale, trace_cor_length_static, lorentz_scale, trace_cor_length_dynamic); - + Iq_out = Iq_gauss_lorentz_gel (q, gauss_scale, trace_cor_length_static, lorentz_scale, trace_cor_length_dynamic); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -238,40 +232,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_gaussian_peak.comp b/mcstas-comps/sasmodels/SasView_gaussian_peak.comp index 072e262ec8..bf5fa7eaec 100644 --- a/mcstas-comps/sasmodels/SasView_gaussian_peak.comp +++ b/mcstas-comps/sasmodels/SasView_gaussian_peak.comp @@ -103,108 +103,103 @@ double Iq_gaussian_peak(double q, double peak_pos, double sigma) INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - Iq_out = Iq_gaussian_peak(q, peak_pos, sigma); - + Iq_out = Iq_gaussian_peak (q, peak_pos, sigma); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -212,40 +207,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_gel_fit.comp b/mcstas-comps/sasmodels/SasView_gel_fit.comp index e3f071b797..7a94faf1c6 100644 --- a/mcstas-comps/sasmodels/SasView_gel_fit.comp +++ b/mcstas-comps/sasmodels/SasView_gel_fit.comp @@ -130,116 +130,110 @@ static double Iq_gel_fit(double q, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_rg=rg; - double trace_cor_length=cor_length; - if ( pd_rg!=0.0 || pd_cor_length!=0.0 ){ - trace_rg = (randnorm()*pd_rg+1.0)*rg; - trace_cor_length = (randnorm()*pd_cor_length+1.0)*cor_length; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_rg = rg; + double trace_cor_length = cor_length; + if (pd_rg != 0.0 || pd_cor_length != 0.0) { + trace_rg = (randnorm () * pd_rg + 1.0) * rg; + trace_cor_length = (randnorm () * pd_cor_length + 1.0) * cor_length; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - Iq_out = Iq_gel_fit(q, guinier_scale, lorentz_scale, trace_rg, fractal_dim, trace_cor_length); - + Iq_out = Iq_gel_fit (q, guinier_scale, lorentz_scale, trace_rg, fractal_dim, trace_cor_length); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -247,40 +241,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_guinier.comp b/mcstas-comps/sasmodels/SasView_guinier.comp index 39a61d6ba5..dc6fa59f2c 100644 --- a/mcstas-comps/sasmodels/SasView_guinier.comp +++ b/mcstas-comps/sasmodels/SasView_guinier.comp @@ -103,114 +103,108 @@ double Iq_guinier(double q, double rg) INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_rg=rg; - if ( pd_rg!=0.0 ){ - trace_rg = (randnorm()*pd_rg+1.0)*rg; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_rg = rg; + if (pd_rg != 0.0) { + trace_rg = (randnorm () * pd_rg + 1.0) * rg; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - Iq_out = Iq_guinier(q, trace_rg); - + Iq_out = Iq_guinier (q, trace_rg); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -218,40 +212,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_guinier_porod.comp b/mcstas-comps/sasmodels/SasView_guinier_porod.comp index bc63bf0a03..0deb71ce19 100644 --- a/mcstas-comps/sasmodels/SasView_guinier_porod.comp +++ b/mcstas-comps/sasmodels/SasView_guinier_porod.comp @@ -127,114 +127,108 @@ double Iq_guinier_porod(double q, double rg, double s, double porod_exp) { INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_rg=rg; - if ( pd_rg!=0.0 ){ - trace_rg = (randnorm()*pd_rg+1.0)*rg; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_rg = rg; + if (pd_rg != 0.0) { + trace_rg = (randnorm () * pd_rg + 1.0) * rg; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - Iq_out = Iq_guinier_porod(q, trace_rg, s, porod_exp); - + Iq_out = Iq_guinier_porod (q, trace_rg, s, porod_exp); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -242,40 +236,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_hardsphere.comp b/mcstas-comps/sasmodels/SasView_hardsphere.comp index 4c005360bc..b3226f3b97 100644 --- a/mcstas-comps/sasmodels/SasView_hardsphere.comp +++ b/mcstas-comps/sasmodels/SasView_hardsphere.comp @@ -185,114 +185,108 @@ double Iq_hardsphere(double q, double radius_effective, double volfraction) INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_radius_effective=radius_effective; - if ( pd_radius_effective!=0.0 ){ - trace_radius_effective = (randnorm()*pd_radius_effective+1.0)*radius_effective; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_radius_effective = radius_effective; + if (pd_radius_effective != 0.0) { + trace_radius_effective = (randnorm () * pd_radius_effective + 1.0) * radius_effective; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - Iq_out = Iq_hardsphere(q, trace_radius_effective, volfraction); - + Iq_out = Iq_hardsphere (q, trace_radius_effective, volfraction); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -300,40 +294,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_hayter_msa.comp b/mcstas-comps/sasmodels/SasView_hayter_msa.comp index 67a8614ba0..6c3a80b562 100644 --- a/mcstas-comps/sasmodels/SasView_hayter_msa.comp +++ b/mcstas-comps/sasmodels/SasView_hayter_msa.comp @@ -651,116 +651,110 @@ sqhcal(double qq, double gMSAWave[]) INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_radius_effective=radius_effective; - double trace_charge=charge; - if ( pd_radius_effective!=0.0 || pd_charge!=0.0 ){ - trace_radius_effective = (randnorm()*pd_radius_effective+1.0)*radius_effective; - trace_charge = (randnorm()*pd_charge+1.0)*charge; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_radius_effective = radius_effective; + double trace_charge = charge; + if (pd_radius_effective != 0.0 || pd_charge != 0.0) { + trace_radius_effective = (randnorm () * pd_radius_effective + 1.0) * radius_effective; + trace_charge = (randnorm () * pd_charge + 1.0) * charge; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - Iq_out = Iq_hayter_msa(q, trace_radius_effective, volfraction, trace_charge, temperature, concentration_salt, dielectconst); - + Iq_out = Iq_hayter_msa (q, trace_radius_effective, volfraction, trace_charge, temperature, concentration_salt, dielectconst); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -768,40 +762,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_hollow_cylinder.comp b/mcstas-comps/sasmodels/SasView_hollow_cylinder.comp index 6f114f9ffb..7417efd655 100644 --- a/mcstas-comps/sasmodels/SasView_hollow_cylinder.comp +++ b/mcstas-comps/sasmodels/SasView_hollow_cylinder.comp @@ -751,120 +751,114 @@ Iqac_hollow_cylinder(double qab, double qc, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_radius=radius; - double trace_thickness=thickness; - double trace_length=length; - if ( pd_radius!=0.0 || pd_thickness!=0.0 || pd_length!=0.0 ){ - trace_radius = (randnorm()*pd_radius+1.0)*radius; - trace_thickness = (randnorm()*pd_thickness+1.0)*thickness; - trace_length = (randnorm()*pd_length+1.0)*length; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_radius = radius; + double trace_thickness = thickness; + double trace_length = length; + if (pd_radius != 0.0 || pd_thickness != 0.0 || pd_length != 0.0) { + trace_radius = (randnorm () * pd_radius + 1.0) * radius; + trace_thickness = (randnorm () * pd_thickness + 1.0) * thickness; + trace_length = (randnorm () * pd_length + 1.0) * length; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - double F1=0.0, F2=0.0; - Fq_hollow_cylinder(q, &F1, &F2, trace_radius, trace_thickness, trace_length, sld, sld_solvent); + double F1 = 0.0, F2 = 0.0; + Fq_hollow_cylinder (q, &F1, &F2, trace_radius, trace_thickness, trace_length, sld, sld_solvent); Iq_out = F2; - float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -872,40 +866,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_hollow_cylinder_aniso.comp b/mcstas-comps/sasmodels/SasView_hollow_cylinder_aniso.comp index 788cca5815..5a85f0f9c8 100644 --- a/mcstas-comps/sasmodels/SasView_hollow_cylinder_aniso.comp +++ b/mcstas-comps/sasmodels/SasView_hollow_cylinder_aniso.comp @@ -757,131 +757,126 @@ Iqac_hollow_cylinder(double qab, double qc, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_radius=radius; - double trace_thickness=thickness; - double trace_length=length; - if ( pd_radius!=0.0 || pd_thickness!=0.0 || pd_length!=0.0 ){ - trace_radius = (randnorm()*pd_radius+1.0)*radius; - trace_thickness = (randnorm()*pd_thickness+1.0)*thickness; - trace_length = (randnorm()*pd_length+1.0)*length; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_radius = radius; + double trace_thickness = thickness; + double trace_length = length; + if (pd_radius != 0.0 || pd_thickness != 0.0 || pd_length != 0.0) { + trace_radius = (randnorm () * pd_radius + 1.0) * radius; + trace_thickness = (randnorm () * pd_thickness + 1.0) * thickness; + trace_length = (randnorm () * pd_length + 1.0) * length; } - - double trace_theta=theta, dtheta=0.0; - double trace_phi=phi, dphi=0.0; - if ( pd_theta!=0.0 || pd_phi!=0.0 ){ - trace_theta = ((rand01()-0.5)*pd_theta + 1.0)*theta; - dtheta = trace_theta-theta; - trace_phi = ((rand01()-0.5)*pd_phi + 1.0)*phi; - dphi = trace_phi-phi; + double trace_theta = theta, dtheta = 0.0; + double trace_phi = phi, dphi = 0.0; + if (pd_theta != 0.0 || pd_phi != 0.0) { + trace_theta = ((rand01 () - 0.5) * pd_theta + 1.0) * theta; + dtheta = trace_theta - theta; + trace_phi = ((rand01 () - 0.5) * pd_phi + 1.0) * phi; + dphi = trace_phi - phi; } - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - double qab=0.0, qc=0.0; + double qab = 0.0, qc = 0.0; QACRotation rotation; - qac_rotation(&rotation, trace_theta, trace_phi, dtheta, dphi); - qac_apply(&rotation, qx, qy, &qab, &qc); - Iq_out = Iqac_hollow_cylinder(qab, qc, trace_radius, trace_thickness, trace_length, sld, sld_solvent ); - + qac_rotation (&rotation, trace_theta, trace_phi, dtheta, dphi); + qac_apply (&rotation, qx, qy, &qab, &qc); + Iq_out = Iqac_hollow_cylinder (qab, qc, trace_radius, trace_thickness, trace_length, sld, sld_solvent); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -889,40 +884,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_hollow_rectangular_prism.comp b/mcstas-comps/sasmodels/SasView_hollow_rectangular_prism.comp index 4dc81a45a9..488f62916d 100644 --- a/mcstas-comps/sasmodels/SasView_hollow_rectangular_prism.comp +++ b/mcstas-comps/sasmodels/SasView_hollow_rectangular_prism.comp @@ -464,118 +464,112 @@ Iqabc_hollow_rectangular_prism(double qa, double qb, double qc, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_length_a=length_a; - double trace_thickness=thickness; - if ( pd_length_a!=0.0 || pd_thickness!=0.0 ){ - trace_length_a = (randnorm()*pd_length_a+1.0)*length_a; - trace_thickness = (randnorm()*pd_thickness+1.0)*thickness; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_length_a = length_a; + double trace_thickness = thickness; + if (pd_length_a != 0.0 || pd_thickness != 0.0) { + trace_length_a = (randnorm () * pd_length_a + 1.0) * length_a; + trace_thickness = (randnorm () * pd_thickness + 1.0) * thickness; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - double F1=0.0, F2=0.0; - Fq_hollow_rectangular_prism(q, &F1, &F2, sld, sld_solvent, trace_length_a, b2a_ratio, c2a_ratio, trace_thickness); + double F1 = 0.0, F2 = 0.0; + Fq_hollow_rectangular_prism (q, &F1, &F2, sld, sld_solvent, trace_length_a, b2a_ratio, c2a_ratio, trace_thickness); Iq_out = F2; - float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -583,40 +577,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_hollow_rectangular_prism_aniso.comp b/mcstas-comps/sasmodels/SasView_hollow_rectangular_prism_aniso.comp index f431920d02..76eeb79a6f 100644 --- a/mcstas-comps/sasmodels/SasView_hollow_rectangular_prism_aniso.comp +++ b/mcstas-comps/sasmodels/SasView_hollow_rectangular_prism_aniso.comp @@ -473,132 +473,127 @@ Iqabc_hollow_rectangular_prism(double qa, double qb, double qc, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_length_a=length_a; - double trace_thickness=thickness; - if ( pd_length_a!=0.0 || pd_thickness!=0.0 ){ - trace_length_a = (randnorm()*pd_length_a+1.0)*length_a; - trace_thickness = (randnorm()*pd_thickness+1.0)*thickness; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_length_a = length_a; + double trace_thickness = thickness; + if (pd_length_a != 0.0 || pd_thickness != 0.0) { + trace_length_a = (randnorm () * pd_length_a + 1.0) * length_a; + trace_thickness = (randnorm () * pd_thickness + 1.0) * thickness; } - - double trace_theta=theta, dtheta=0.0; - double trace_phi=phi, dphi=0.0; - double trace_Psi=Psi, dPsi=0.0; - if ( pd_theta!=0.0 || pd_phi!=0.0 || pd_Psi!=0.0 ){ - trace_theta = ((rand01()-0.5)*pd_theta + 1.0)*theta; - dtheta = trace_theta-theta; - trace_phi = ((rand01()-0.5)*pd_phi + 1.0)*phi; - dphi = trace_phi-phi; - trace_Psi = ((rand01()-0.5)*pd_Psi + 1.0)*Psi; - dPsi = trace_Psi-Psi; + double trace_theta = theta, dtheta = 0.0; + double trace_phi = phi, dphi = 0.0; + double trace_Psi = Psi, dPsi = 0.0; + if (pd_theta != 0.0 || pd_phi != 0.0 || pd_Psi != 0.0) { + trace_theta = ((rand01 () - 0.5) * pd_theta + 1.0) * theta; + dtheta = trace_theta - theta; + trace_phi = ((rand01 () - 0.5) * pd_phi + 1.0) * phi; + dphi = trace_phi - phi; + trace_Psi = ((rand01 () - 0.5) * pd_Psi + 1.0) * Psi; + dPsi = trace_Psi - Psi; } - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - double qa=0.0, qb=0.0, qc=0.0; + double qa = 0.0, qb = 0.0, qc = 0.0; QABCRotation rotation; - qabc_rotation(&rotation, trace_theta, trace_phi, trace_Psi, dtheta, dphi, dPsi); - qabc_apply(&rotation, qx, qy, &qa, &qb, &qc); - Iq_out = Iqabc_hollow_rectangular_prism(qa, qb, qc, sld, sld_solvent, trace_length_a, b2a_ratio, c2a_ratio, trace_thickness ); - + qabc_rotation (&rotation, trace_theta, trace_phi, trace_Psi, dtheta, dphi, dPsi); + qabc_apply (&rotation, qx, qy, &qa, &qb, &qc); + Iq_out = Iqabc_hollow_rectangular_prism (qa, qb, qc, sld, sld_solvent, trace_length_a, b2a_ratio, c2a_ratio, trace_thickness); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -606,40 +601,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_hollow_rectangular_prism_thin_walls.comp b/mcstas-comps/sasmodels/SasView_hollow_rectangular_prism_thin_walls.comp index 013bfac190..350ac8a414 100644 --- a/mcstas-comps/sasmodels/SasView_hollow_rectangular_prism_thin_walls.comp +++ b/mcstas-comps/sasmodels/SasView_hollow_rectangular_prism_thin_walls.comp @@ -418,116 +418,110 @@ Fq_hollow_rectangular_prism_thin_walls(double q, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_length_a=length_a; - if ( pd_length_a!=0.0 ){ - trace_length_a = (randnorm()*pd_length_a+1.0)*length_a; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_length_a = length_a; + if (pd_length_a != 0.0) { + trace_length_a = (randnorm () * pd_length_a + 1.0) * length_a; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - double F1=0.0, F2=0.0; - Fq_hollow_rectangular_prism_thin_walls(q, &F1, &F2, sld, sld_solvent, trace_length_a, b2a_ratio, c2a_ratio); + double F1 = 0.0, F2 = 0.0; + Fq_hollow_rectangular_prism_thin_walls (q, &F1, &F2, sld, sld_solvent, trace_length_a, b2a_ratio, c2a_ratio); Iq_out = F2; - float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -535,40 +529,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_lamellar_hg.comp b/mcstas-comps/sasmodels/SasView_lamellar_hg.comp index fa929e102f..2daf52183f 100644 --- a/mcstas-comps/sasmodels/SasView_lamellar_hg.comp +++ b/mcstas-comps/sasmodels/SasView_lamellar_hg.comp @@ -125,116 +125,110 @@ double Iq_lamellar_hg(double q, double length_tail, double length_head, double s INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_length_tail=length_tail; - double trace_length_head=length_head; - if ( pd_length_tail!=0.0 || pd_length_head!=0.0 ){ - trace_length_tail = (randnorm()*pd_length_tail+1.0)*length_tail; - trace_length_head = (randnorm()*pd_length_head+1.0)*length_head; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_length_tail = length_tail; + double trace_length_head = length_head; + if (pd_length_tail != 0.0 || pd_length_head != 0.0) { + trace_length_tail = (randnorm () * pd_length_tail + 1.0) * length_tail; + trace_length_head = (randnorm () * pd_length_head + 1.0) * length_head; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - Iq_out = Iq_lamellar_hg(q, trace_length_tail, trace_length_head, sld, sld_head, sld_solvent); - + Iq_out = Iq_lamellar_hg (q, trace_length_tail, trace_length_head, sld, sld_head, sld_solvent); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -242,40 +236,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_lamellar_hg_stack_caille.comp b/mcstas-comps/sasmodels/SasView_lamellar_hg_stack_caille.comp index cd164bf820..b3a0aec29e 100644 --- a/mcstas-comps/sasmodels/SasView_lamellar_hg_stack_caille.comp +++ b/mcstas-comps/sasmodels/SasView_lamellar_hg_stack_caille.comp @@ -171,116 +171,110 @@ Iq_lamellar_hg_stack_caille(double qval, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_length_tail=length_tail; - double trace_length_head=length_head; - if ( pd_length_tail!=0.0 || pd_length_head!=0.0 ){ - trace_length_tail = (randnorm()*pd_length_tail+1.0)*length_tail; - trace_length_head = (randnorm()*pd_length_head+1.0)*length_head; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_length_tail = length_tail; + double trace_length_head = length_head; + if (pd_length_tail != 0.0 || pd_length_head != 0.0) { + trace_length_tail = (randnorm () * pd_length_tail + 1.0) * length_tail; + trace_length_head = (randnorm () * pd_length_head + 1.0) * length_head; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - Iq_out = Iq_lamellar_hg_stack_caille(q, trace_length_tail, trace_length_head, Nlayers, d_spacing, Caille_parameter, sld, sld_head, sld_solvent); - + Iq_out = Iq_lamellar_hg_stack_caille (q, trace_length_tail, trace_length_head, Nlayers, d_spacing, Caille_parameter, sld, sld_head, sld_solvent); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -288,40 +282,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_lamellar_stack_caille.comp b/mcstas-comps/sasmodels/SasView_lamellar_stack_caille.comp index 90300aecbd..80d0751349 100644 --- a/mcstas-comps/sasmodels/SasView_lamellar_stack_caille.comp +++ b/mcstas-comps/sasmodels/SasView_lamellar_stack_caille.comp @@ -161,114 +161,108 @@ Iq_lamellar_stack_caille(double qval, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_thickness=thickness; - if ( pd_thickness!=0.0 ){ - trace_thickness = (randnorm()*pd_thickness+1.0)*thickness; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_thickness = thickness; + if (pd_thickness != 0.0) { + trace_thickness = (randnorm () * pd_thickness + 1.0) * thickness; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - Iq_out = Iq_lamellar_stack_caille(q, trace_thickness, Nlayers, d_spacing, Caille_parameter, sld, sld_solvent); - + Iq_out = Iq_lamellar_stack_caille (q, trace_thickness, Nlayers, d_spacing, Caille_parameter, sld, sld_solvent); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -276,40 +270,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_lamellar_stack_paracrystal.comp b/mcstas-comps/sasmodels/SasView_lamellar_stack_paracrystal.comp index e78abbc472..615fe05998 100644 --- a/mcstas-comps/sasmodels/SasView_lamellar_stack_paracrystal.comp +++ b/mcstas-comps/sasmodels/SasView_lamellar_stack_paracrystal.comp @@ -181,114 +181,108 @@ paraCryst_an(double ww, double qval, double davg, int Nlayers) { INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_thickness=thickness; - if ( pd_thickness!=0.0 ){ - trace_thickness = (randnorm()*pd_thickness+1.0)*thickness; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_thickness = thickness; + if (pd_thickness != 0.0) { + trace_thickness = (randnorm () * pd_thickness + 1.0) * thickness; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - Iq_out = Iq_lamellar_stack_paracrystal(q, trace_thickness, Nlayers, d_spacing, sigma_d, sld, sld_solvent); - + Iq_out = Iq_lamellar_stack_paracrystal (q, trace_thickness, Nlayers, d_spacing, sigma_d, sld, sld_solvent); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -296,40 +290,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_line.comp b/mcstas-comps/sasmodels/SasView_line.comp index e074d32c3c..1c130d3770 100644 --- a/mcstas-comps/sasmodels/SasView_line.comp +++ b/mcstas-comps/sasmodels/SasView_line.comp @@ -109,108 +109,103 @@ double Iq_line(double q, double intercept, double slope) { INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - Iq_out = Iq_line(q, intercept, slope); - + Iq_out = Iq_line (q, intercept, slope); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -218,40 +213,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_linear_pearls.comp b/mcstas-comps/sasmodels/SasView_linear_pearls.comp index 8d04a53494..6783faf571 100644 --- a/mcstas-comps/sasmodels/SasView_linear_pearls.comp +++ b/mcstas-comps/sasmodels/SasView_linear_pearls.comp @@ -249,114 +249,108 @@ double Iq_linear_pearls(double q, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_radius=radius; - if ( pd_radius!=0.0 ){ - trace_radius = (randnorm()*pd_radius+1.0)*radius; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_radius = radius; + if (pd_radius != 0.0) { + trace_radius = (randnorm () * pd_radius + 1.0) * radius; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - Iq_out = Iq_linear_pearls(q, trace_radius, edge_sep, num_pearls, sld, sld_solvent); - + Iq_out = Iq_linear_pearls (q, trace_radius, edge_sep, num_pearls, sld, sld_solvent); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -364,40 +358,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_lorentz.comp b/mcstas-comps/sasmodels/SasView_lorentz.comp index 2452108ae5..70299484ac 100644 --- a/mcstas-comps/sasmodels/SasView_lorentz.comp +++ b/mcstas-comps/sasmodels/SasView_lorentz.comp @@ -102,114 +102,108 @@ double Iq_lorentz(double q, double cor_length) INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_cor_length=cor_length; - if ( pd_cor_length!=0.0 ){ - trace_cor_length = (randnorm()*pd_cor_length+1.0)*cor_length; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_cor_length = cor_length; + if (pd_cor_length != 0.0) { + trace_cor_length = (randnorm () * pd_cor_length + 1.0) * cor_length; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - Iq_out = Iq_lorentz(q, trace_cor_length); - + Iq_out = Iq_lorentz (q, trace_cor_length); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -217,40 +211,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_mass_fractal.comp b/mcstas-comps/sasmodels/SasView_mass_fractal.comp index 88da4fd94e..519ff481eb 100644 --- a/mcstas-comps/sasmodels/SasView_mass_fractal.comp +++ b/mcstas-comps/sasmodels/SasView_mass_fractal.comp @@ -362,116 +362,110 @@ Iq_mass_fractal(double q, double radius, double fractal_dim_mass, double cutoff_ INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_radius=radius; - double trace_cutoff_length=cutoff_length; - if ( pd_radius!=0.0 || pd_cutoff_length!=0.0 ){ - trace_radius = (randnorm()*pd_radius+1.0)*radius; - trace_cutoff_length = (randnorm()*pd_cutoff_length+1.0)*cutoff_length; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_radius = radius; + double trace_cutoff_length = cutoff_length; + if (pd_radius != 0.0 || pd_cutoff_length != 0.0) { + trace_radius = (randnorm () * pd_radius + 1.0) * radius; + trace_cutoff_length = (randnorm () * pd_cutoff_length + 1.0) * cutoff_length; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - Iq_out = Iq_mass_fractal(q, trace_radius, fractal_dim_mass, trace_cutoff_length); - + Iq_out = Iq_mass_fractal (q, trace_radius, fractal_dim_mass, trace_cutoff_length); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -479,40 +473,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_mass_surface_fractal.comp b/mcstas-comps/sasmodels/SasView_mass_surface_fractal.comp index d277130a23..9f9bf2af99 100644 --- a/mcstas-comps/sasmodels/SasView_mass_surface_fractal.comp +++ b/mcstas-comps/sasmodels/SasView_mass_surface_fractal.comp @@ -123,116 +123,110 @@ Iq_mass_surface_fractal(double q, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_rg_cluster=rg_cluster; - double trace_rg_primary=rg_primary; - if ( pd_rg_cluster!=0.0 || pd_rg_primary!=0.0 ){ - trace_rg_cluster = (randnorm()*pd_rg_cluster+1.0)*rg_cluster; - trace_rg_primary = (randnorm()*pd_rg_primary+1.0)*rg_primary; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_rg_cluster = rg_cluster; + double trace_rg_primary = rg_primary; + if (pd_rg_cluster != 0.0 || pd_rg_primary != 0.0) { + trace_rg_cluster = (randnorm () * pd_rg_cluster + 1.0) * rg_cluster; + trace_rg_primary = (randnorm () * pd_rg_primary + 1.0) * rg_primary; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - Iq_out = Iq_mass_surface_fractal(q, fractal_dim_mass, fractal_dim_surf, trace_rg_cluster, trace_rg_primary); - + Iq_out = Iq_mass_surface_fractal (q, fractal_dim_mass, fractal_dim_surf, trace_rg_cluster, trace_rg_primary); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -240,40 +234,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_mono_gauss_coil.comp b/mcstas-comps/sasmodels/SasView_mono_gauss_coil.comp index c19e06425d..08fa226627 100644 --- a/mcstas-comps/sasmodels/SasView_mono_gauss_coil.comp +++ b/mcstas-comps/sasmodels/SasView_mono_gauss_coil.comp @@ -164,114 +164,108 @@ Iq_mono_gauss_coil(double q, double i_zero, double rg) INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_rg=rg; - if ( pd_rg!=0.0 ){ - trace_rg = (randnorm()*pd_rg+1.0)*rg; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_rg = rg; + if (pd_rg != 0.0) { + trace_rg = (randnorm () * pd_rg + 1.0) * rg; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - Iq_out = Iq_mono_gauss_coil(q, i_zero, trace_rg); - + Iq_out = Iq_mono_gauss_coil (q, i_zero, trace_rg); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -279,40 +273,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_multilayer_vesicle.comp b/mcstas-comps/sasmodels/SasView_multilayer_vesicle.comp index 47111768ea..5c8bba5c26 100644 --- a/mcstas-comps/sasmodels/SasView_multilayer_vesicle.comp +++ b/mcstas-comps/sasmodels/SasView_multilayer_vesicle.comp @@ -261,120 +261,114 @@ Fq_multilayer_vesicle(double q, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_radius=radius; - double trace_thick_shell=thick_shell; - double trace_thick_solvent=thick_solvent; - if ( pd_radius!=0.0 || pd_thick_shell!=0.0 || pd_thick_solvent!=0.0 ){ - trace_radius = (randnorm()*pd_radius+1.0)*radius; - trace_thick_shell = (randnorm()*pd_thick_shell+1.0)*thick_shell; - trace_thick_solvent = (randnorm()*pd_thick_solvent+1.0)*thick_solvent; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_radius = radius; + double trace_thick_shell = thick_shell; + double trace_thick_solvent = thick_solvent; + if (pd_radius != 0.0 || pd_thick_shell != 0.0 || pd_thick_solvent != 0.0) { + trace_radius = (randnorm () * pd_radius + 1.0) * radius; + trace_thick_shell = (randnorm () * pd_thick_shell + 1.0) * thick_shell; + trace_thick_solvent = (randnorm () * pd_thick_solvent + 1.0) * thick_solvent; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - double F1=0.0, F2=0.0; - Fq_multilayer_vesicle(q, &F1, &F2, volfraction, trace_radius, trace_thick_shell, trace_thick_solvent, sld_solvent, sld, n_shells); + double F1 = 0.0, F2 = 0.0; + Fq_multilayer_vesicle (q, &F1, &F2, volfraction, trace_radius, trace_thick_shell, trace_thick_solvent, sld_solvent, sld, n_shells); Iq_out = F2; - float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -382,40 +376,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_onion.comp b/mcstas-comps/sasmodels/SasView_onion.comp index 3fc1ff7b91..13b9f31e4b 100644 --- a/mcstas-comps/sasmodels/SasView_onion.comp +++ b/mcstas-comps/sasmodels/SasView_onion.comp @@ -254,118 +254,112 @@ Fq_onion(double q, double *F1, double *F2, double sld_core, double radius_core, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_radius_core=radius_core; - double trace_thickness[n_shells]=thickness[n_shells]; - if ( pd_radius_core!=0.0 || pd_thickness[n_shells]!=0.0 ){ - trace_radius_core = (randnorm()*pd_radius_core+1.0)*radius_core; - trace_thickness[n_shells] = (randnorm()*pd_thickness[n_shells]+1.0)*thickness[n_shells]; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_radius_core = radius_core; + double trace_thickness[n_shells] = thickness[n_shells]; + if (pd_radius_core != 0.0 || pd_thickness[n_shells] != 0.0) { + trace_radius_core = (randnorm () * pd_radius_core + 1.0) * radius_core; + trace_thickness[n_shells] = (randnorm () * pd_thickness[n_shells] + 1.0) * thickness[n_shells]; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - double F1=0.0, F2=0.0; - Fq_onion(q, &F1, &F2, sld_core, trace_radius_core, sld_solvent, n_shells, sld_in[n_shells], sld_out[n_shells], trace_thickness[n_shells], A[n_shells]); + double F1 = 0.0, F2 = 0.0; + Fq_onion (q, &F1, &F2, sld_core, trace_radius_core, sld_solvent, n_shells, sld_in[n_shells], sld_out[n_shells], trace_thickness[n_shells], A[n_shells]); Iq_out = F2; - float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -373,40 +367,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_parallelepiped.comp b/mcstas-comps/sasmodels/SasView_parallelepiped.comp index 78e2ae07f9..bac6ffffa8 100644 --- a/mcstas-comps/sasmodels/SasView_parallelepiped.comp +++ b/mcstas-comps/sasmodels/SasView_parallelepiped.comp @@ -427,120 +427,114 @@ Iqabc_parallelepiped(double qa, double qb, double qc, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_length_a=length_a; - double trace_length_b=length_b; - double trace_length_c=length_c; - if ( pd_length_a!=0.0 || pd_length_b!=0.0 || pd_length_c!=0.0 ){ - trace_length_a = (randnorm()*pd_length_a+1.0)*length_a; - trace_length_b = (randnorm()*pd_length_b+1.0)*length_b; - trace_length_c = (randnorm()*pd_length_c+1.0)*length_c; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_length_a = length_a; + double trace_length_b = length_b; + double trace_length_c = length_c; + if (pd_length_a != 0.0 || pd_length_b != 0.0 || pd_length_c != 0.0) { + trace_length_a = (randnorm () * pd_length_a + 1.0) * length_a; + trace_length_b = (randnorm () * pd_length_b + 1.0) * length_b; + trace_length_c = (randnorm () * pd_length_c + 1.0) * length_c; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - double F1=0.0, F2=0.0; - Fq_parallelepiped(q, &F1, &F2, sld, sld_solvent, trace_length_a, trace_length_b, trace_length_c); + double F1 = 0.0, F2 = 0.0; + Fq_parallelepiped (q, &F1, &F2, sld, sld_solvent, trace_length_a, trace_length_b, trace_length_c); Iq_out = F2; - float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -548,40 +542,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_parallelepiped_aniso.comp b/mcstas-comps/sasmodels/SasView_parallelepiped_aniso.comp index 60c02efe9a..26b82de2b8 100644 --- a/mcstas-comps/sasmodels/SasView_parallelepiped_aniso.comp +++ b/mcstas-comps/sasmodels/SasView_parallelepiped_aniso.comp @@ -436,134 +436,129 @@ Iqabc_parallelepiped(double qa, double qb, double qc, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_length_a=length_a; - double trace_length_b=length_b; - double trace_length_c=length_c; - if ( pd_length_a!=0.0 || pd_length_b!=0.0 || pd_length_c!=0.0 ){ - trace_length_a = (randnorm()*pd_length_a+1.0)*length_a; - trace_length_b = (randnorm()*pd_length_b+1.0)*length_b; - trace_length_c = (randnorm()*pd_length_c+1.0)*length_c; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_length_a = length_a; + double trace_length_b = length_b; + double trace_length_c = length_c; + if (pd_length_a != 0.0 || pd_length_b != 0.0 || pd_length_c != 0.0) { + trace_length_a = (randnorm () * pd_length_a + 1.0) * length_a; + trace_length_b = (randnorm () * pd_length_b + 1.0) * length_b; + trace_length_c = (randnorm () * pd_length_c + 1.0) * length_c; } - - double trace_theta=theta, dtheta=0.0; - double trace_phi=phi, dphi=0.0; - double trace_Psi=Psi, dPsi=0.0; - if ( pd_theta!=0.0 || pd_phi!=0.0 || pd_Psi!=0.0 ){ - trace_theta = ((rand01()-0.5)*pd_theta + 1.0)*theta; - dtheta = trace_theta-theta; - trace_phi = ((rand01()-0.5)*pd_phi + 1.0)*phi; - dphi = trace_phi-phi; - trace_Psi = ((rand01()-0.5)*pd_Psi + 1.0)*Psi; - dPsi = trace_Psi-Psi; + double trace_theta = theta, dtheta = 0.0; + double trace_phi = phi, dphi = 0.0; + double trace_Psi = Psi, dPsi = 0.0; + if (pd_theta != 0.0 || pd_phi != 0.0 || pd_Psi != 0.0) { + trace_theta = ((rand01 () - 0.5) * pd_theta + 1.0) * theta; + dtheta = trace_theta - theta; + trace_phi = ((rand01 () - 0.5) * pd_phi + 1.0) * phi; + dphi = trace_phi - phi; + trace_Psi = ((rand01 () - 0.5) * pd_Psi + 1.0) * Psi; + dPsi = trace_Psi - Psi; } - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - double qa=0.0, qb=0.0, qc=0.0; + double qa = 0.0, qb = 0.0, qc = 0.0; QABCRotation rotation; - qabc_rotation(&rotation, trace_theta, trace_phi, trace_Psi, dtheta, dphi, dPsi); - qabc_apply(&rotation, qx, qy, &qa, &qb, &qc); - Iq_out = Iqabc_parallelepiped(qa, qb, qc, sld, sld_solvent, trace_length_a, trace_length_b, trace_length_c ); - + qabc_rotation (&rotation, trace_theta, trace_phi, trace_Psi, dtheta, dphi, dPsi); + qabc_apply (&rotation, qx, qy, &qa, &qb, &qc); + Iq_out = Iqabc_parallelepiped (qa, qb, qc, sld, sld_solvent, trace_length_a, trace_length_b, trace_length_c); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -571,40 +566,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_peak_lorentz.comp b/mcstas-comps/sasmodels/SasView_peak_lorentz.comp index 8456b2d94c..78bc37a093 100644 --- a/mcstas-comps/sasmodels/SasView_peak_lorentz.comp +++ b/mcstas-comps/sasmodels/SasView_peak_lorentz.comp @@ -109,108 +109,103 @@ double Iq_peak_lorentz(double q, double peak_pos, double peak_hwhm) { INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - Iq_out = Iq_peak_lorentz(q, peak_pos, peak_hwhm); - + Iq_out = Iq_peak_lorentz (q, peak_pos, peak_hwhm); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -218,40 +213,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_pearl_necklace.comp b/mcstas-comps/sasmodels/SasView_pearl_necklace.comp index 0503e59686..2348dc82e9 100644 --- a/mcstas-comps/sasmodels/SasView_pearl_necklace.comp +++ b/mcstas-comps/sasmodels/SasView_pearl_necklace.comp @@ -319,116 +319,110 @@ double Iq_pearl_necklace(double q, double radius, double edge_sep, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_radius=radius; - double trace_thick_string=thick_string; - if ( pd_radius!=0.0 || pd_thick_string!=0.0 ){ - trace_radius = (randnorm()*pd_radius+1.0)*radius; - trace_thick_string = (randnorm()*pd_thick_string+1.0)*thick_string; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_radius = radius; + double trace_thick_string = thick_string; + if (pd_radius != 0.0 || pd_thick_string != 0.0) { + trace_radius = (randnorm () * pd_radius + 1.0) * radius; + trace_thick_string = (randnorm () * pd_thick_string + 1.0) * thick_string; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - Iq_out = Iq_pearl_necklace(q, trace_radius, edge_sep, trace_thick_string, num_pearls, sld, sld_string, sld_solvent); - + Iq_out = Iq_pearl_necklace (q, trace_radius, edge_sep, trace_thick_string, num_pearls, sld, sld_string, sld_solvent); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -436,40 +430,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_poly_gauss_coil.comp b/mcstas-comps/sasmodels/SasView_poly_gauss_coil.comp index 6bc85548d6..97d56ba9cf 100644 --- a/mcstas-comps/sasmodels/SasView_poly_gauss_coil.comp +++ b/mcstas-comps/sasmodels/SasView_poly_gauss_coil.comp @@ -131,114 +131,108 @@ double Iq_poly_gauss_coil(double q, double i_zero, double rg, double polydispers INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_rg=rg; - if ( pd_rg!=0.0 ){ - trace_rg = (randnorm()*pd_rg+1.0)*rg; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_rg = rg; + if (pd_rg != 0.0) { + trace_rg = (randnorm () * pd_rg + 1.0) * rg; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - Iq_out = Iq_poly_gauss_coil(q, i_zero, trace_rg, polydispersity); - + Iq_out = Iq_poly_gauss_coil (q, i_zero, trace_rg, polydispersity); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -246,40 +240,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_polymer_excl_volume.comp b/mcstas-comps/sasmodels/SasView_polymer_excl_volume.comp index 97b9ec2b4c..4e92c37134 100644 --- a/mcstas-comps/sasmodels/SasView_polymer_excl_volume.comp +++ b/mcstas-comps/sasmodels/SasView_polymer_excl_volume.comp @@ -141,114 +141,108 @@ double Iq_polymer_excl_volume(double q, double rg, double porod_exp) { INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_rg=rg; - if ( pd_rg!=0.0 ){ - trace_rg = (randnorm()*pd_rg+1.0)*rg; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_rg = rg; + if (pd_rg != 0.0) { + trace_rg = (randnorm () * pd_rg + 1.0) * rg; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - Iq_out = Iq_polymer_excl_volume(q, trace_rg, porod_exp); - + Iq_out = Iq_polymer_excl_volume (q, trace_rg, porod_exp); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -256,40 +250,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_polymer_micelle.comp b/mcstas-comps/sasmodels/SasView_polymer_micelle.comp index 149fff01b1..0a5f120ab9 100644 --- a/mcstas-comps/sasmodels/SasView_polymer_micelle.comp +++ b/mcstas-comps/sasmodels/SasView_polymer_micelle.comp @@ -271,116 +271,110 @@ double Iq_polymer_micelle(double q, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_radius_core=radius_core; - double trace_rg=rg; - if ( pd_radius_core!=0.0 || pd_rg!=0.0 ){ - trace_radius_core = (randnorm()*pd_radius_core+1.0)*radius_core; - trace_rg = (randnorm()*pd_rg+1.0)*rg; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_radius_core = radius_core; + double trace_rg = rg; + if (pd_radius_core != 0.0 || pd_rg != 0.0) { + trace_radius_core = (randnorm () * pd_radius_core + 1.0) * radius_core; + trace_rg = (randnorm () * pd_rg + 1.0) * rg; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - Iq_out = Iq_polymer_micelle(q, ndensity, v_core, v_corona, sld_solvent, sld_core, sld_corona, trace_radius_core, trace_rg, d_penetration, n_aggreg); - + Iq_out = Iq_polymer_micelle (q, ndensity, v_core, v_corona, sld_solvent, sld_core, sld_corona, trace_radius_core, trace_rg, d_penetration, n_aggreg); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -388,40 +382,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_porod.comp b/mcstas-comps/sasmodels/SasView_porod.comp index a264bba97f..be181a5ac9 100644 --- a/mcstas-comps/sasmodels/SasView_porod.comp +++ b/mcstas-comps/sasmodels/SasView_porod.comp @@ -104,108 +104,103 @@ double Iq_porod(double q) { INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - Iq_out = Iq_porod(q); - + Iq_out = Iq_porod (q); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -213,40 +208,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_power_law.comp b/mcstas-comps/sasmodels/SasView_power_law.comp index da3e51842b..4c02da8fc9 100644 --- a/mcstas-comps/sasmodels/SasView_power_law.comp +++ b/mcstas-comps/sasmodels/SasView_power_law.comp @@ -107,108 +107,103 @@ double Iq_power_law(double q, double power) { INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - Iq_out = Iq_power_law(q, power); - + Iq_out = Iq_power_law (q, power); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -216,40 +211,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_pringle.comp b/mcstas-comps/sasmodels/SasView_pringle.comp index 27e432da1f..1155b1f4f3 100644 --- a/mcstas-comps/sasmodels/SasView_pringle.comp +++ b/mcstas-comps/sasmodels/SasView_pringle.comp @@ -1282,116 +1282,110 @@ double Iq_pringle( INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_radius=radius; - double trace_thickness=thickness; - if ( pd_radius!=0.0 || pd_thickness!=0.0 ){ - trace_radius = (randnorm()*pd_radius+1.0)*radius; - trace_thickness = (randnorm()*pd_thickness+1.0)*thickness; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_radius = radius; + double trace_thickness = thickness; + if (pd_radius != 0.0 || pd_thickness != 0.0) { + trace_radius = (randnorm () * pd_radius + 1.0) * radius; + trace_thickness = (randnorm () * pd_thickness + 1.0) * thickness; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - Iq_out = Iq_pringle(q, trace_radius, trace_thickness, alpha, beta, sld, sld_solvent); - + Iq_out = Iq_pringle (q, trace_radius, trace_thickness, alpha, beta, sld, sld_solvent); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -1399,40 +1393,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_raspberry.comp b/mcstas-comps/sasmodels/SasView_raspberry.comp index 21a2e22911..1967ac1a6c 100644 --- a/mcstas-comps/sasmodels/SasView_raspberry.comp +++ b/mcstas-comps/sasmodels/SasView_raspberry.comp @@ -279,116 +279,110 @@ double Iq_raspberry(double q, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_radius_lg=radius_lg; - double trace_radius_sm=radius_sm; - if ( pd_radius_lg!=0.0 || pd_radius_sm!=0.0 ){ - trace_radius_lg = (randnorm()*pd_radius_lg+1.0)*radius_lg; - trace_radius_sm = (randnorm()*pd_radius_sm+1.0)*radius_sm; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_radius_lg = radius_lg; + double trace_radius_sm = radius_sm; + if (pd_radius_lg != 0.0 || pd_radius_sm != 0.0) { + trace_radius_lg = (randnorm () * pd_radius_lg + 1.0) * radius_lg; + trace_radius_sm = (randnorm () * pd_radius_sm + 1.0) * radius_sm; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - Iq_out = Iq_raspberry(q, sld_lg, sld_sm, sld_solvent, volfraction_lg, volfraction_sm, surface_fraction, trace_radius_lg, trace_radius_sm, penetration); - + Iq_out = Iq_raspberry (q, sld_lg, sld_sm, sld_solvent, volfraction_lg, volfraction_sm, surface_fraction, trace_radius_lg, trace_radius_sm, penetration); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -396,40 +390,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_rectangular_prism.comp b/mcstas-comps/sasmodels/SasView_rectangular_prism.comp index 5437f01f6a..d0e3303364 100644 --- a/mcstas-comps/sasmodels/SasView_rectangular_prism.comp +++ b/mcstas-comps/sasmodels/SasView_rectangular_prism.comp @@ -87,114 +87,108 @@ SHARE %{ INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_length_a=length_a; - if ( pd_length_a!=0.0 ){ - trace_length_a = (randnorm()*pd_length_a+1.0)*length_a; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_length_a = length_a; + if (pd_length_a != 0.0) { + trace_length_a = (randnorm () * pd_length_a + 1.0) * length_a; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - Iq_out = Iq(q, sld, sld_solvent, trace_length_a, b2a_ratio, c2a_ratio); - + Iq_out = Iq (q, sld, sld_solvent, trace_length_a, b2a_ratio, c2a_ratio); float vol; - vol = form_volume(trace_length_a, b2a_ratio, c2a_ratio); + vol = form_volume (trace_length_a, b2a_ratio, c2a_ratio); // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -202,40 +196,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_rectangular_prism_aniso.comp b/mcstas-comps/sasmodels/SasView_rectangular_prism_aniso.comp index 7ddf3fcd77..bec090f741 100644 --- a/mcstas-comps/sasmodels/SasView_rectangular_prism_aniso.comp +++ b/mcstas-comps/sasmodels/SasView_rectangular_prism_aniso.comp @@ -494,130 +494,125 @@ Iqabc_rectangular_prism(double qa, double qb, double qc, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_length_a=length_a; - if ( pd_length_a!=0.0 ){ - trace_length_a = (randnorm()*pd_length_a+1.0)*length_a; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_length_a = length_a; + if (pd_length_a != 0.0) { + trace_length_a = (randnorm () * pd_length_a + 1.0) * length_a; } - - double trace_theta=theta, dtheta=0.0; - double trace_phi=phi, dphi=0.0; - double trace_Psi=Psi, dPsi=0.0; - if ( pd_theta!=0.0 || pd_phi!=0.0 || pd_Psi!=0.0 ){ - trace_theta = ((rand01()-0.5)*pd_theta + 1.0)*theta; - dtheta = trace_theta-theta; - trace_phi = ((rand01()-0.5)*pd_phi + 1.0)*phi; - dphi = trace_phi-phi; - trace_Psi = ((rand01()-0.5)*pd_Psi + 1.0)*Psi; - dPsi = trace_Psi-Psi; + double trace_theta = theta, dtheta = 0.0; + double trace_phi = phi, dphi = 0.0; + double trace_Psi = Psi, dPsi = 0.0; + if (pd_theta != 0.0 || pd_phi != 0.0 || pd_Psi != 0.0) { + trace_theta = ((rand01 () - 0.5) * pd_theta + 1.0) * theta; + dtheta = trace_theta - theta; + trace_phi = ((rand01 () - 0.5) * pd_phi + 1.0) * phi; + dphi = trace_phi - phi; + trace_Psi = ((rand01 () - 0.5) * pd_Psi + 1.0) * Psi; + dPsi = trace_Psi - Psi; } - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - double qa=0.0, qb=0.0, qc=0.0; + double qa = 0.0, qb = 0.0, qc = 0.0; QABCRotation rotation; - qabc_rotation(&rotation, trace_theta, trace_phi, trace_Psi, dtheta, dphi, dPsi); - qabc_apply(&rotation, qx, qy, &qa, &qb, &qc); - Iq_out = Iqabc_rectangular_prism(qa, qb, qc, sld, sld_solvent, trace_length_a, b2a_ratio, c2a_ratio ); - + qabc_rotation (&rotation, trace_theta, trace_phi, trace_Psi, dtheta, dphi, dPsi); + qabc_apply (&rotation, qx, qy, &qa, &qb, &qc); + Iq_out = Iqabc_rectangular_prism (qa, qb, qc, sld, sld_solvent, trace_length_a, b2a_ratio, c2a_ratio); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -625,40 +620,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_rpa.comp b/mcstas-comps/sasmodels/SasView_rpa.comp index 27a4d38b71..c0a116073d 100644 --- a/mcstas-comps/sasmodels/SasView_rpa.comp +++ b/mcstas-comps/sasmodels/SasView_rpa.comp @@ -734,108 +734,103 @@ switch(icase){ INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - Iq_out = Iq_rpa(q, case_num, N[4], Phi[4], v[4], L[4], b[4], K12, K13, K14, K23, K24, K34); - + Iq_out = Iq_rpa (q, case_num, N[4], Phi[4], v[4], L[4], b[4], K12, K13, K14, K23, K24, K34); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -843,40 +838,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_sc_paracrystal.comp b/mcstas-comps/sasmodels/SasView_sc_paracrystal.comp index b2dd18074e..11938392e3 100644 --- a/mcstas-comps/sasmodels/SasView_sc_paracrystal.comp +++ b/mcstas-comps/sasmodels/SasView_sc_paracrystal.comp @@ -624,114 +624,108 @@ Iqabc_sc_paracrystal(double qa, double qb, double qc, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_radius=radius; - if ( pd_radius!=0.0 ){ - trace_radius = (randnorm()*pd_radius+1.0)*radius; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_radius = radius; + if (pd_radius != 0.0) { + trace_radius = (randnorm () * pd_radius + 1.0) * radius; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - Iq_out = Iq_sc_paracrystal(q, dnn, d_factor, trace_radius, sld, sld_solvent); - + Iq_out = Iq_sc_paracrystal (q, dnn, d_factor, trace_radius, sld, sld_solvent); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -739,40 +733,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_sc_paracrystal_aniso.comp b/mcstas-comps/sasmodels/SasView_sc_paracrystal_aniso.comp index f6397e5c7c..e53bd75ba9 100644 --- a/mcstas-comps/sasmodels/SasView_sc_paracrystal_aniso.comp +++ b/mcstas-comps/sasmodels/SasView_sc_paracrystal_aniso.comp @@ -633,130 +633,125 @@ Iqabc_sc_paracrystal(double qa, double qb, double qc, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_radius=radius; - if ( pd_radius!=0.0 ){ - trace_radius = (randnorm()*pd_radius+1.0)*radius; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_radius = radius; + if (pd_radius != 0.0) { + trace_radius = (randnorm () * pd_radius + 1.0) * radius; } - - double trace_theta=theta, dtheta=0.0; - double trace_phi=phi, dphi=0.0; - double trace_Psi=Psi, dPsi=0.0; - if ( pd_theta!=0.0 || pd_phi!=0.0 || pd_Psi!=0.0 ){ - trace_theta = ((rand01()-0.5)*pd_theta + 1.0)*theta; - dtheta = trace_theta-theta; - trace_phi = ((rand01()-0.5)*pd_phi + 1.0)*phi; - dphi = trace_phi-phi; - trace_Psi = ((rand01()-0.5)*pd_Psi + 1.0)*Psi; - dPsi = trace_Psi-Psi; + double trace_theta = theta, dtheta = 0.0; + double trace_phi = phi, dphi = 0.0; + double trace_Psi = Psi, dPsi = 0.0; + if (pd_theta != 0.0 || pd_phi != 0.0 || pd_Psi != 0.0) { + trace_theta = ((rand01 () - 0.5) * pd_theta + 1.0) * theta; + dtheta = trace_theta - theta; + trace_phi = ((rand01 () - 0.5) * pd_phi + 1.0) * phi; + dphi = trace_phi - phi; + trace_Psi = ((rand01 () - 0.5) * pd_Psi + 1.0) * Psi; + dPsi = trace_Psi - Psi; } - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - double qa=0.0, qb=0.0, qc=0.0; + double qa = 0.0, qb = 0.0, qc = 0.0; QABCRotation rotation; - qabc_rotation(&rotation, trace_theta, trace_phi, trace_Psi, dtheta, dphi, dPsi); - qabc_apply(&rotation, qx, qy, &qa, &qb, &qc); - Iq_out = Iqabc_sc_paracrystal(qa, qb, qc, dnn, d_factor, trace_radius, sld, sld_solvent ); - + qabc_rotation (&rotation, trace_theta, trace_phi, trace_Psi, dtheta, dphi, dPsi); + qabc_apply (&rotation, qx, qy, &qa, &qb, &qc); + Iq_out = Iqabc_sc_paracrystal (qa, qb, qc, dnn, d_factor, trace_radius, sld, sld_solvent); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -764,40 +759,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_sphere.comp b/mcstas-comps/sasmodels/SasView_sphere.comp index 3a2c97f7dd..d4fb137fe2 100644 --- a/mcstas-comps/sasmodels/SasView_sphere.comp +++ b/mcstas-comps/sasmodels/SasView_sphere.comp @@ -189,116 +189,110 @@ static void Fq_sphere(double q, double *f1, double *f2, double sld, double sld_s INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_radius=radius; - if ( pd_radius!=0.0 ){ - trace_radius = (randnorm()*pd_radius+1.0)*radius; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_radius = radius; + if (pd_radius != 0.0) { + trace_radius = (randnorm () * pd_radius + 1.0) * radius; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - double F1=0.0, F2=0.0; - Fq_sphere(q, &F1, &F2, sld, sld_solvent, trace_radius); + double F1 = 0.0, F2 = 0.0; + Fq_sphere (q, &F1, &F2, sld, sld_solvent, trace_radius); Iq_out = F2; - float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -306,40 +300,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_spinodal.comp b/mcstas-comps/sasmodels/SasView_spinodal.comp index 73d420aaac..f783c78f5d 100644 --- a/mcstas-comps/sasmodels/SasView_spinodal.comp +++ b/mcstas-comps/sasmodels/SasView_spinodal.comp @@ -109,108 +109,103 @@ double Iq_spinodal(double q, double gamma, double q_0) { INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - Iq_out = Iq_spinodal(q, gamma, q_0); - + Iq_out = Iq_spinodal (q, gamma, q_0); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -218,40 +213,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_squarewell.comp b/mcstas-comps/sasmodels/SasView_squarewell.comp index 5cfe07d157..3635da7a37 100644 --- a/mcstas-comps/sasmodels/SasView_squarewell.comp +++ b/mcstas-comps/sasmodels/SasView_squarewell.comp @@ -149,114 +149,108 @@ double Iq_squarewell(double q, double radius_effective, double volfraction, doub INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_radius_effective=radius_effective; - if ( pd_radius_effective!=0.0 ){ - trace_radius_effective = (randnorm()*pd_radius_effective+1.0)*radius_effective; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_radius_effective = radius_effective; + if (pd_radius_effective != 0.0) { + trace_radius_effective = (randnorm () * pd_radius_effective + 1.0) * radius_effective; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - Iq_out = Iq_squarewell(q, trace_radius_effective, volfraction, welldepth, wellwidth); - + Iq_out = Iq_squarewell (q, trace_radius_effective, volfraction, welldepth, wellwidth); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -264,40 +258,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_stacked_disks.comp b/mcstas-comps/sasmodels/SasView_stacked_disks.comp index 9731b20a4e..3e74ea11d8 100644 --- a/mcstas-comps/sasmodels/SasView_stacked_disks.comp +++ b/mcstas-comps/sasmodels/SasView_stacked_disks.comp @@ -828,118 +828,112 @@ Iqac_stacked_disks(double qab, double qc, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_thick_core=thick_core; - double trace_thick_layer=thick_layer; - double trace_radius=radius; - if ( pd_thick_core!=0.0 || pd_thick_layer!=0.0 || pd_radius!=0.0 ){ - trace_thick_core = (randnorm()*pd_thick_core+1.0)*thick_core; - trace_thick_layer = (randnorm()*pd_thick_layer+1.0)*thick_layer; - trace_radius = (randnorm()*pd_radius+1.0)*radius; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_thick_core = thick_core; + double trace_thick_layer = thick_layer; + double trace_radius = radius; + if (pd_thick_core != 0.0 || pd_thick_layer != 0.0 || pd_radius != 0.0) { + trace_thick_core = (randnorm () * pd_thick_core + 1.0) * thick_core; + trace_thick_layer = (randnorm () * pd_thick_layer + 1.0) * thick_layer; + trace_radius = (randnorm () * pd_radius + 1.0) * radius; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - Iq_out = Iq_stacked_disks(q, trace_thick_core, trace_thick_layer, trace_radius, n_stacking, sigma_d, sld_core, sld_layer, sld_solvent); - + Iq_out = Iq_stacked_disks (q, trace_thick_core, trace_thick_layer, trace_radius, n_stacking, sigma_d, sld_core, sld_layer, sld_solvent); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -947,40 +941,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_stacked_disks_aniso.comp b/mcstas-comps/sasmodels/SasView_stacked_disks_aniso.comp index f080fc8dcd..a330d90db2 100644 --- a/mcstas-comps/sasmodels/SasView_stacked_disks_aniso.comp +++ b/mcstas-comps/sasmodels/SasView_stacked_disks_aniso.comp @@ -834,131 +834,126 @@ Iqac_stacked_disks(double qab, double qc, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_thick_core=thick_core; - double trace_thick_layer=thick_layer; - double trace_radius=radius; - if ( pd_thick_core!=0.0 || pd_thick_layer!=0.0 || pd_radius!=0.0 ){ - trace_thick_core = (randnorm()*pd_thick_core+1.0)*thick_core; - trace_thick_layer = (randnorm()*pd_thick_layer+1.0)*thick_layer; - trace_radius = (randnorm()*pd_radius+1.0)*radius; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_thick_core = thick_core; + double trace_thick_layer = thick_layer; + double trace_radius = radius; + if (pd_thick_core != 0.0 || pd_thick_layer != 0.0 || pd_radius != 0.0) { + trace_thick_core = (randnorm () * pd_thick_core + 1.0) * thick_core; + trace_thick_layer = (randnorm () * pd_thick_layer + 1.0) * thick_layer; + trace_radius = (randnorm () * pd_radius + 1.0) * radius; } - - double trace_theta=theta, dtheta=0.0; - double trace_phi=phi, dphi=0.0; - if ( pd_theta!=0.0 || pd_phi!=0.0 ){ - trace_theta = ((rand01()-0.5)*pd_theta + 1.0)*theta; - dtheta = trace_theta-theta; - trace_phi = ((rand01()-0.5)*pd_phi + 1.0)*phi; - dphi = trace_phi-phi; + double trace_theta = theta, dtheta = 0.0; + double trace_phi = phi, dphi = 0.0; + if (pd_theta != 0.0 || pd_phi != 0.0) { + trace_theta = ((rand01 () - 0.5) * pd_theta + 1.0) * theta; + dtheta = trace_theta - theta; + trace_phi = ((rand01 () - 0.5) * pd_phi + 1.0) * phi; + dphi = trace_phi - phi; } - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - double qab=0.0, qc=0.0; + double qab = 0.0, qc = 0.0; QACRotation rotation; - qac_rotation(&rotation, trace_theta, trace_phi, dtheta, dphi); - qac_apply(&rotation, qx, qy, &qab, &qc); - Iq_out = Iqac_stacked_disks(qab, qc, trace_thick_core, trace_thick_layer, trace_radius, n_stacking, sigma_d, sld_core, sld_layer, sld_solvent ); - + qac_rotation (&rotation, trace_theta, trace_phi, dtheta, dphi); + qac_apply (&rotation, qx, qy, &qab, &qc); + Iq_out = Iqac_stacked_disks (qab, qc, trace_thick_core, trace_thick_layer, trace_radius, n_stacking, sigma_d, sld_core, sld_layer, sld_solvent); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -966,40 +961,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_star_polymer.comp b/mcstas-comps/sasmodels/SasView_star_polymer.comp index c0cdde2970..b2b3fc198f 100644 --- a/mcstas-comps/sasmodels/SasView_star_polymer.comp +++ b/mcstas-comps/sasmodels/SasView_star_polymer.comp @@ -127,114 +127,108 @@ double Iq_star_polymer(double q, double radius2, double arms) INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_rg_squared=rg_squared; - if ( pd_rg_squared!=0.0 ){ - trace_rg_squared = (randnorm()*pd_rg_squared+1.0)*rg_squared; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_rg_squared = rg_squared; + if (pd_rg_squared != 0.0) { + trace_rg_squared = (randnorm () * pd_rg_squared + 1.0) * rg_squared; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - Iq_out = Iq_star_polymer(q, trace_rg_squared, arms); - + Iq_out = Iq_star_polymer (q, trace_rg_squared, arms); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -242,40 +236,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_stickyhardsphere.comp b/mcstas-comps/sasmodels/SasView_stickyhardsphere.comp index 74d0c4097d..c1731cfada 100644 --- a/mcstas-comps/sasmodels/SasView_stickyhardsphere.comp +++ b/mcstas-comps/sasmodels/SasView_stickyhardsphere.comp @@ -170,114 +170,108 @@ double Iq_stickyhardsphere(double q, double radius_effective, double volfraction INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_radius_effective=radius_effective; - if ( pd_radius_effective!=0.0 ){ - trace_radius_effective = (randnorm()*pd_radius_effective+1.0)*radius_effective; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_radius_effective = radius_effective; + if (pd_radius_effective != 0.0) { + trace_radius_effective = (randnorm () * pd_radius_effective + 1.0) * radius_effective; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - Iq_out = Iq_stickyhardsphere(q, trace_radius_effective, volfraction, perturb, stickiness); - + Iq_out = Iq_stickyhardsphere (q, trace_radius_effective, volfraction, perturb, stickiness); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -285,40 +279,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_superball.comp b/mcstas-comps/sasmodels/SasView_superball.comp index 686d629c41..8ac85a421d 100644 --- a/mcstas-comps/sasmodels/SasView_superball.comp +++ b/mcstas-comps/sasmodels/SasView_superball.comp @@ -498,116 +498,110 @@ Iqabc_superball(double qa, double qb, double qc, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_length_a=length_a; - if ( pd_length_a!=0.0 ){ - trace_length_a = (randnorm()*pd_length_a+1.0)*length_a; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_length_a = length_a; + if (pd_length_a != 0.0) { + trace_length_a = (randnorm () * pd_length_a + 1.0) * length_a; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - double F1=0.0, F2=0.0; - Fq_superball(q, &F1, &F2, sld, sld_solvent, trace_length_a, exponent_p); + double F1 = 0.0, F2 = 0.0; + Fq_superball (q, &F1, &F2, sld, sld_solvent, trace_length_a, exponent_p); Iq_out = F2; - float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -615,40 +609,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_superball_aniso.comp b/mcstas-comps/sasmodels/SasView_superball_aniso.comp index 1c221515e0..fa1b8a61e5 100644 --- a/mcstas-comps/sasmodels/SasView_superball_aniso.comp +++ b/mcstas-comps/sasmodels/SasView_superball_aniso.comp @@ -507,130 +507,125 @@ Iqabc_superball(double qa, double qb, double qc, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_length_a=length_a; - if ( pd_length_a!=0.0 ){ - trace_length_a = (randnorm()*pd_length_a+1.0)*length_a; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_length_a = length_a; + if (pd_length_a != 0.0) { + trace_length_a = (randnorm () * pd_length_a + 1.0) * length_a; } - - double trace_theta=theta, dtheta=0.0; - double trace_phi=phi, dphi=0.0; - double trace_Psi=Psi, dPsi=0.0; - if ( pd_theta!=0.0 || pd_phi!=0.0 || pd_Psi!=0.0 ){ - trace_theta = ((rand01()-0.5)*pd_theta + 1.0)*theta; - dtheta = trace_theta-theta; - trace_phi = ((rand01()-0.5)*pd_phi + 1.0)*phi; - dphi = trace_phi-phi; - trace_Psi = ((rand01()-0.5)*pd_Psi + 1.0)*Psi; - dPsi = trace_Psi-Psi; + double trace_theta = theta, dtheta = 0.0; + double trace_phi = phi, dphi = 0.0; + double trace_Psi = Psi, dPsi = 0.0; + if (pd_theta != 0.0 || pd_phi != 0.0 || pd_Psi != 0.0) { + trace_theta = ((rand01 () - 0.5) * pd_theta + 1.0) * theta; + dtheta = trace_theta - theta; + trace_phi = ((rand01 () - 0.5) * pd_phi + 1.0) * phi; + dphi = trace_phi - phi; + trace_Psi = ((rand01 () - 0.5) * pd_Psi + 1.0) * Psi; + dPsi = trace_Psi - Psi; } - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - double qa=0.0, qb=0.0, qc=0.0; + double qa = 0.0, qb = 0.0, qc = 0.0; QABCRotation rotation; - qabc_rotation(&rotation, trace_theta, trace_phi, trace_Psi, dtheta, dphi, dPsi); - qabc_apply(&rotation, qx, qy, &qa, &qb, &qc); - Iq_out = Iqabc_superball(qa, qb, qc, sld, sld_solvent, trace_length_a, exponent_p ); - + qabc_rotation (&rotation, trace_theta, trace_phi, trace_Psi, dtheta, dphi, dPsi); + qabc_apply (&rotation, qx, qy, &qa, &qb, &qc); + Iq_out = Iqabc_superball (qa, qb, qc, sld, sld_solvent, trace_length_a, exponent_p); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -638,40 +633,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_surface_fractal.comp b/mcstas-comps/sasmodels/SasView_surface_fractal.comp index ee554779b3..52ce472ee1 100644 --- a/mcstas-comps/sasmodels/SasView_surface_fractal.comp +++ b/mcstas-comps/sasmodels/SasView_surface_fractal.comp @@ -381,116 +381,110 @@ double Iq_surface_fractal(double q, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_radius=radius; - double trace_cutoff_length=cutoff_length; - if ( pd_radius!=0.0 || pd_cutoff_length!=0.0 ){ - trace_radius = (randnorm()*pd_radius+1.0)*radius; - trace_cutoff_length = (randnorm()*pd_cutoff_length+1.0)*cutoff_length; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_radius = radius; + double trace_cutoff_length = cutoff_length; + if (pd_radius != 0.0 || pd_cutoff_length != 0.0) { + trace_radius = (randnorm () * pd_radius + 1.0) * radius; + trace_cutoff_length = (randnorm () * pd_cutoff_length + 1.0) * cutoff_length; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - Iq_out = Iq_surface_fractal(q, trace_radius, fractal_dim_surf, trace_cutoff_length); - + Iq_out = Iq_surface_fractal (q, trace_radius, fractal_dim_surf, trace_cutoff_length); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -498,40 +492,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_teubner_strey.comp b/mcstas-comps/sasmodels/SasView_teubner_strey.comp index b6ecdfc12b..7d4e3ca7dc 100644 --- a/mcstas-comps/sasmodels/SasView_teubner_strey.comp +++ b/mcstas-comps/sasmodels/SasView_teubner_strey.comp @@ -122,108 +122,103 @@ double Iq_teubner_strey(double q, double volfraction_a, double sld_a, double sld INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - Iq_out = Iq_teubner_strey(q, volfraction_a, sld_a, sld_b, d, xi); - + Iq_out = Iq_teubner_strey (q, volfraction_a, sld_a, sld_b, d, xi); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -231,40 +226,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_triaxial_ellipsoid.comp b/mcstas-comps/sasmodels/SasView_triaxial_ellipsoid.comp index dd434c7354..c34b9ef05a 100644 --- a/mcstas-comps/sasmodels/SasView_triaxial_ellipsoid.comp +++ b/mcstas-comps/sasmodels/SasView_triaxial_ellipsoid.comp @@ -513,120 +513,114 @@ Iqabc_triaxial_ellipsoid(double qa, double qb, double qc, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_radius_equat_minor=radius_equat_minor; - double trace_radius_equat_major=radius_equat_major; - double trace_radius_polar=radius_polar; - if ( pd_radius_equat_minor!=0.0 || pd_radius_equat_major!=0.0 || pd_radius_polar!=0.0 ){ - trace_radius_equat_minor = (randnorm()*pd_radius_equat_minor+1.0)*radius_equat_minor; - trace_radius_equat_major = (randnorm()*pd_radius_equat_major+1.0)*radius_equat_major; - trace_radius_polar = (randnorm()*pd_radius_polar+1.0)*radius_polar; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_radius_equat_minor = radius_equat_minor; + double trace_radius_equat_major = radius_equat_major; + double trace_radius_polar = radius_polar; + if (pd_radius_equat_minor != 0.0 || pd_radius_equat_major != 0.0 || pd_radius_polar != 0.0) { + trace_radius_equat_minor = (randnorm () * pd_radius_equat_minor + 1.0) * radius_equat_minor; + trace_radius_equat_major = (randnorm () * pd_radius_equat_major + 1.0) * radius_equat_major; + trace_radius_polar = (randnorm () * pd_radius_polar + 1.0) * radius_polar; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - double F1=0.0, F2=0.0; - Fq_triaxial_ellipsoid(q, &F1, &F2, sld, sld_solvent, trace_radius_equat_minor, trace_radius_equat_major, trace_radius_polar); + double F1 = 0.0, F2 = 0.0; + Fq_triaxial_ellipsoid (q, &F1, &F2, sld, sld_solvent, trace_radius_equat_minor, trace_radius_equat_major, trace_radius_polar); Iq_out = F2; - float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -634,40 +628,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_triaxial_ellipsoid_aniso.comp b/mcstas-comps/sasmodels/SasView_triaxial_ellipsoid_aniso.comp index 07d0ba1bdc..27ab4e8d2a 100644 --- a/mcstas-comps/sasmodels/SasView_triaxial_ellipsoid_aniso.comp +++ b/mcstas-comps/sasmodels/SasView_triaxial_ellipsoid_aniso.comp @@ -522,134 +522,129 @@ Iqabc_triaxial_ellipsoid(double qa, double qb, double qc, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_radius_equat_minor=radius_equat_minor; - double trace_radius_equat_major=radius_equat_major; - double trace_radius_polar=radius_polar; - if ( pd_radius_equat_minor!=0.0 || pd_radius_equat_major!=0.0 || pd_radius_polar!=0.0 ){ - trace_radius_equat_minor = (randnorm()*pd_radius_equat_minor+1.0)*radius_equat_minor; - trace_radius_equat_major = (randnorm()*pd_radius_equat_major+1.0)*radius_equat_major; - trace_radius_polar = (randnorm()*pd_radius_polar+1.0)*radius_polar; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_radius_equat_minor = radius_equat_minor; + double trace_radius_equat_major = radius_equat_major; + double trace_radius_polar = radius_polar; + if (pd_radius_equat_minor != 0.0 || pd_radius_equat_major != 0.0 || pd_radius_polar != 0.0) { + trace_radius_equat_minor = (randnorm () * pd_radius_equat_minor + 1.0) * radius_equat_minor; + trace_radius_equat_major = (randnorm () * pd_radius_equat_major + 1.0) * radius_equat_major; + trace_radius_polar = (randnorm () * pd_radius_polar + 1.0) * radius_polar; } - - double trace_theta=theta, dtheta=0.0; - double trace_phi=phi, dphi=0.0; - double trace_Psi=Psi, dPsi=0.0; - if ( pd_theta!=0.0 || pd_phi!=0.0 || pd_Psi!=0.0 ){ - trace_theta = ((rand01()-0.5)*pd_theta + 1.0)*theta; - dtheta = trace_theta-theta; - trace_phi = ((rand01()-0.5)*pd_phi + 1.0)*phi; - dphi = trace_phi-phi; - trace_Psi = ((rand01()-0.5)*pd_Psi + 1.0)*Psi; - dPsi = trace_Psi-Psi; + double trace_theta = theta, dtheta = 0.0; + double trace_phi = phi, dphi = 0.0; + double trace_Psi = Psi, dPsi = 0.0; + if (pd_theta != 0.0 || pd_phi != 0.0 || pd_Psi != 0.0) { + trace_theta = ((rand01 () - 0.5) * pd_theta + 1.0) * theta; + dtheta = trace_theta - theta; + trace_phi = ((rand01 () - 0.5) * pd_phi + 1.0) * phi; + dphi = trace_phi - phi; + trace_Psi = ((rand01 () - 0.5) * pd_Psi + 1.0) * Psi; + dPsi = trace_Psi - Psi; } - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - double qa=0.0, qb=0.0, qc=0.0; + double qa = 0.0, qb = 0.0, qc = 0.0; QABCRotation rotation; - qabc_rotation(&rotation, trace_theta, trace_phi, trace_Psi, dtheta, dphi, dPsi); - qabc_apply(&rotation, qx, qy, &qa, &qb, &qc); - Iq_out = Iqabc_triaxial_ellipsoid(qa, qb, qc, sld, sld_solvent, trace_radius_equat_minor, trace_radius_equat_major, trace_radius_polar ); - + qabc_rotation (&rotation, trace_theta, trace_phi, trace_Psi, dtheta, dphi, dPsi); + qabc_apply (&rotation, qx, qy, &qa, &qb, &qc); + Iq_out = Iqabc_triaxial_ellipsoid (qa, qb, qc, sld, sld_solvent, trace_radius_equat_minor, trace_radius_equat_major, trace_radius_polar); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -657,40 +652,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_two_lorentzian.comp b/mcstas-comps/sasmodels/SasView_two_lorentzian.comp index 7b017a7e26..b149f15497 100644 --- a/mcstas-comps/sasmodels/SasView_two_lorentzian.comp +++ b/mcstas-comps/sasmodels/SasView_two_lorentzian.comp @@ -133,116 +133,110 @@ double Iq_two_lorentzian(double q, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_lorentz_length_1=lorentz_length_1; - double trace_lorentz_length_2=lorentz_length_2; - if ( pd_lorentz_length_1!=0.0 || pd_lorentz_length_2!=0.0 ){ - trace_lorentz_length_1 = (randnorm()*pd_lorentz_length_1+1.0)*lorentz_length_1; - trace_lorentz_length_2 = (randnorm()*pd_lorentz_length_2+1.0)*lorentz_length_2; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_lorentz_length_1 = lorentz_length_1; + double trace_lorentz_length_2 = lorentz_length_2; + if (pd_lorentz_length_1 != 0.0 || pd_lorentz_length_2 != 0.0) { + trace_lorentz_length_1 = (randnorm () * pd_lorentz_length_1 + 1.0) * lorentz_length_1; + trace_lorentz_length_2 = (randnorm () * pd_lorentz_length_2 + 1.0) * lorentz_length_2; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - Iq_out = Iq_two_lorentzian(q, lorentz_scale_1, trace_lorentz_length_1, lorentz_exp_1, lorentz_scale_2, trace_lorentz_length_2, lorentz_exp_2); - + Iq_out = Iq_two_lorentzian (q, lorentz_scale_1, trace_lorentz_length_1, lorentz_exp_1, lorentz_scale_2, trace_lorentz_length_2, lorentz_exp_2); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -250,40 +244,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_two_power_law.comp b/mcstas-comps/sasmodels/SasView_two_power_law.comp index 1d99156580..c0d8514131 100644 --- a/mcstas-comps/sasmodels/SasView_two_power_law.comp +++ b/mcstas-comps/sasmodels/SasView_two_power_law.comp @@ -120,108 +120,103 @@ double Iq_two_power_law(double q, double coefficent_1, double crossover, double INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - Iq_out = Iq_two_power_law(q, coefficent_1, crossover, power_1, power_2); - + Iq_out = Iq_two_power_law (q, coefficent_1, crossover, power_1, power_2); float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -229,40 +224,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END diff --git a/mcstas-comps/sasmodels/SasView_vesicle.comp b/mcstas-comps/sasmodels/SasView_vesicle.comp index f90dc077cd..7fbd6c57b0 100644 --- a/mcstas-comps/sasmodels/SasView_vesicle.comp +++ b/mcstas-comps/sasmodels/SasView_vesicle.comp @@ -236,118 +236,112 @@ Fq_vesicle(double q, INITIALIZE %{ -shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ -if (xwidth && yheight && zdepth) - shape=1; + shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */ + if (xwidth && yheight && zdepth) + shape = 1; else if (R > 0 && yheight) - shape=0; + shape = 0; else if (R > 0 && !yheight) - shape=2; + shape = 2; if (shape < 0) - exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n" - "ERROR Please check parameter values.\n", NAME_CURRENT_COMP)); + exit (fprintf (stderr, + "SasView_model: %s: sample has invalid dimensions.\n" + "ERROR Please check parameter values.\n", + NAME_CURRENT_COMP)); /* now compute target coords if a component index is supplied */ - if (!target_index && !target_x && !target_y && !target_z) target_index=1; - if (target_index) - { + if (!target_index && !target_x && !target_y && !target_z) + target_index = 1; + if (target_index) { Coords ToTarget; - ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); - ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); - coords_get(ToTarget, &target_x, &target_y, &target_z); + ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP); + ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget); + coords_get (ToTarget, &target_x, &target_y, &target_z); } if (!(target_x || target_y || target_z)) { - printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", - NAME_CURRENT_COMP); - target_z=1; + printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP); + target_z = 1; } - my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ - + my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */ %} TRACE %{ double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s; - double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z; + double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z; double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z; double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz; - char intersect=0; + char intersect = 0; /* Intersection neutron trajectory / sample (sample surface) */ - if (shape == 0){ - intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);} - else if (shape == 1){ - intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);} - else if (shape == 2){ - intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);} - if(intersect) - { - if(t0 < 0) + if (shape == 0) { + intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight); + } else if (shape == 1) { + intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth); + } else if (shape == 2) { + intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R); + } + if (intersect) { + if (t0 < 0) ABSORB; /* Neutron enters at t=t0. */ - v = sqrt(vx*vx + vy*vy + vz*vz); + v = sqrt (vx * vx + vy * vy + vz * vz); l_full = v * (t1 - t0); /* Length of full path through sample */ - dt = rand01()*(t1 - t0) + t0; /* Time of scattering */ - PROP_DT(dt); /* Point of scattering */ - l = v*(dt-t0); /* Penetration in sample */ + dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */ + PROP_DT (dt); /* Point of scattering */ + l = v * (dt - t0); /* Penetration in sample */ - vx_i=vx; - vy_i=vy; - vz_i=vz; + vx_i = vx; + vy_i = vy; + vz_i = vz; if ((target_x || target_y || target_z)) { - aim_x = target_x-x; /* Vector pointing at target (anal./det.) */ - aim_y = target_y-y; - aim_z = target_z-z; + aim_x = target_x - x; /* Vector pointing at target (anal./det.) */ + aim_y = target_y - y; + aim_z = target_z - z; } - if(focus_aw && focus_ah) { - randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); - } else if(focus_xw && focus_yh) { - randvec_target_rect(&vx, &vy, &vz, &solid_angle, - aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); + if (focus_aw && focus_ah) { + randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP); + } else if (focus_xw && focus_yh) { + randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP); } else { - randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); + randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r); } - NORM(vx, vy, vz); + NORM (vx, vy, vz); vx *= v; vy *= v; vz *= v; - qx = V2K*(vx_i-vx); - qy = V2K*(vy_i-vy); - qz = V2K*(vz_i-vz); - q = sqrt(qx*qx+qy*qy+qz*qz); - - double trace_radius=radius; - double trace_thickness=thickness; - if ( pd_radius!=0.0 || pd_thickness!=0.0 ){ - trace_radius = (randnorm()*pd_radius+1.0)*radius; - trace_thickness = (randnorm()*pd_thickness+1.0)*thickness; + qx = V2K * (vx_i - vx); + qy = V2K * (vy_i - vy); + qz = V2K * (vz_i - vz); + q = sqrt (qx * qx + qy * qy + qz * qz); + + double trace_radius = radius; + double trace_thickness = thickness; + if (pd_radius != 0.0 || pd_thickness != 0.0) { + trace_radius = (randnorm () * pd_radius + 1.0) * radius; + trace_thickness = (randnorm () * pd_thickness + 1.0) * thickness; } - - - // Sample dependent. Retrieved from SasView.///////////////////// float Iq_out; Iq_out = 1; - double F1=0.0, F2=0.0; - Fq_vesicle(q, &F1, &F2, sld, sld_solvent, volfraction, trace_radius, trace_thickness); + double F1 = 0.0, F2 = 0.0; + Fq_vesicle (q, &F1, &F2, sld, sld_solvent, volfraction, trace_radius, trace_thickness); Iq_out = F2; - float vol; vol = 1; // Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m] - Iq_out = model_scale*Iq_out / vol * 1.0E2; + Iq_out = model_scale * Iq_out / vol * 1.0E2; - l_1 = v*t1; - p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v); + l_1 = v * t1; + p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v); SCATTER; } %} @@ -355,40 +349,30 @@ TRACE MCDISPLAY %{ - if (shape == 0) { /* cylinder */ - circle("xz", 0, yheight/2.0, 0, R); - circle("xz", 0, -yheight/2.0, 0, R); - line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0); - line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0); - line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R); - line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R); - } - else if (shape == 1) { /* box */ - double xmin = -0.5*xwidth; - double xmax = 0.5*xwidth; - double ymin = -0.5*yheight; - double ymax = 0.5*yheight; - double zmin = -0.5*zdepth; - double zmax = 0.5*zdepth; - multiline(5, xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymin, zmin); - multiline(5, xmin, ymin, zmax, - xmax, ymin, zmax, - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax); - line(xmin, ymin, zmin, xmin, ymin, zmax); - line(xmax, ymin, zmin, xmax, ymin, zmax); - line(xmin, ymax, zmin, xmin, ymax, zmax); - line(xmax, ymax, zmin, xmax, ymax, zmax); - } - else if (shape == 2) { /* sphere */ - circle("xy", 0, 0.0, 0, R); - circle("xz", 0, 0.0, 0, R); - circle("yz", 0, 0.0, 0, R); + if (shape == 0) { /* cylinder */ + circle ("xz", 0, yheight / 2.0, 0, R); + circle ("xz", 0, -yheight / 2.0, 0, R); + line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0); + line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0); + line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R); + line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R); + } else if (shape == 1) { /* box */ + double xmin = -0.5 * xwidth; + double xmax = 0.5 * xwidth; + double ymin = -0.5 * yheight; + double ymax = 0.5 * yheight; + double zmin = -0.5 * zdepth; + double zmax = 0.5 * zdepth; + multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin); + multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax); + line (xmin, ymin, zmin, xmin, ymin, zmax); + line (xmax, ymin, zmin, xmax, ymin, zmax); + line (xmin, ymax, zmin, xmin, ymax, zmax); + line (xmax, ymax, zmin, xmax, ymax, zmax); + } else if (shape == 2) { /* sphere */ + circle ("xy", 0, 0.0, 0, R); + circle ("xz", 0, 0.0, 0, R); + circle ("yz", 0, 0.0, 0, R); } %} END