<!DOCTYPE OMNotebook>
<Notebook>
 <GroupCell closed="false" >
  <GroupCell closed="false" >
   <TextCell style="Title" >
    <Text>&lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;/head>&lt;body style=" white-space: pre-wrap; font-family:MS Shell Dlg; font-size:8.25pt; font-weight:400; font-style:normal; text-decoration:none;">&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:Arial; font-size:38pt; font-weight:600; color:#000000;">Terminate&lt;/p>&lt;/body>&lt;/html></Text>
   </TextCell>
   <TextCell style="Text" >
    <Text>&lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;/head>&lt;body style=" white-space: pre-wrap; font-family:MS Shell Dlg; font-size:8.25pt; font-weight:400; font-style:normal; text-decoration:none;">&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:Times New Roman; font-size:12pt; color:#000000;">&lt;br />The most common usage of &lt;span style=" font-family:Courier New;">terminate&lt;/span> is to give a more appropriate stopping criteria for terminating a simulation than a fixed point in time. The &lt;span style=" font-family:Courier New;">terminate&lt;/span> function takes a single argument of type &lt;span style=" font-family:Courier New;">String&lt;/span>, which is used to indicate the reason for a successful termination. This is exemplified in the &lt;span style=" font-family:Courier New;">terminate&lt;/span> statement within the &lt;span style=" font-family:Courier New;">when&lt;/span>-statement in &lt;span style=" font-family:Courier New;">MoonLanding&lt;/span>.&lt;/p>&lt;/body>&lt;/html></Text>
   </TextCell>
   <GroupCell closed="false" >
    <TextCell style="Section" >
     <Text>&lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;/head>&lt;body style=" white-space: pre-wrap; font-family:MS Shell Dlg; font-size:8.25pt; font-weight:400; font-style:normal; text-decoration:none;">&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:Times; font-size:18pt; font-weight:600; color:#000000;">Celestial Body&lt;/p>&lt;/body>&lt;/html></Text>
    </TextCell>
    <InputCell style="Input" closed="true" >
     <Input>class CelestialBody
  constant Real g = 6.672e-11;
  parameter Real radius;
  parameter String name;
  Real mass;
end CelestialBody;</Input>
     <Output></Output>
    </InputCell>
   </GroupCell>
   <GroupCell closed="false" >
    <TextCell style="Section" >
     <Text>&lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;/head>&lt;body style=" white-space: pre-wrap; font-family:MS Shell Dlg; font-size:8.25pt; font-weight:400; font-style:normal; text-decoration:none;">&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:Times; font-size:18pt; font-weight:600; color:#000000;">Rocket&lt;/p>&lt;/body>&lt;/html></Text>
    </TextCell>
    <InputCell style="Input" closed="true" >
     <Input>class Rocket
  parameter String name;
  Real mass(start = 1038.358);
  Real altitude(start = 59404);
  Real velocity(start = -2003);
  Real acceleration;
  Real thrust;                    // Thrust force on the rocket
  Real gravity;                    // Gravity forcefield
  parameter Real massLossRate = 0.000277;
equation
  (thrust - mass*gravity)/mass = acceleration;
  der(mass) = -massLossRate * abs(thrust);
  der(altitude) = velocity;
  der(velocity) = acceleration;
end Rocket;  </Input>
     <Output></Output>
    </InputCell>
   </GroupCell>
   <GroupCell closed="false" >
    <TextCell style="Section" >
     <Text>&lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;/head>&lt;body style=" white-space: pre-wrap; font-family:MS Shell Dlg; font-size:8.25pt; font-weight:400; font-style:normal; text-decoration:none;">&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:Times; font-size:18pt; font-weight:600; color:#000000;">MoonLanding&lt;/p>&lt;/body>&lt;/html></Text>
    </TextCell>
    <TextCell style="Text" >
     <Text>&lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;/head>&lt;body style=" white-space: pre-wrap; font-family:MS Shell Dlg; font-size:8.25pt; font-weight:400; font-style:normal; text-decoration:none;">&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:Times New Roman; font-size:12pt; color:#000000;">When using this terminate condition the simulation stops when the moon lander touches the ground on the moon.&lt;/p>&lt;/body>&lt;/html></Text>
    </TextCell>
    <InputCell style="Input" closed="true" >
     <Input>class MoonLanding
  parameter Real force1 = 36350;          
  parameter Real force2 = 1308;
protected                      
  parameter Real thrustEndTime = 210;
  parameter Real thrustDecreaseTime = 43.2;
public            
  Rocket apollo(name = "Apollo13");
  CelestialBody moon(name = "moon", mass = 7.382e22, radius = 1.738e6);
  
equation
  apollo.thrust = if (time &lt; thrustDecreaseTime) then force1
            else if (time &lt; thrustEndTime) then force2
            else 0;
  apollo.gravity = moon.g*moon.mass/(apollo.altitude + moon.radius) ^2;
  
algorithm
  when apollo.altitude &lt; 0 then    // Termination condition
    terminate("The moon lander touches the ground of the moon");
  end when;  
end MoonLanding;  
</Input>
     <Output></Output>
    </InputCell>
   </GroupCell>
   <GroupCell closed="false" >
    <TextCell style="Section" >
     <Text>&lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;/head>&lt;body style=" white-space: pre-wrap; font-family:MS Shell Dlg; font-size:8.25pt; font-weight:400; font-style:normal; text-decoration:none;">&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:Times; font-size:18pt; font-weight:600; color:#000000;">MoonLanding Simulation&lt;/p>&lt;/body>&lt;/html></Text>
    </TextCell>
    <TextCell style="Text" >
     <Text>&lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;/head>&lt;body style=" white-space: pre-wrap; font-family:MS Shell Dlg; font-size:8.25pt; font-weight:400; font-style:normal; text-decoration:none;">&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:Times New Roman; font-size:12pt; color:#000000;">When we simulate the MoonLanding class from 0 to 230 we get a message that the simulation ended before reaching 230. In the dslog.txt file we see that the simulation is terminated at T = 218.&lt;/p>&lt;/body>&lt;/html></Text>
    </TextCell>
    <InputCell style="Input" closed="true" >
     <Input>simulate( MoonLanding, stopTime=230 );</Input>
     <Output></Output>
    </InputCell>
    <TextCell style="" >
     <Text>&lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;/head>&lt;body style=" white-space: pre-wrap; font-family:MS Shell Dlg; font-size:8.25pt; font-weight:400; font-style:normal; text-decoration:none;">&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:8pt;">&lt;span style=" font-family:Times New Roman; font-size:12pt; color:#000000;">Simulate::smft&lt;/span>&lt;/p>&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:Times New Roman; font-size:12pt; color:#000000;">: &lt;/p>&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:Times New Roman; font-size:12pt; color:#000000;">"Simulate ended before reaching \\!\\(230\\)."&lt;/p>&lt;p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:Times New Roman; font-size:12pt; color:#000000;">&lt;/p>&lt;/body>&lt;/html></Text>
    </TextCell>
    <TextCell style="Output" >
     <Text>&lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;/head>&lt;body style=" white-space: pre-wrap; font-family:MS Shell Dlg; font-size:8.25pt; font-weight:400; font-style:normal; text-decoration:none;">&lt;p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:Courier New; font-size:11pt; color:#000000;">&lt;/p>&lt;/body>&lt;/html></Text>
    </TextCell>
    <InputCell style="Input" closed="true" >
     <Input>!! dslog.txt</Input>
     <Output></Output>
    </InputCell>
    <InputCell style="Input" closed="true" >
     <Input>plot( { apollo.velocity, apollo.altitude }, xrange={0,208} );</Input>
     <Output>&lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;/head>&lt;body style=" white-space: pre-wrap; font-family:MS Shell Dlg; font-size:8.25pt; font-weight:400; font-style:normal; text-decoration:none;">&lt;p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:Courier New; font-size:11pt; color:#000000;">&lt;/p>&lt;/body>&lt;/html></Output>
    </InputCell>
    <TextCell style="Text" >
     <Text>&lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;/head>&lt;body style=" white-space: pre-wrap; font-family:MS Shell Dlg; font-size:8.25pt; font-weight:400; font-style:normal; text-decoration:none;">&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:Times New Roman; font-size:12pt; color:#000000;">&lt;img src="file:///C:/OpenModelica132/bin/OMNoteboook_tempfiles/12.png" width="288" height="214" />&lt;/p>&lt;/body>&lt;/html></Text>
     <Image name="file:///C:/OpenModelica132/bin/OMNoteboook_tempfiles/12.png" >AAAAAYlQTkcNChoKAAAADUlIRFIAAAEgAAAA1ggDAAAARuGvAgAAAwBQTFRFAAAAAH8AAAD/2dnZAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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96MnSQzUoRx+WXsmgiOaT6W1BH1q21ISgmTY1NSRoZmrM04tF+ox2NDWXQQkNeGpb0ML0oqguBC1Mb4hqtAadMj1pqqcM2vGEqa4FrUxTLVnbE71V0JVB5QeaUmwHWhqr9vlI7mEXK6dzNoOuZJCY+NMZ/xxJnDaycVLrEvsdULm/dtk8XxcJir4RpdNqFrOgJD9vmlRLaAV5cpIwyOug+7hNUPzrZ8oB26VhkOVYtgPdJ2hZGAz9BhiGSbxQDcr84AE8wB3Ier7aEeGyINuxTAe6sbbYzrREkG1QlG8vCjKfaYEg2yCxze/eS8xQpDM/fnPPoMxvL5+G62biFwoCUBCAggAUBKAgAAUBKAhAQQAKAlAQgIIAFASgIAAFASgI8Bdc9cHM/ZTeiAAAAABJRU5ErkJggg==</Image>
    </TextCell>
    <TextCell style="" >
     <Text>&lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;/head>&lt;body style=" white-space: pre-wrap; font-family:MS Shell Dlg; font-size:8.25pt; font-weight:400; font-style:normal; text-decoration:none;">&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:8pt;">&lt;span style=" font-family:Times New Roman; font-size:12pt; color:#000000;">Vertical &lt;/span>&lt;span style=" font-family:Courier New; font-size:12pt; color:#000000;">velocity&lt;/span>&lt;span style=" font-family:Times New Roman; font-size:12pt; color:#000000;"> relative to the lunar surface and &lt;/span>&lt;span style=" font-family:Courier New; font-size:12pt; color:#000000;">Altitude&lt;/span>&lt;span style=" font-family:Times New Roman; font-size:12pt; color:#000000;"> of the Apollo rocket over the lunar surface.&lt;/span>&lt;/p>&lt;/body>&lt;/html></Text>
    </TextCell>
   </GroupCell>
  </GroupCell>
 </GroupCell>
</Notebook>
