PipelineStudio Gas Simulator Module Excel - English
PipelineStudio Gas Simulator Module Excel - English
PipelineStudio Gas Simulator Module Excel - English
1. PipelineStudio Configuration
The foundation of this program is the investigation of the integration of pipelinestudio with other applications; hence a relatively simple point to point pipelinestudio Gas configuration consisting of 20 pipeline sections of one mile length and 12 internal diameter will be used as the baseline. The purpose of the number of leg segments is that it permits us to trend pressure and flow at more intervals than simply the ends of the pipe. A supply will be connected to the upstream and a volumetric delivery to the downstream points of the pipeline configuration. In general default pipelinestudio properties should be used to prevent excessive time constructing the model. The input fluid will be the default Gulf Coast Gas from the TGNET Library; this should be available from the drop down menu on the supply dialogue. To reflect this choice a compositional equation should be selected, to determine the fluid density and compressibility, from the simulation options (BWRS recommended), though this is not essential as the default SAREM equation can calculate the required fluid properties from the fluid composition (though a warning message is presented on model validation this would be ultimately hidden from an end user if the correct arguments are used). Ultimately with this model the inlet and outlet flow boundaries will be varied over time, however this does not preclude the fact that for an initial steady state solution an initial pressure boundary set point is required. The model will be run initially as a PQ model; i.e. initial control pressure upstream and flow downstream. An upstream flow constraint and a downstream pressure constraint will also be provided. The upstream flow constraint permits variance of the upstream
PLStudio /RunTransient xyz.tgw PLStudio /RunSteady /CloseWhenFinished xyz.tgw PLStudio /RunTransient /CloseWhenFinished xyz.tgw PLStudio /RunSteady /StartMinimized /CloseWhenFinished xyz.tgw PLStudio /RunTransient /StartMinimized /CloseWhenFinished xyz.tgw PLStudio /importKeywordfile abc.kw /SaveConfig xyz.tgw /CloseWhenFinished
2.1.2. Example 2 start plstudio /RunTransient C:\data\demo.tgw This would, in order: start pipelinestudio open the demo.tgw file from the c:\data folder run a transient simulation
2.1.4. Example 3b C:\Program Files\Energy Solutions\PLStudio\plstudio.exe /scenariodata C:\data\demoscen.csv /RunSteady C:\data\demo.tgw This would do the same as the previous example and then run a steady-state simulation.
2.1.5. Example 4 C:\Program Files\Energy Solutions\PLStudio\plstudio.exe /importdata C:\data\demoinit.csv /scenariodata C:\data\demoscen.csv C:\data\demo.tgw This example shows the /scenariodata flag combined with the /importdata flag. This would, in order: start pipelinestudio open the demo.tgw file from the c:\data folder import initial data from the demoinit.csv file in the c:\data\ folder import scenario data from the demoscen.csv file in the c:\data\ folder.
2.1.6. Example 5 C:\Program Files\Energy Solutions\PLStudio\plstudio.exe /RunTransient /CloseWhenFinished C:\data\demo.tgw This would, in order: start pipelinestudio open the demo.tgw file from the c:\data folder run a transient simulation close pipelinestudio
3. Control Options
The Control Options are a subset of values that are normally set via the Simulation | Options menu. Using the File | Export | Option Data menu option causes a Control Options file to be written to the selected folder. This (plain text) file will contain the options along with their current value in the selected configuration. When the Control Options are imported any number of the control options can be omitted from the import file. The import file can contain one, a selection, or all the control options that are exported. The format of the Control Options file is Comma Separated Value (CSV) so it can be easily edited either in a text editor or any other application that supports the CSV file format such as Microsoft Excel. Control options can be imported and exported either by the menu option File | Export | Option Data and File | Import | Options Data or from the command line using the flags /ImportOptions options_data_file_name.csv or /ExportOptions options_data_file_name.csv. See the online help file in pipelinestudio for more information on working with pipelinestudio from the command line.
Data 1, Data 2, Data3 The comma indicates a field separator. There are several different import and export options available for pipelinestudio. These options are: Import/Export Keyword file # The file format describes the configuration of the pipeline network to be studied in a formatted paragraph file. It is used primarily for processing purpose though some older configurations may be stored in this file format. Initial data # This file format describes the pipeline configuration in terms of a CSV file. This file is used to import boundary condition changes into pipelinestudio. The file does not have to contain a full description of the network, only the parts which should be changed. Scenario data # This file describes a transient scenario in terms of a CSV file which may be exported into pipelinestudio. Options data # This file describes the simulation options in a CSV file format. Not all options may be changed with this file. Library file # An archived library may be imported. The file is in a binary file format. The files which are normally used for an integrated pipelinestudio application are the Initial Data file, the Scenario file and perhaps the Options file. The initial data is normally used to describe any steady set point and constraint changes to the defaults configuration, the scenario file describes any changes to the default transient scenario and the options file may describe any changes to the base options.
10
Option Explicit Public Sub fill_some_cells() Worksheets( !Sheet1 ).Range(!A2:C7 ).Value = !Hi! End Sub This macro may then be run, using the play button from the Visual Basic editor. So what this piece of code does is: Option Explicit Public Sub fill_some_cells() Worksheets( !Sheet1 ).Range(!A2:C7 ).Value= Hi! Forces explicit declaration of all variables Creates a subroutine called fill_some_cells Selects worksheet Sheet1, selects the cells in the range A2 to C7 and populates these cells with the value Hi. Closes the sub routine
End Sub
11
Generate set point data Execute batch file Set point file
Scenario file
Batch file
The code to perform this set of functions is relatively straightforward, selecting data from an Excel worksheet, copying the data in a file (one for set points and one for the scenario); creating a
12
13
FileNum = FreeFile
' This line permits us to allow read/write access to the setpoints file
Worksheets("Setpoints").Activate Worksheets("Setpoints").UsedRange.Select Selection.Copy Workbooks.Open Filename:=sSetpointFileNameWithPath Selection.PasteSpecial Paste:=xlValues, operation:=xlNone, SkipBlanks:= _ False, Transpose:=False ActiveWorkbook.SaveAs Filename:=sSetpointFileNameWithPath _ , FileFormat:=xlCSV, CreateBackup:=False End Sub Public Sub CreateScenarioFile() Dim FileNum As Integer Dim sScenarioFileNameWithPath As String sScenarioFileNameWithPath = ThisWorkbook.Path & "\" & "scenario.csv" FileNum = FreeFile Open sScenarioFileNameWithPath For Output Access Write As #FileNum Close #FileNum
14
Worksheets("Scenario").Activate Worksheets("Scenario").UsedRange.Select Selection.Copy Workbooks.Open Filename:=sScenarioFileNameWithPath Selection.PasteSpecial Paste:=xlValues, operation:=xlNone, SkipBlanks:= _ False, Transpose:=False ActiveWorkbook.SaveAs Filename:=sScenarioFileNameWithPath _ , FileFormat:=xlCSV, CreateBackup:=False End Sub
Public Sub CreateBatchFileAndRun() Dim FileNum As Integer Dim sBatchFileWithPath, sStudioCommand, sStudioPath, sPLSID As String
' Here we create the batch file
sStudioCommand = "cmd /k Start Plstudio /importdata " & ThisWorkbook.Path & "\setpoints.csv /scenariodata " & ThisWorkbook.Path & "\scenario.csv /StartMinimized /CloseWhenFinished /RunTransient " & ThisWorkbook.Path & "\Simulation_base.tgw" Open sBatchFileWithPath For Output As #FileNum Write #FileNum, sStudioCommand Close #FileNum
' This piece of code runs the batch file
sPLSID = (ThisWorkbook.Path & "\pls.bat") On Error Resume Next AppActivate (Shell(sPLSID)) End Sub
15
Workbooks.OpenText Filename:=ThisWorkbook.Path & "\" & "Simulation_Base.wtg" Workbooks("Simulation_Base.wtg").Worksheets("Simulation_Base").Activate Workbooks("Simulation_Base.wtg").Worksheets("Simulation_Base").UsedRange.Select Selection.Copy Workbooks("Application.xls").Worksheets("Results").Activate ActiveWorkbook.Worksheets("Results").Range("A1").Select ActiveWorkbook.Worksheets("Results").Paste End Sub Public Sub GraphInventory()
' This code creates a graph of inventory
Workbooks("Application.xls").Worksheets("Results").Activate ActiveWindow.SmallScroll ToRight:=137 Range("ER1").Select ActiveCell.FormulaR1C1 = "Inv Sum" Range("ER7").Select ActiveCell.FormulaR1C1 = "MMSCF" Range("ER8").Select ActiveCell.FormulaR1C1 = _ "=SUM(RC[-140]+RC[-133]+RC[-126]+RC[-119]+RC[-112]+RC[-105]+RC[-98]+RC[-91]+RC[84]+RC[-77]+RC[-70]+RC[-63]+RC[-56]+RC[-49]+RC[-42]+RC[-35]+RC[-28]+RC[-21]+RC[14]+RC[-7])" Range("ER8").Select Selection.AutoFill Destination:=Range("ER8:ER68"), Type:=xlFillDefault Range("ER8:ER68").Select Charts.Add ActiveChart.ChartType = xlXYScatterSmoothNoMarkers ActiveChart.Location Where:=xlLocationAsNewSheet, Name:="Inventory" With ActiveChart .HasTitle = True .ChartTitle.Characters.Text = "Inventory Vs Time" .Axes(xlCategory, xlPrimary).HasTitle = True .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Time" .Axes(xlValue, xlPrimary).HasTitle = True .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Inventory" End With ActiveChart.HasLegend = False Application.CommandBars("Chart").Visible = False End Sub
16