Calculate Results from a Model

From ReliaWiki
Jump to navigation Jump to search
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 Synthesis repository for testing purposes. Perform a simple analysis (can use Weibull++ or ALTA) 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. You will use the object ID to retrieve the model from the database.


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.

The 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.rsr11") '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.rsr11") '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 documentation lists all available methods for performing calculations on models. 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, first 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 methods in the class to perform the calculations. 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 value 0 indicates that the stress value applies to the first stress in the model):

 ... 

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

References