Calculate Results from a Model: Difference between revisions
Kate Racaza (talk | contribs) mNo edit summary |
Kate Racaza (talk | contribs) No edit summary |
||
Line 8: | Line 8: | ||
*Create a Synthesis repository for testing purposes. Perform a simple analysis (can use [http://weibull.reliasoft.com/ Weibull++] or [http://alta.reliasoft.com/ 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. | *Create a Synthesis repository for testing purposes. Perform a simple analysis (can use [http://weibull.reliasoft.com/ Weibull++] or [http://alta.reliasoft.com/ 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 | *Note the published model's [[Synthesis_API_Object_IDs|object ID]]. You will use the object ID to retrieve the model from the database. | ||
Line 25: | Line 25: | ||
{{APIComment|'Connect to a Synthesis repository and 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. | MyRepository.ConnectToRepository({{APIString|"C:\RSRepository1.rsr11"}}){{APIComment|'Replace with name and path to test repository.}} | ||
MyRepository.Project.SetCurrentProject(1){{APIComment|'Replace with the object ID of test project.}} | MyRepository.Project.SetCurrentProject(1){{APIComment|'Replace with the object ID of test project.}} | ||
Line 69: | Line 69: | ||
{{APIComment|'Connect to a Synthesis repository and 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. | MyRepository.ConnectToRepository({{APIString|"C:\RSRepository1.rsr11"}}){{APIComment|'Replace with name and path to test repository.}} | ||
MyRepository.Project.SetCurrentProject(1){{APIComment|'Replace with the object ID of test project.}} | MyRepository.Project.SetCurrentProject(1){{APIComment|'Replace with the object ID of test project.}} | ||
Line 78: | Line 78: | ||
AModel = MyRepository.Model.GetModel(21){{APIComment|'Replace with the object ID of test model.}} | 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 | We can now obtain some metrics from the model. The [[CModel Class|cModel Class]] reference documentation lists all available methods for performing calculations on models. 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.}} | {{APIComment|'Declare some variables to store the results.}} | ||
Line 88: | Line 88: | ||
Result2 = AModel.MeanTime | Result2 = AModel.MeanTime | ||
To calculate the confidence bounds, use the [[CModel.SetConfidenceLevel|SetConfidenceLevel]] method to specify 90% two-sided confidence bounds. | To calculate the confidence bounds, first use the [[CModel.SetConfidenceLevel|SetConfidenceLevel]] method to specify 90% two-sided confidence bounds. | ||
{{APIComment|'Set the confidence level to 90% two-sided bounds.}} | {{APIComment|'Set the confidence level to 90% two-sided bounds.}} | ||
Line 95: | Line 95: | ||
AModel.SetConfidenceLevel(0.9, ConfBoundsSides.TwoSidedBoth, False, ErrorMsg) | AModel.SetConfidenceLevel(0.9, ConfBoundsSides.TwoSidedBoth, False, ErrorMsg) | ||
And then use any of the bounds | And then use any of the bounds methods in the class to perform the calculations. 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.}} | {{APIComment|'Declare new BoundsValues objects to store the confidence bounds results.}} |
Latest revision as of 18:22, 3 April 2017
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)