0
$\begingroup$

I get the error:

CompiledFunction::cfexe: Could not complete external evaluation; proceeding with uncompiled evaluation.

but I am not using any compiled function in my code: how can it be possible?

Here is my code:

ClearAll["Global`*"]
slab = Cuboid[{0, 0, 0}, {3, 3, 0.3}];
fslab = RegionMember[slab];
me =(*511000/29979200*)511000;
M = 18.95*10^9;
(*c=29979200;*)
z = 10;
ρ = 19.32;
τ[T_?NumericQ] := (20 T)/M ;
β[T_?NumericQ] := Sqrt[1 - (1/(τ[T] + 1))^2];
wm[T_?NumericQ] := (2 me β[T]^2)/(1 - β[T]^2);
Zs[T_?NumericQ] = z (1 - Exp[-((125 β[T])/z^(2/3))]);
(*Numero delta prodotti da protone da 100 MeV*)
Σ[en_] := 
 Integrate[
  0.307075*79/197 (10^6 ρ)/2 (
   10^-4 Zs[en]^2(*Per micrometri*))/(β[
      en]^2 (w)^2) (1 - (β[en]^2 (w))/
     wm[en] + (Pi β[en] Zs[en]^2)/
      137 Sqrt[(w)/wm[en]] (1 - (w)/wm[en])), {w, 1, wm[en]}, 
  GenerateConditions -> False]    

me =(*511000/29979200*)511000;
M = 18.95*10^9;
(*c=29979200;*)
z = 10;
ρ = 19.32;
τ[T_?NumericQ] := (20 T)/M ;
β[T_?NumericQ] := Sqrt[1 - (1/(τ[T] + 1))^2];
wm[T_?NumericQ] := (2 me β[T]^2)/(1 - β[T]^2);
Zs[T_?NumericQ] = z (1 - Exp[-((125 β[T])/z^(2/3))]);
(*Numero delta prodotti da protone da 100 MeV*)


pr[s_] := 
 ProbabilityDistribution[(0.307075*79/196.96655 10^6/2 ρ (
     10^-4 Zs[w]^2(*Per micrometri*))/(β[
        w]^2 (w)^2) (1 - (β[w]^2 (w))/
       wm[w] + (Pi β[w] Zs[w]^2)/
        137 Sqrt[(w)/wm[w]] (1 - (w)/wm[w])))/
   NIntegrate[
    0.307075*79/196.96655 10^6/2 ρ (
     10^-4 Zs[w]^2(*Per micrometri*))/(β[
        w]^2 (w)^2) (1 - (β[w]^2 (w))/
       wm[w] + (Pi β[w] Zs[w]^2)/
        137 Sqrt[(w)/wm[w]] (1 - (w)/wm[w])), {w, 1, s}, 
    MaxRecursion -> 20], {w, 1, s}]

e = 5.5*10^10;
λ[e_] := 1/Σ[e];
ne = 0;
elettrone = {};
dx = 0.001;

Dynamic[ne]
Do[{x, y, s} = {0, 0, 0.3};
 enp = e;
 While[RegionMember[slab, {x, y, s - dx}], nl = -Log[RandomReal[]];
  While[RegionMember[slab, {x, y, s - dx}] && 
    nl - dx/λ[enp] > 0, nl -= dx/λ[enp]; s -= dx];
  ne++;
  energy = RandomVariate[pr[wm[enp]]];
  θ = ArcCos[(wm[enp] + me)/wm[enp]*energy/(energy + me)];
  ϕ = RandomReal[{-Pi, Pi}];
  elettrone = 
   AppendTo[elettrone, {{x, y, s}, θ, ϕ, energy}];
  enp -= energy;], {3}]
ne
elettrone // TableForm;

EDIT

If I substitute τ[T_?NumericQ] := (20 T)/M ; with τ[T_?NumericQ] := (T)/M ; the code works. I think there is a bug lurking somewhere, maybe in ProbabilityDistribution.

EDIT2 I have upgraded to version 11.3 and nothing happens the code runs as it is supposed to do. I think I strumbled upon a bug somewhere.

$\endgroup$
  • $\begingroup$ It seems that my code dies when evaluatiing pr[e]. $\endgroup$ – mattiav27 Sep 7 '18 at 17:27
  • $\begingroup$ NIntegrate will try to compile its integrand. Try to submit Compiled -> False and see whether the warning message disappears. This would localize the issue. Could be an overflow or underflow problem... $\endgroup$ – Henrik Schumacher Sep 7 '18 at 17:30
  • $\begingroup$ But I cannot reproduce the problem with Mma version 11.3 on macOS... $\endgroup$ – Henrik Schumacher Sep 7 '18 at 17:35
  • 1
    $\begingroup$ @HenrikSchumacher that option didin't work $\endgroup$ – mattiav27 Sep 7 '18 at 17:46
  • 1
    $\begingroup$ 10.0 is quite old. I'd recommend upgrading. $\endgroup$ – user6014 Sep 8 '18 at 4:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.