Calculate Results from a Model: Difference between revisions

From ReliaWiki
Jump to navigation Jump to search
No edit summary
Line 1: Line 1:
{{Template:API}}
{{Template:API}}{{Template:BacktoPrevPage|[[API Tutorials|<< Back to Tutorials Main Page]]}}
<div style="border:1px solid #AAA; background:#f9f9f9; border-radius:10px; width:auto; margin:0 0 1em 1em; padding:1em; float:right;">
<nowiki><<</nowiki> [[API Tutorials|Back to API Tutorials]]


'''Basics'''
In Synthesis applications, models can represent the reliability of a component, the duration of a task, the expected cost of a repair and many other characteristics. In this tutorial, you'll learn how to calculate some useful metrics from models.
#[[Connect or Disconnect from a Synthesis Repository]]
#[[Add New Synthesis Resources to a Repository]]
#[[Edit Existing Synthesis Resources]]
#[[Calculate Results from a Model]]
</div>


Models are used by other Synthesis resources to represent the reliability of a task, the duration of a task, the expected cost of a repair, and many other characteristics. In this tutorial, you'll learn how to obtain calculated results from models.
==Prerequisites==
Before you begin:


Before you begin, publish a model from the repository and note the model's object ID number (see [[Using Object IDs]]). You will use the object ID number to retrieve the model, so you can compare the results returned by the API with the results obtained from the Quick Calculation Pad (QCP).  
*Create a test repository (can use [http://weibull.reliasoft.com/ Weibull++] or [http://alta.reliasoft.com/ ALTA]). Perform a simple analysis and then publish a model of the analysis. You'll want to use a published model with this tutorial so you can perform confidence bounds calculations.


*Note the published model's object ID number. You will use the ID# to retrieve the model from the database. (To display the object IDs, choose '''File > Application Setup''', then click '''Other''' under the Synthesis Settings heading in the navigation panel. Select the '''Display Object IDs''' check box. The object ID of the model is displayed in the Resource Manager.)




==Tutorial: Calculate Results from a Model==
The following example demonstrates how to obtain calculated results from a model resource. A discussion of the example follows.


 
A VBA version of the code sample is available [[Calculate_Results_from_a_Model/VBA|here]].  
 
 
==Calculate Results from a Model==
1. Create a new module and begin by connecting to a Synthesis repository and project. The following code assumes that a standard repository called "RSRepository1.rsr10" exists in the C drive.
 
{{APIComment|'Connect to the Synthesis repository and set project ID#1 as the current project.}}
  {{APIPrefix|Dim}} MyRepository {{APIPrefix|As New}} Repository
  MyRepository.ConnectToRepository({{APIString|"C:\RSRepository1.rsr10"}})
  MyRepository.Project.SetCurrentProject(1)
 
2. Retrieve a model from the repository. The following code assumes that the repository contains a model with ID number 21.
 
'''VBA'''
{{APIComment|'Retrieve the model with ID# 21 from the repository.}}
  {{APIPrefix|Dim}} Amodel {{APIPrefix|As New}} cModel
  {{APIPrefix|Set}} AModel = MyRepository.Model.GetModel(21)
 
'''VB.NET'''
{{APIComment|'Retrieve the model with ID# 21 from the repository.}}
  {{APIPrefix|Dim}} Amodel {{APIPrefix|As New}} cModel
  AModel = MyRepository.Model.GetModel(21)
 
2. Use the <code>Reliability</code> method to calculate for the reliability at 100 hrs and the <code>MeanTime</code> method to return the mean time to failure.
{{APIComment|'Declare variables.}}
  {{APIPrefix|Dim}} Result1 {{APIPrefix|As}} Double
  {{APIPrefix|Dim}} Result2 {{APIPrefix|As}} Double
{{APIComment|'Calculate the model's reliability at time &#61; 100 hrs and mean time.}}
  Result1 = AModel.Reliability(100)
  Result2 = AModel.MeanTime
 
3. Let's add confidence bounds calculations to the results. Use the <code>SetConfidenceLevel</code> method to specify 90% two-sided confidence bounds.
 
'''VBA'''
{{APIComment|'Set the confidence level to 90% two-sided bounds.}}
{{APIComment|'Declare a string variable for any errors found during this method.}}
  {{APIPrefix|Dim}} ErrorMsg {{APIPrefix|As}} String
  {{APIPrefix|Call}} AModel.SetConfidenceLevel(0.9, ConfBoundsSides_TwoSidedBoth, False, ErrorMsg)
{{APIComment|'Initiate new instances of the BoundsValues class.}}
  {{APIPrefix|Dim}} BResult1 {{APIPrefix|As}} BoundsValues
  {{APIPrefix|Dim}} BResult2 {{APIPrefix|As}} BoundsValues
{{APIComment|'Calculate bounds for the reliability at 100 hrs and the mean time.}}
  {{APIPrefix|Set}} BResult1 = AModel.Bounds_Reliability(100)
  {{APIPrefix|Set}} BResult2 = AModel.Bounds_MeanTime
 
{{APIComment|'Display the output.}}
  MsgBox ({{APIString|"Reliability <nowiki>=</nowiki> "}} & Result1 & vbNewLine & _
          {{APIString|"Upper Bound <nowiki>=</nowiki> "}} & BResult1.upper & vbNewLine & _
          {{APIString|"Lower Bound <nowiki>=</nowiki> "}} & BResult1.lower & vbNewLine)
  MsgBox ({{APIString|"Mean Time <nowiki>=</nowiki> "}} & Result2 & vbNewLine & _
          {{APIString|"Upper Bound <nowiki>=</nowiki> "}} & BResult2.upper & vbNewLine & _
          {{APIString|"Lower Bound <nowiki>=</nowiki> "}} & BResult2.lower & vbNewLine)
 
'''VB.NET'''
{{APIComment|'Set the confidence level to 90% two-sided bounds.}}
{{APIComment|'Declare a string variable for any errors found during this method.}}
  {{APIPrefix|Dim}} ErrorMsg {{APIPrefix|As}} String
  AModel.SetConfidenceLevel(0.9, ConfBoundsSides.TwoSidedBoth, False, ErrorMsg)
{{APIComment|'Initiate new instances of the BoundsValues class.}}
  {{APIPrefix|Dim}} BResult1 {{APIPrefix|As}} BoundsValues
  {{APIPrefix|Dim}} BResult2 {{APIPrefix|As}} BoundsValues
{{APIComment|'Calculate bounds for the reliability at 100 hrs and the mean time.}}
  BResult1 = AModel.Bounds_Reliability(100)
  BResult2 = AModel.Bounds_MeanTime
 
{{APIComment|'Display the output.}}
  MsgBox ({{APIString|"Reliability <nowiki>=</nowiki> "}} & Result1 & vbNewLine & _
          {{APIString|"Upper Bound <nowiki>=</nowiki> "}} & BResult1.upper & vbNewLine & _
          {{APIString|"Lower Bound <nowiki>=</nowiki> "}} & BResult1.lower & vbNewLine)
  MsgBox ({{APIString|"Mean Time <nowiki>=</nowiki> "}} & Result2 & vbNewLine & _
          {{APIString|"Upper Bound <nowiki>=</nowiki> "}} & BResult2.upper & vbNewLine & _
          {{APIString|"Lower Bound <nowiki>=</nowiki> "}} & BResult2.lower & vbNewLine)
 
===Test the Code===
Below are the complete code lists for this example. To test them, run the application by clicking '''Start''' on the Debug menu. Compare the results returned by the API with the results obtained from the Quick Calculation Pad (QCP).
 
'''VBA'''
Sub Main()
 
{{APIComment|'Connect to the Synthesis repository and set project ID#1 as the current project.}}
  {{APIPrefix|Dim}} MyRepository {{APIPrefix|As New}} Repository
  MyRepository.ConnectToRepository({{APIString|"C:\RSRepository1.rsr10"}})
  MyRepository.Project.SetCurrentProject(1)
{{APIComment|'Retrieve the model with ID# 21 from the repository.}}
  {{APIPrefix|Dim}} AModel {{APIPrefix|As}} cModel
  {{APIPrefix|Set}} AModel = MyRepository.Model.GetModel(21)
 
{{APIComment|'Declare variables.}}
  {{APIPrefix|Dim}} Result1 {{APIPrefix|As}} Double
  {{APIPrefix|Dim}} Result2 {{APIPrefix|As}} Double
{{APIComment|'Calculate the model's reliability at time &#61; 100 hrs and mean time.}}
  Result1 = AModel.Reliability(100)
  Result2 = AModel.MeanTime
 
{{APIComment|'Set the confidence level to 90% two-sided bounds.}}
{{APIComment|'Declare a string variable for any errors found during this method.}}
  {{APIPrefix|Dim}} ErrorMsg {{APIPrefix|As}} String
  {{APIPrefix|Call}} AModel.SetConfidenceLevel(0.9, ConfBoundsSides_TwoSidedBoth, False, ErrorMsg)
{{APIComment|'Initiate new instances of the BoundsValues class.}}
  {{APIPrefix|Dim}} BResult1 {{APIPrefix|As}} BoundsValues
  {{APIPrefix|Dim}} BResult2 {{APIPrefix|As}} BoundsValues
{{APIComment|'Calculate bounds for the reliability at 100 hrs and the mean time.}}
  {{APIPrefix|Set}} BResult1 = AModel.Bounds_Reliability(100)
  {{APIPrefix|Set}} BResult2 = AModel.Bounds_MeanTime
 
{{APIComment|'Display the output.}}
  MsgBox ({{APIString|"Reliability <nowiki>=</nowiki> "}} & Result1 & vbNewLine & _
          {{APIString|"Upper Bound <nowiki>=</nowiki> "}} & BResult1.upper & vbNewLine & _
          {{APIString|"Lower Bound <nowiki>=</nowiki> "}} & BResult1.lower & vbNewLine)
  MsgBox ({{APIString|"Mean Time <nowiki>=</nowiki> "}} & Result2 & vbNewLine & _
          {{APIString|"Upper Bound <nowiki>=</nowiki> "}} & BResult2.upper & vbNewLine & _
          {{APIString|"Lower Bound <nowiki>=</nowiki> "}} & BResult2.lower & vbNewLine)
End Sub


  '''VB.NET'''
  '''VB.NET'''
Line 152: Line 20:
  {{APIPrefix|Imports}} SynthesisAPI  
  {{APIPrefix|Imports}} SynthesisAPI  
   
   
   {{APIPrefix|Public Class}} Form1
   {{APIPrefix|Module}} Module1
     {{APIPrefix|Private Sub}} Button1_Click(sender {{APIPrefix|As}} System.Object, e {{APIPrefix|As}} System.EventArgs) {{APIPrefix|Handles}} Button1.Click
     {{APIPrefix|Sub}} Main()
    
    
     {{APIComment|'Connect to the Synthesis repository and set project ID#1 as the current project.}}
     {{APIComment|'Connect to a Synthesis repository and project.}}
       {{APIPrefix|Dim}} MyRepository {{APIPrefix|As New}} Repository
       {{APIPrefix|Dim}} MyRepository {{APIPrefix|As New}} Repository
       MyRepository.ConnectToRepository({{APIString|"C:\RSRepository1.rsr10"}})
       MyRepository.ConnectToRepository({{APIString|"C:\RSRepository1.rsr10"}}){{APIComment|'Replace with name and path to test repository.}}
       MyRepository.Project.SetCurrentProject(1)
       MyRepository.Project.SetCurrentProject(1){{APIComment|'Replace with the object ID of test project.}}
   
   
     {{APIComment|'Retrieve the model with ID# 21 from the repository.}}       
     {{APIComment|'Retrieve a model from the repository.}}       
       {{APIPrefix|Dim}} AModel {{APIPrefix|As}} cModel
       {{APIPrefix|Dim}} AModel {{APIPrefix|As}} cModel
       AModel = MyRepository.Model.GetModel(21)
       AModel = MyRepository.Model.GetModel(21){{APIComment|'Replace with the object ID of test model.}}
    
    
     {{APIComment|'Declare variables.}}
     {{APIComment|'Declare some variables to store the results.}}
       {{APIPrefix|Dim}} Result1 {{APIPrefix|As}} Double
       {{APIPrefix|Dim}} Result1 {{APIPrefix|As}} Double
       {{APIPrefix|Dim}} Result2 {{APIPrefix|As}} Double
       {{APIPrefix|Dim}} Result2 {{APIPrefix|As}} Double
Line 177: Line 45:
       AModel.SetConfidenceLevel(0.9, ConfBoundsSides.TwoSidedBoth, False, ErrorMsg)
       AModel.SetConfidenceLevel(0.9, ConfBoundsSides.TwoSidedBoth, False, ErrorMsg)
   
   
     {{APIComment|'Initiate new instances of the BoundsValues class.}}
     {{APIComment|'Declare new BoundsValues objects to store the confidence bounds results.}}
       {{APIPrefix|Dim}} BResult1 {{APIPrefix|As}} BoundsValues
       {{APIPrefix|Dim}} BResult1 {{APIPrefix|As}} BoundsValues
       {{APIPrefix|Dim}} BResult2 {{APIPrefix|As}} BoundsValues
       {{APIPrefix|Dim}} BResult2 {{APIPrefix|As}} BoundsValues
Line 194: Line 62:
   
   
     {{APIPrefix|End Sub}}
     {{APIPrefix|End Sub}}
  {{APIPrefix|End Class}}
  {{APIPrefix|End Module}}
 
 
==Discussion==
Begin by connecting to a Synthesis repository and project (for details, see [[Connect_or_Disconnect_from_a_Synthesis_Repository|this tutorial]].) If you're copying this section of code, be sure to replace the inputs with appropriate data for your test repository.
 
{{APIComment|'Connect to a Synthesis repository and project.}}
  {{APIPrefix|Dim}} MyRepository {{APIPrefix|As New}} Repository
  MyRepository.ConnectToRepository({{APIString|"C:\RSRepository1.rsr10"}}){{APIComment|'Replace with name and path to test repository.}}
  MyRepository.Project.SetCurrentProject(1){{APIComment|'Replace with the object ID of test project.}}
 
Once you are connected to the repository, use the [[Repository.Model.GetModel|Model.GetModel]] method to retrieve a single model from the repository. The following code assumes that the repository contains a model with ID#21.
 
{{APIComment|'Retrieve a model from the repository.}}     
  {{APIPrefix|Dim}} AModel {{APIPrefix|As}} cModel
  AModel = MyRepository.Model.GetModel(21){{APIComment|'Replace with the object ID of test model.}}
 
We can now obtain some metrics from the model. The [[CModel Class|cModel Class]] reference doc lists all available methods for performing calculations on models, but for this example, we'll limit it to the [[CModel.Reliability|Reliability]] and [[CModel.MeanTime|MeanTime]] methods.
 
{{APIComment|'Declare some variables to store the results.}}
  {{APIPrefix|Dim}} Result1 {{APIPrefix|As}} Double
  {{APIPrefix|Dim}} Result2 {{APIPrefix|As}} Double
{{APIComment|'Calculate the model's reliability at time &#61; 100 hrs and mean time.}}
  Result1 = AModel.Reliability(100)
  Result2 = AModel.MeanTime
 
To calculate the confidence bounds, use the [[CModel.SetConfidenceLevel|SetConfidenceLevel]] method to specify 90% two-sided confidence bounds.
 
{{APIComment|'Set the confidence level to 90% two-sided bounds.}}
{{APIComment|'Declare a string variable for any errors found during this method.}}
  {{APIPrefix|Dim}} ErrorMsg {{APIPrefix|As}} String
  AModel.SetConfidenceLevel(0.9, ConfBoundsSides.TwoSidedBoth, False, ErrorMsg)
 
And then use any of the bounds calculation methods in the class to perform the commands. Here, we limit the example to the [[CModel.Bounds_Reliability|Bounds_Reliability]] and [[CModel.Bounds_MeanTime|Bounds_MeanTime]] methods.
 
{{APIComment|'Declare new BoundsValues objects to store the confidence bounds results.}}
  {{APIPrefix|Dim}} BResult1 {{APIPrefix|As}} BoundsValues
  {{APIPrefix|Dim}} BResult2 {{APIPrefix|As}} BoundsValues
{{APIComment|'Calculate bounds for the reliability at 100 hrs and the mean time.}}
  BResult1 = AModel.Bounds_Reliability(100)
  BResult2 = AModel.Bounds_MeanTime
 
The last section of code creates simple message boxes to display the outputs. To verify, you can compare the results returned by the API with the results obtained from the software's Quick Calculation Pad (QCP).
 
{{APIComment|'Display the output.}}
  MsgBox ({{APIString|"Reliability <nowiki>=</nowiki> "}} & Result1 & vbNewLine & _
          {{APIString|"Upper Bound <nowiki>=</nowiki> "}} & BResult1.upper & vbNewLine & _
          {{APIString|"Lower Bound <nowiki>=</nowiki> "}} & BResult1.lower & vbNewLine)
  MsgBox ({{APIString|"Mean Time <nowiki>=</nowiki> "}} & Result2 & vbNewLine & _
          {{APIString|"Upper Bound <nowiki>=</nowiki> "}} & BResult2.upper & vbNewLine & _
          {{APIString|"Lower Bound <nowiki>=</nowiki> "}} & BResult2.lower & vbNewLine)
 


===Notes===
===Notes===
See <code>[[CModel Class|cModel]]</code> class for a list of all available calculation methods for models.
For ALTA models, you can specify the use stress level to use for the calculations by using the [[CModel.SetUseStress|cModel.SetUseStress]] method. For example, the following code returns the reliability at 100 hrs for a use stress level of 200 (the 0 parameter indicates that the stress value applies to the first stress in the model):
 
{{APIComment|...}}
  AModel.SetUseStress(0, 200)
  Result1 = AModel.Reliability(100)
 


===References===
===References===
To learn more, see the reference documentation for the class and methods discussed in this tutorial:
*[[CModel Class]]
 
*[[CModel.Reliability|cModel.Reliability Method]]
*[[CModel.Reliability|cModel.Reliability Method]]
*[[CModel.MeanTime|cModel.MeanTime Method]]
*[[CModel.MeanTime|cModel.MeanTime Method]]

Revision as of 17:14, 28 April 2016

APIWiki.png


<< Back to Tutorials Main Page

In Synthesis applications, models can represent the reliability of a component, the duration of a task, the expected cost of a repair and many other characteristics. In this tutorial, you'll learn how to calculate some useful metrics from models.

Prerequisites

Before you begin:

  • Create a test repository (can use Weibull++ or ALTA). Perform a simple analysis and then publish a model of the analysis. You'll want to use a published model with this tutorial so you can perform confidence bounds calculations.
  • Note the published model's object ID number. You will use the ID# to retrieve the model from the database. (To display the object IDs, choose File > Application Setup, then click Other under the Synthesis Settings heading in the navigation panel. Select the Display Object IDs check box. The object ID of the model is displayed in the Resource Manager.)


Tutorial: Calculate Results from a Model

The following example demonstrates how to obtain calculated results from a model resource. A discussion of the example follows.

A VBA version of the code sample is available here.

VB.NET

Imports SynthesisAPI 

 Module Module1
    Sub Main()
  
    'Connect to a Synthesis repository and project. 
     Dim MyRepository As New Repository
     MyRepository.ConnectToRepository("C:\RSRepository1.rsr10") 'Replace with name and path to test repository. 
     MyRepository.Project.SetCurrentProject(1) 'Replace with the object ID of test project. 

    'Retrieve a model from the repository.       
     Dim AModel As cModel
     AModel = MyRepository.Model.GetModel(21) 'Replace with the object ID of test model. 
  
    'Declare some variables to store the results. 
     Dim Result1 As Double
     Dim Result2 As Double

    'Calculate the model's reliability at time = 100 hrs and mean time. 
     Result1 = AModel.Reliability(100)
     Result2 = AModel.MeanTime

    'Set the confidence level to 90% two-sided bounds. 
    'Declare a string variable for any errors found during this method. 
     Dim ErrorMsg As String
     AModel.SetConfidenceLevel(0.9, ConfBoundsSides.TwoSidedBoth, False, ErrorMsg)

    'Declare new BoundsValues objects to store the confidence bounds results. 
     Dim BResult1 As BoundsValues
     Dim BResult2 As BoundsValues

    'Calculate bounds for the reliability at 100 hrs and the mean time. 
     BResult1 = AModel.Bounds_Reliability(100)
     BResult2 = AModel.Bounds_MeanTime

    'Display the output. 
     MsgBox ("Reliability = " & Result1 & vbNewLine & _
             "Upper Bound = " & BResult1.upper & vbNewLine & _
             "Lower Bound = " & BResult1.lower & vbNewLine)
     MsgBox ("Mean Time = " & Result2 & vbNewLine & _
             "Upper Bound = " & BResult2.upper & vbNewLine & _
             "Lower Bound = " & BResult2.lower & vbNewLine)

    End Sub
End Module


Discussion

Begin by connecting to a Synthesis repository and project (for details, see this tutorial.) If you're copying this section of code, be sure to replace the inputs with appropriate data for your test repository.

 'Connect to a Synthesis repository and project. 
  Dim MyRepository As New Repository
  MyRepository.ConnectToRepository("C:\RSRepository1.rsr10") 'Replace with name and path to test repository. 
  MyRepository.Project.SetCurrentProject(1) 'Replace with the object ID of test project. 

Once you are connected to the repository, use the Model.GetModel method to retrieve a single model from the repository. The following code assumes that the repository contains a model with ID#21.

 'Retrieve a model from the repository.       
  Dim AModel As cModel
  AModel = MyRepository.Model.GetModel(21) 'Replace with the object ID of test model. 

We can now obtain some metrics from the model. The cModel Class reference doc lists all available methods for performing calculations on models, but for this example, we'll limit it to the Reliability and MeanTime methods.

 'Declare some variables to store the results. 
  Dim Result1 As Double
  Dim Result2 As Double

 'Calculate the model's reliability at time = 100 hrs and mean time. 
  Result1 = AModel.Reliability(100)
  Result2 = AModel.MeanTime

To calculate the confidence bounds, use the SetConfidenceLevel method to specify 90% two-sided confidence bounds.

 'Set the confidence level to 90% two-sided bounds. 
 'Declare a string variable for any errors found during this method. 
  Dim ErrorMsg As String
  AModel.SetConfidenceLevel(0.9, ConfBoundsSides.TwoSidedBoth, False, ErrorMsg)

And then use any of the bounds calculation methods in the class to perform the commands. Here, we limit the example to the Bounds_Reliability and Bounds_MeanTime methods.

 'Declare new BoundsValues objects to store the confidence bounds results. 
  Dim BResult1 As BoundsValues
  Dim BResult2 As BoundsValues

 'Calculate bounds for the reliability at 100 hrs and the mean time. 
  BResult1 = AModel.Bounds_Reliability(100)
  BResult2 = AModel.Bounds_MeanTime

The last section of code creates simple message boxes to display the outputs. To verify, you can compare the results returned by the API with the results obtained from the software's Quick Calculation Pad (QCP).

 'Display the output. 
  MsgBox ("Reliability = " & Result1 & vbNewLine & _
         "Upper Bound = " & BResult1.upper & vbNewLine & _
         "Lower Bound = " & BResult1.lower & vbNewLine)
  MsgBox ("Mean Time = " & Result2 & vbNewLine & _
         "Upper Bound = " & BResult2.upper & vbNewLine & _
         "Lower Bound = " & BResult2.lower & vbNewLine)


Notes

For ALTA models, you can specify the use stress level to use for the calculations by using the cModel.SetUseStress method. For example, the following code returns the reliability at 100 hrs for a use stress level of 200 (the 0 parameter indicates that the stress value applies to the first stress in the model):

 ... 

  AModel.SetUseStress(0, 200)
  Result1 = AModel.Reliability(100)


References