Search code examples
randomequationmodelica

algebraic operation with normal random values in Modelica


I've got such code in Modelica:

model BioPowerSetup
  Modelica.Blocks.Interfaces.RealOutput BioPowerOutput;
  parameter Real alpha=0.05;
  parameter Real mu1=7/25;
  Real Nmax=25;
  parameter Real D=0.2;
  Modelica.Blocks.Noise.TruncatedNormalNoise Noise(
    y_min=-0.028,
    y_max=0.028,
    samplePeriod=1);
equation 
  if BioPowerOutput < 489100 then
    BioPowerOutput = alpha*mu1*(Nmax*exp(mu1*time));
  else
    BioPowerOutput = 489100*exp(Noise.y*time);
  end if;
end BioPowerSetup;

After compiling this program, it interrupts on the 55s with such error:

Warning: [EVENT]  Mixed block did not converge during event iteration. [b4»]   [@55.0 s] 
Error: [GENERAL] Mid-simulation event iteration didn't converge. [@55.0 s]

I will be glad of any help!

I think, that error is located in the algebraic operation with noise value, but I don't know what to do with it.


Solution

  • I think the code you have got is not really ok and I have done some improvements.

    • Main thing is that the Noise block is made for a time discrete environment with the given samplePeriod. I have made that for you.

    • Here must also be a globalSeed as specified.

    • Further, I think Nmax is a parameter and not a variable.

      model BioPowerSetup 
         parameter Real Nmax = 25;  
         parameter Real alpha = 0.05;   
         parameter Real mu1 = 7 / 25 ;   
         parameter Real D = 0.2 ; 
         parameter Real samplePeriod = 1;   
         Modelica.Blocks.Interfaces.RealOutput BioPowerOutput;    
         Modelica.Blocks.Noise.TruncatedNormalNoise Noise(y_min = -0.028, y_max = 0.028, samplePeriod = samplePeriod); 
            inner Modelica.Blocks.Noise.GlobalSeed globalSeed;
      equation  
         when sample(0, samplePeriod) then
            if BioPowerOutput < 489100 then    
               BioPowerOutput = alpha * mu1 * (Nmax * exp(mu1 * time));   
            else     
               BioPowerOutput = 489100 * exp(Noise.y * time);   
            end if; 
         end when;
      end BioPowerSetup;
      

    Does this make sense to you?

    A first simulation (in OpenModelica) past time 55 seconds is shown below. On the y-axis you have BioPowerOutput.

    enter image description here