3 replaced http://mathematica.stackexchange.com/ with https://mathematica.stackexchange.com/
source | link

This is a follow-up question about How to delete InterpolationFunction created by NDSolve/ParametricNDSolve?How to delete InterpolationFunction created by NDSolve/ParametricNDSolve?. In the previous question, J. M.♦ and Albert Retey showed $HistoryLength = 0 and Clear[] are uesful to release memory occupied by InterplatingFunction. But in the present question, I found a different memory manage between NDSolve and ParametricNDSolveValue. The code is follows:

This is a follow-up question about How to delete InterpolationFunction created by NDSolve/ParametricNDSolve?. In the previous question, J. M.♦ and Albert Retey showed $HistoryLength = 0 and Clear[] are uesful to release memory occupied by InterplatingFunction. But in the present question, I found a different memory manage between NDSolve and ParametricNDSolveValue. The code is follows:

This is a follow-up question about How to delete InterpolationFunction created by NDSolve/ParametricNDSolve?. In the previous question, J. M.♦ and Albert Retey showed $HistoryLength = 0 and Clear[] are uesful to release memory occupied by InterplatingFunction. But in the present question, I found a different memory manage between NDSolve and ParametricNDSolveValue. The code is follows:

2 deleted 543 characters in body
source | link
(*NDSolve*)
$HistoryLength = 0;
mpl = 1/Sqrt[6.70837*10^-39];
gsT = 106.75;

Sup[\[CapitalLambda]I_Sup[ΛI_?NumericQ, \[CapitalGamma]I_ΓI_?NumericQ] := 
Module[{a, \[Rho]rρr, Trad, tf, s, t, result}, tf = 10/\[CapitalGamma]I;ΓI;
s = NDSolve[{a'[t] == 
  a[t]*Sqrt[(8 \[Pi]π)/(3 mpl^2) (\[Rho]r[ρr[
        t] + \[CapitalLambda]I^4ΛI^4/
         a[t]^3 Exp[-\[CapitalGamma]IΓI t])], \[Rho]r'[t]ρr'[t] + 
   4*Sqrt[(8 \[Pi]π)/(3 mpl^2) (\[Rho]r[ρr[
         t] + \[CapitalLambda]I^4ΛI^4/
          a[t]^3 Exp[-\[CapitalGamma]IΓI t])] \[Rho]r[ρr[
     t] == \[CapitalGamma]IΓI \[CapitalLambda]I^4ΛI^4/
    a[t]^3 Exp[-\[CapitalGamma]IΓI t], 
 a[0] == 1, \[Rho]r[0]ρr[0] == 0}, {a, \[Rho]rρr}, {t, 0, tf}];
 {a = a /. s[[1]], \[Rho]rρr = \[Rho]rρr /. s[[1]]};
 result = \[Rho]r[tf]*a[tf];ρr[tf]*a[tf];
 Remove[tf]; Remove[Trad]; Remove[s]; Remove[a]; Remove[\[Rho]r];Remove[ρr]; 
 Remove[t];
 result]
Do[(Module[{s, as}, 
s = ParametricNDSolveValue[{a'[t] == 
   a[t]*Sqrt[(8 \[Pi]π)/(3 mpl^2) (\[Rho]r[ρr[
         t] + \[CapitalLambda]I^4ΛI^4/
          a[t]^3 Exp[-\[CapitalGamma]IΓI t])], \[Rho]r'[t]ρr'[t] + 
    4*Sqrt[(8 \[Pi]π)/(3 mpl^2) (\[Rho]r[ρr[
          t] + \[CapitalLambda]I^4ΛI^4/
           a[t]^3 Exp[-\[CapitalGamma]IΓI t])] \[Rho]r[ρr[
      t] == \[CapitalGamma]IΓI \[CapitalLambda]I^4ΛI^4/
     a[t]^3 Exp[-\[CapitalGamma]IΓI t], 
  a[0] == 1, \[Rho]r[0]ρr[0] == 0}, {a, \[Rho]rρr}, {t, 0, 
  tf}, {\[CapitalLambda]IΛI, \[CapitalGamma]IΓI, tf}]; 
  as = s[2.2, time, time/10]; Remove[s]; Remove[as];]), {time, 1, 10000,  0.1}]
s = ParametricNDSolveValue[{a'[t] == 
 a[t]*Sqrt[(8 \[Pi]π)/(3 mpl^2) (\[Rho]r[ρr[
       t] + \[CapitalLambda]I^4ΛI^4/
        a[t]^3 Exp[-\[CapitalGamma]IΓI t])], \[Rho]r'[t]ρr'[t] + 
  4*Sqrt[(8 \[Pi]π)/(3 mpl^2) (\[Rho]r[ρr[
        t] + \[CapitalLambda]I^4ΛI^4/
         a[t]^3 Exp[-\[CapitalGamma]IΓI t])] \[Rho]r[ρr[
    t] == \[CapitalGamma]IΓI \[CapitalLambda]I^4ΛI^4/
   a[t]^3 Exp[-\[CapitalGamma]IΓI t], 
a[0] == 1, \[Rho]r[0]ρr[0] == 0}, {a, \[Rho]rρr}, {t, 0, 
tf}, {\[CapitalLambda]IΛI, \[CapitalGamma]IΓI, tf}];
Do[(Module[{as}, as = s[2.2, time, time/10]; Remove[as];]), {time, 1, 
 10000, 0.1}]
(*NDSolve*)
$HistoryLength = 0;
mpl = 1/Sqrt[6.70837*10^-39];
gsT = 106.75;

Sup[\[CapitalLambda]I_?NumericQ, \[CapitalGamma]I_?NumericQ] := 
Module[{a, \[Rho]r, Trad, tf, s, t, result}, tf = 10/\[CapitalGamma]I;
s = NDSolve[{a'[t] == 
  a[t]*Sqrt[(8 \[Pi])/(3 mpl^2) (\[Rho]r[
        t] + \[CapitalLambda]I^4/
         a[t]^3 Exp[-\[CapitalGamma]I t])], \[Rho]r'[t] + 
   4*Sqrt[(8 \[Pi])/(3 mpl^2) (\[Rho]r[
         t] + \[CapitalLambda]I^4/
          a[t]^3 Exp[-\[CapitalGamma]I t])] \[Rho]r[
     t] == \[CapitalGamma]I \[CapitalLambda]I^4/
    a[t]^3 Exp[-\[CapitalGamma]I t], 
 a[0] == 1, \[Rho]r[0] == 0}, {a, \[Rho]r}, {t, 0, tf}];
 {a = a /. s[[1]], \[Rho]r = \[Rho]r /. s[[1]]};
 result = \[Rho]r[tf]*a[tf];
 Remove[tf]; Remove[Trad]; Remove[s]; Remove[a]; Remove[\[Rho]r]; 
 Remove[t];
 result]
Do[(Module[{s, as}, 
s = ParametricNDSolveValue[{a'[t] == 
   a[t]*Sqrt[(8 \[Pi])/(3 mpl^2) (\[Rho]r[
         t] + \[CapitalLambda]I^4/
          a[t]^3 Exp[-\[CapitalGamma]I t])], \[Rho]r'[t] + 
    4*Sqrt[(8 \[Pi])/(3 mpl^2) (\[Rho]r[
          t] + \[CapitalLambda]I^4/
           a[t]^3 Exp[-\[CapitalGamma]I t])] \[Rho]r[
      t] == \[CapitalGamma]I \[CapitalLambda]I^4/
     a[t]^3 Exp[-\[CapitalGamma]I t], 
  a[0] == 1, \[Rho]r[0] == 0}, {a, \[Rho]r}, {t, 0, 
  tf}, {\[CapitalLambda]I, \[CapitalGamma]I, tf}]; 
  as = s[2.2, time, time/10]; Remove[s]; Remove[as];]), {time, 1, 10000,  0.1}]
s = ParametricNDSolveValue[{a'[t] == 
 a[t]*Sqrt[(8 \[Pi])/(3 mpl^2) (\[Rho]r[
       t] + \[CapitalLambda]I^4/
        a[t]^3 Exp[-\[CapitalGamma]I t])], \[Rho]r'[t] + 
  4*Sqrt[(8 \[Pi])/(3 mpl^2) (\[Rho]r[
        t] + \[CapitalLambda]I^4/
         a[t]^3 Exp[-\[CapitalGamma]I t])] \[Rho]r[
    t] == \[CapitalGamma]I \[CapitalLambda]I^4/
   a[t]^3 Exp[-\[CapitalGamma]I t], 
a[0] == 1, \[Rho]r[0] == 0}, {a, \[Rho]r}, {t, 0, 
tf}, {\[CapitalLambda]I, \[CapitalGamma]I, tf}];
Do[(Module[{as}, as = s[2.2, time, time/10]; Remove[as];]), {time, 1, 
 10000, 0.1}]
(*NDSolve*)
$HistoryLength = 0;
mpl = 1/Sqrt[6.70837*10^-39];
gsT = 106.75;

Sup[ΛI_?NumericQ, ΓI_?NumericQ] := 
Module[{a, ρr, Trad, tf, s, t, result}, tf = 10/ΓI;
s = NDSolve[{a'[t] == 
  a[t]*Sqrt[(8 π)/(3 mpl^2) (ρr[
        t] + ΛI^4/
         a[t]^3 Exp[-ΓI t])], ρr'[t] + 
   4*Sqrt[(8 π)/(3 mpl^2) (ρr[
         t] + ΛI^4/
          a[t]^3 Exp[-ΓI t])] ρr[
     t] == ΓI ΛI^4/
    a[t]^3 Exp[-ΓI t], 
 a[0] == 1, ρr[0] == 0}, {a, ρr}, {t, 0, tf}];
 {a = a /. s[[1]], ρr = ρr /. s[[1]]};
 result = ρr[tf]*a[tf];
 Remove[tf]; Remove[Trad]; Remove[s]; Remove[a]; Remove[ρr]; 
 Remove[t];
 result]
Do[(Module[{s, as}, 
s = ParametricNDSolveValue[{a'[t] == 
   a[t]*Sqrt[(8 π)/(3 mpl^2) (ρr[
         t] + ΛI^4/
          a[t]^3 Exp[-ΓI t])], ρr'[t] + 
    4*Sqrt[(8 π)/(3 mpl^2) (ρr[
          t] + ΛI^4/
           a[t]^3 Exp[-ΓI t])] ρr[
      t] == ΓI ΛI^4/
     a[t]^3 Exp[-ΓI t], 
  a[0] == 1, ρr[0] == 0}, {a, ρr}, {t, 0, 
  tf}, {ΛI, ΓI, tf}]; 
  as = s[2.2, time, time/10]; Remove[s]; Remove[as];]), {time, 1, 10000,  0.1}]
s = ParametricNDSolveValue[{a'[t] == 
 a[t]*Sqrt[(8 π)/(3 mpl^2) (ρr[
       t] + ΛI^4/
        a[t]^3 Exp[-ΓI t])], ρr'[t] + 
  4*Sqrt[(8 π)/(3 mpl^2) (ρr[
        t] + ΛI^4/
         a[t]^3 Exp[-ΓI t])] ρr[
    t] == ΓI ΛI^4/
   a[t]^3 Exp[-ΓI t], 
a[0] == 1, ρr[0] == 0}, {a, ρr}, {t, 0, 
tf}, {ΛI, ΓI, tf}];
Do[(Module[{as}, as = s[2.2, time, time/10]; Remove[as];]), {time, 1, 
 10000, 0.1}]
1
source | link

Why does NDSolve and ParametricNDSolveValue show different memory manage in same loop?

This is a follow-up question about How to delete InterpolationFunction created by NDSolve/ParametricNDSolve?. In the previous question, J. M.♦ and Albert Retey showed $HistoryLength = 0 and Clear[] are uesful to release memory occupied by InterplatingFunction. But in the present question, I found a different memory manage between NDSolve and ParametricNDSolveValue. The code is follows:

(*NDSolve*)
$HistoryLength = 0;
mpl = 1/Sqrt[6.70837*10^-39];
gsT = 106.75;

Sup[\[CapitalLambda]I_?NumericQ, \[CapitalGamma]I_?NumericQ] := 
Module[{a, \[Rho]r, Trad, tf, s, t, result}, tf = 10/\[CapitalGamma]I;
s = NDSolve[{a'[t] == 
  a[t]*Sqrt[(8 \[Pi])/(3 mpl^2) (\[Rho]r[
        t] + \[CapitalLambda]I^4/
         a[t]^3 Exp[-\[CapitalGamma]I t])], \[Rho]r'[t] + 
   4*Sqrt[(8 \[Pi])/(3 mpl^2) (\[Rho]r[
         t] + \[CapitalLambda]I^4/
          a[t]^3 Exp[-\[CapitalGamma]I t])] \[Rho]r[
     t] == \[CapitalGamma]I \[CapitalLambda]I^4/
    a[t]^3 Exp[-\[CapitalGamma]I t], 
 a[0] == 1, \[Rho]r[0] == 0}, {a, \[Rho]r}, {t, 0, tf}];
 {a = a /. s[[1]], \[Rho]r = \[Rho]r /. s[[1]]};
 result = \[Rho]r[tf]*a[tf];
 Remove[tf]; Remove[Trad]; Remove[s]; Remove[a]; Remove[\[Rho]r]; 
 Remove[t];
 result]

I use more power clean function Remove[] to replace Clear[], and in the loop

Do[Sup[2.2, time], {time, 1, 10000, 0.1}]

showing a stable memory which is not increaing. But using ParametricNDSolveValue with the same equation and loop, it shows a increasing memory.

Do[(Module[{s, as}, 
s = ParametricNDSolveValue[{a'[t] == 
   a[t]*Sqrt[(8 \[Pi])/(3 mpl^2) (\[Rho]r[
         t] + \[CapitalLambda]I^4/
          a[t]^3 Exp[-\[CapitalGamma]I t])], \[Rho]r'[t] + 
    4*Sqrt[(8 \[Pi])/(3 mpl^2) (\[Rho]r[
          t] + \[CapitalLambda]I^4/
           a[t]^3 Exp[-\[CapitalGamma]I t])] \[Rho]r[
      t] == \[CapitalGamma]I \[CapitalLambda]I^4/
     a[t]^3 Exp[-\[CapitalGamma]I t], 
  a[0] == 1, \[Rho]r[0] == 0}, {a, \[Rho]r}, {t, 0, 
  tf}, {\[CapitalLambda]I, \[CapitalGamma]I, tf}]; 
  as = s[2.2, time, time/10]; Remove[s]; Remove[as];]), {time, 1, 10000,  0.1}]

or

s = ParametricNDSolveValue[{a'[t] == 
 a[t]*Sqrt[(8 \[Pi])/(3 mpl^2) (\[Rho]r[
       t] + \[CapitalLambda]I^4/
        a[t]^3 Exp[-\[CapitalGamma]I t])], \[Rho]r'[t] + 
  4*Sqrt[(8 \[Pi])/(3 mpl^2) (\[Rho]r[
        t] + \[CapitalLambda]I^4/
         a[t]^3 Exp[-\[CapitalGamma]I t])] \[Rho]r[
    t] == \[CapitalGamma]I \[CapitalLambda]I^4/
   a[t]^3 Exp[-\[CapitalGamma]I t], 
a[0] == 1, \[Rho]r[0] == 0}, {a, \[Rho]r}, {t, 0, 
tf}, {\[CapitalLambda]I, \[CapitalGamma]I, tf}];
Do[(Module[{as}, as = s[2.2, time, time/10]; Remove[as];]), {time, 1, 
 10000, 0.1}]

So is there a explain?