Talk:Calculate Results from a Model/Notes: Difference between revisions

From ReliaWiki
Jump to navigation Jump to search
No edit summary
(Replaced content with '==DRAFT==')
 
Line 1: Line 1:
{{Template:API}}{{Template:BacktoPrevPage|[[API Tutorials|<< Back to Tutorials Main Page]]}}
==DRAFT==
 
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 a variety of useful metrics from models.
 
==Prerequisites==
Before you begin:
 
*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 compare the results returned by the API with the results obtained from the Quick Calculation Pad (QCP).
 
*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]].
 
'''VB.NET'''
{{APIPrefix|Imports}} SynthesisAPI
  {{APIPrefix|Module}} Module1
    {{APIPrefix|Sub}} Main()
 
    {{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.}}
    {{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.}}
 
    {{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
    {{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|'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
    {{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)
    {{APIPrefix|End Sub}}
{{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, allowing you to 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===
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)
{{APIComment|...}}
 
===References===
*[[CModel Class]]
*[[CModel.Reliability|cModel.Reliability Method]]
*[[CModel.MeanTime|cModel.MeanTime Method]]
*[[CModel.SetConfidenceLevel|cModel.SetConfidenceLevel Method]]
*[[CModel.Bounds_Reliability|cModel.Bounds_Reliability Method]]
*[[CModel.Bounds_MeanTime|cModel.Bounds_MeanTime Method]]
*[[BoundsValues Class]]

Latest revision as of 17:14, 28 April 2016

DRAFT